In this tutorial we will show you how to install Laravel with nginx on CentOS 8. For those of you who didn’t know, Laravel is a free, open-source PHP web application framework, created by Taylor Otwell and intended for the development of web applications following the model view controller (MVC) architectural pattern. It is a pretty new framework, but with a big potential to become one of the most popular PHP frameworks.
This article assumes you have at least basic knowledge of linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo’ to the commands to get root privileges. I will show you through the step by step installation Laravel PHP Framework with nginx on a CentOS 8 server.
Install Laravel With Nginx on CentOS 8
Step 1. First let’s start by ensuring your system is up-to-date.
Step 2. Install LEMP stack server.
A CentOS 8 LEMP stack server is required. If you do not have LEMP installed, you can follow our guide here.
Step 3. Installing Composer.
The composer is required for installing Laravel dependencies. So use below commands to download and use as a command in our system:
curl-sShttps://getcomposer.org/installer | php
Confirm the installation of Composer using following command:
Install Laravel using following command:
We will need to change some folders permissions:
By default, MariaDB is not hardened. You can secure MariaDB using the mysql_secure_installation script. You should read and below each steps carefully which will set root password, remove anonymous users, disallow remote root login, and remove the test database and access to secure MariaDB.
Configure it like this:
Next we will need to log in to the MariaDB console and create a database for the Laravel. Run the following command:
This will prompt you for a password, so enter your MariaDB root password and hit Enter. Once you are logged in to your database server you need to create a database for Laravel installation:
Now open .env file and make changes as given below:
First, create a root directory for your Laravel project by typing following command:
Now go to Nginx configuration directory and create a file your-domain.com.conf for your project configuration:
Add the following lines:
# Log files for Debugging
# Webroot Directory for Laravel project
# Your Domain Name
# PHP-FPM Configuration Nginx
Save and close the file. Restart the Nginx service for the changes to take effects:
Create a firewall rule to allow access from external machines to the Laravel:
Laravel PHP Framework will be available on HTTP port 80 by default. Open your favorite browser and navigate to http://your_domain.com or http://server-ip-addressand complete the required the steps to finish the installation.
Congratulation’s! You have successfully installed Laravel. Thanks for using this tutorial for installing Laravel PHP Framework on your CentOS 8 system. For additional help or useful information, we recommend you to check the official Laravel website.