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 which helps you to build modern PHP applications. This popular tool is the first choice of many developers as is a good idea for a streamlined development process.  In this article, we try to teach you How to install Laravel 5.6 with NGINX on Ubuntu 18.04. You can visit the packages available in Eldernode to purchase a Ubuntu VPS server.

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. If you have not your own VPS, it is time to touch this experience.

Recommended Article: How to Reset forgotten Debian Linux password [Top Way]


To let this tutorial work better, please consider the below Prerequisites:
a non-root user with sudo privileges
To set up, follow our Initial Setup with Ubuntu 18.04.



How to install Laravel 5.6 with NGINX on Ubuntu 18.04

Join us with this article to let us show you deploying a simple Laravel application environment in mind, which requires a few common steps. Do not the miss the same tutorial if you are interested in learning for Laravel on CentOS 8.

Let’s have a look at the requires steps:

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 1 :  Update Ubuntu Virtual Server

First, you 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 server:

ssh root@ip  

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



Step 2 : Install NGINX

Reboot your virtual private server and reconnect it using SSH.

At this point, you 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  curl -I localhost



Step 3 : Install PHP7.2 and PHP-FPM

You have  got NGINX installed so far, and now you need to go into installing PHP-FPM version 7. You 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, you are able to install PHP and PHP-FPM on the Ubuntu Virtual Private Server. Now you need to move on to the next steps.

Recommended Article: How to install Node.js on CentOS 8


Step 4 : Install MariaDB Database

This is optional, but when your laravel project is based on MYSQL you should do it for your project. You 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 is also done.

Step 5 : 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, you will configure Virtual Host for laravel. But before doing so, you need to decide on the directory needed for our laravel project. You 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 server_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

You 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“. You 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. You 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

Step 8 : Test

In the Virtual Host configuration file, you 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.


In this article, you learned how to install Laravel 5.6 with NGINX on Ubuntu 18.04. By passing the above steps successfully, now you can use the Laravel and enjoy its features. In case you are using Ubuntu 20.04, use the related guide.

How useful was this post?

Click on a star to rate it!

Average rating 1 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

We Are Waiting for your valuable comments and you can be sure that it will be answered in the shortest possible time.

15 thoughts on “How to install Laravel 5.6 with NGINX on Ubuntu 18.04

    1. Yes it is. It uses .env which contains a default application key but you need to generate a new one for your laravel deployment for secure purposes.

    1. In this situation, you can also clone your git project inside laravel directory and after that start to installing the required packages by using composer.

    1. Use below commands after adding the PHP repository.
      apt-get install python-software-properties.
      add-apt-repository ppa:ondrej/php.
      apt-get update.
      apt-get install php7

      Point: Be careful to execute commands with Root access in the user interface, you must use the Sudo command before all commands.

Leave a Reply

Your email address will not be published. Required fields are marked *

We are by your side every step of the way

Think about developing your online business; We will protect it compassionately

We are by your side every step of the way


7 days a week, 24 hours a day