How to install Laravel 5.6 with NGINX on Ubuntu 18.04

How to install Laravel 5.6 with NGINX on Ubuntu 18.04

How to install Laravel 5.6 with NGINX on Ubuntu 18.04, laravel is an open-source PHP framework that uses the MVC design template.

This option sought to provide a more advanced alternative to the CI framework. In year 2011, laravel released its first and second editions. The latest version of laravel, version 5.6, comes with improved features such as command line support, support for various database systems and Route improvements.

In this tutorial, we are going to review step by step how to install laravel version 5.6 with NGINX on Ubuntu 18.04. So be with the eldernode.

What will we do in this training?

1) Updating the Ubuntu repository

2) Install NGINX

3) Install PHP-FPM 7.2

4) Install MariaDB

5) Install PHP Composer

6) Configure Virtual Hosts for laravel

7) Installing laravel

8) test


Step One: Update Ubuntu Virtual Server

We must update the Ubuntu repository before starting the installation process. Then update all available packages to the latest version. To do this, first log in to your Ubuntu Virtual Private Server:

ssh [email protected]

Now update the Ubuntu repository and update all the packages available on the system to the latest version using the following command:

sudo apt update

sudo apt upgrade

Reboot your virtual private server and reconnect it using SSH.

Step Two: Install NGINX

At this point, we need to install NGINX 1.14 on our system. This option is available by default in the Ubuntu repository. You should install it using the following command:

sudo apt install Nginx -y

After the installation process, start the NGINX service and set it to run automatically on system boot. Get help with following command:

systemctl start Nginx

systemctl enable Nginx

As you know, NGINX works on port 80. Check the status quo using the following command:

netstat -plntu

You can also use the following command:

curl -I localhost

Step Three: Install PHP7.2 and PHP-FPM

We’ve got NGINX installed so far, and now we need to go into installing PHP-FPM version 7. We will install PHP7.2 and some PHP plugins needed for laravel. Get help with the following command:

sudo apt install php7.2 php7.2-curl php7.2-common php7.2-cli php7.2-MySQL php7.2-mbstring php7.2-fpm php7.2-XML php7.2-zip -y

Now go to the PHP Configuration Directory and edit the php.ini file in this directory:

cd /etc/php/7.2/

vim fpm/php.ini

Uncomment the following CGI line and change it to zero:


Now save the file and exit. You can start PHP-FPM and set it to run automatically on system boot.

systemctl start php7.2-fpm

systemctl enable php7.2-fpm

In Ubuntu by default, PHP-FPM runs under sock file supervision. Check this file using the following command:

netstat -pl | grep php7.2-fpm

At this point, we were able to install PHP and PHP-FPM on the Ubuntu Virtual Private Server. Now we need to move on to the next steps.

Step Four: Install MariaDB Database

This is optional, but when your laravel project is based on MYSQL you should do it for your project. We will install the latest version of the database on the server. You can install the database from the repository using the following command:

sudo apt install mariadb-server mariadb-client -y

After the installation process is complete, run MariaDB and get it ready for boot on the system.

systemcl start mysql

systemctl enable mysql

This database works on port 3306. Check it out with the following command:

netstat -plntu

Now specify the database password using the following command:


Enter the root password, delete the anonymous user, and remove the remote root login:

Set root password? [Y/n] Y

Remove anonymous users? [Y/n] Y

Disallow root login remotely? [Y/n] Y

Remove test database and access to it? [Y/n] Y

Reload privilege tables now? [Y/n] Y

Database installation and configuration were also done. ☺

Step Five: Install PHP Composer

Composer is a package manager for PHP programming language. This option was created in the Year 2011. On the Ubuntu 18.04 VPS, the composer is available in the repository and you can install it with the apt command.

sudo apt install composer -y

After the installation process is complete, run the following command to see the result.


Step 6: Configure Virtual Host for laravel

At this point, we will configure Virtual Host for laravel. But before doing so, we need to decide on the directory needed for our laravel project. We use the ‘/ var / www / laravel’ directory for our project. Create it using the following command:

mkdir -p /var/www/laravel

Now go to the NGINX Configuration Directory. Create a new virtual host file called laravel under the ‘sites-available‘ directory:

cd /etc/Nginx/

vim sites-available/laravel

Paste the following configurations into it:

 server {

listen 80;

listen [::]:80 ipv6only=on;

# Log files for Debugging

access_log /var/log/nginx/laravel-access.log;

error_log /var/log/nginx/laravel-error.log;

# Webroot Directory for Laravel project

root /var/www/laravel/public;

index index.php index.html index.htm;

# Your Domain Name


location / {

try_files $uri $uri/ /index.php?$query_string;


# PHP-FPM Configuration Nginx

location ~ \.php$ {

try_files $uri =404;

fastcgi_split_path_info ^(.+\.php)(/.+)$;

fastcgi_pass unix:/run/php/php7.2-fpm.sock;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;



Now save the file and exit. You can enable Virtual Host by creating the Symlink Laravel file for the directory you want. Test the configuration file and make sure you don’t see an error:

ln -s /etc/Nginx/sites-available/laravel /etc/Nginx/sites-enabled/

nginx -t

The virtual host was created for laravel. You should now restart the NGINX service:

systemctl restart Nginx

Step 7: Install the laravel

Before proceeding to install laravel, you need to make sure that the unzip feature is installed on the VPS. If you don’t have this tool yet, install it using the following command:

sudo apt install unzip -y

We already have a directory for laravel at ‘/var/www/laravel’. Go to this directory:

cd /var/www/laravel

Install laravel with the Composer command. There are two ways to install laravel. One is to install it through the laravel installer. Second, install it with the help of “Composer create project“. We will use the second option. Run the following command:

composer create-project laravel/laravel.

You must wait for the laravel installation. After a few minutes, the process is complete. We need to change the access to the laravel project to the user ‘www-data‘.

chown -R www-data:root /var/www/laravel

chmod 755 /var/www/laravel/storage

The final step: Test

In the Virtual Host configuration file, we define the domain name for laravel as ‘‘. Open your browser and enter the phrase. (Your domain name may be different from this one. So use your domain name). In this case, you should see the laravel homepage.

How to install Laravel 5.6 with NGINX on Ubuntu 18.04;



Use of this Site is subject to express terms of use. By using this site, you signify that you agree to be bound by these