Setup Laravel PHP Framework on Ubuntu 16.04 | 17.10 | 18.04 with Nginx and PHP 7.2-FPM Support

The steps below shows user an easy way to install Laravel with Nginx web server on Ubuntu to enable its PHP framework. After installing, visit Laravel main website for help building your apps.

Laravel is a flexible opensource PHP framework for web artisans. It can be used as an alternative to CodeIgniter framework. Laravel is designed for ease of use to allow developers create great applications.

If you’re looking for a simple and straightforward PHP framework to design your next application, you’ll find Laravel to be useful. This brief tutorial is going to show students and new users how to install Laravel PHP framework on Ubuntu 16.04 | 17.10 | 18.04 with Nginx and PHP 7.2 support.

To get started with installing Laravel, follow the steps below:

Step 1: Install Nginx

For this tutorial, we’re going to be installing Nginx web server. to do that, run the commands below.l

sudo apt update
sudo apt install nginx

After installing, the commads below can be used to stop, start and enable Nginx service to always start up with the server boots.

sudo systemctl stop nginx.service
sudo systemctl start nginx.service
sudo systemctl enable nginx.service

Step 2: Install PHP 7.2-FPM and Related Modules

Laravel is based on PHP. so you’ll need to install it. To install PHP and related modules run the commands below

sudo apt install php7.2-fpm php7.2-mbstring php7.2-xmlrpc php7.2-soap php7.2-gd php7.2-xml php7.2-cli php7.2-zip

After install PHP, run the commands below to open PHP-FPM default file.

sudo nano /etc/php/7.2/fpm/php.ini

Then make the change the following lines below in the file and save.

memory_limit = 256M
upload_max_filesize = 64M

Step 3: Install Composer to Download Laravel

Run the commands below to install composer package and install. you must have curl package installed for the commands to work. if not, just run sudo apt install curl to install it.

curl -sS | sudo php -- --install-dir=/usr/local/bin --filename=composer

Change into Laravel directory and run the commands below to download and install Laravel for th e project you want to create. name the project whatever you want. for this post, we’re calling it MyProject.

cd /var/www/html
sudo composer create-project laravel/laravel MyProject --prefer-dist

After running the commands above, a new project directory will be created. Run the commands below to set the correct permissions for that directory.

sudo chown -R www-data:www-data /var/www/html/MyProject/
sudo chmod -R 755 /var/www/html/MyProject/

Step 5: Configure Nginx

Finally, configure Apahce2 site configuration file for Laravel. This file will control how users access Laravel content. Run the commands below to create a new configuration file called laravel

sudo nano /etc/nginx/sites-available/laravel

Then copy and paste the content below into the file and save it. Replace the highlighted line with your own domain name and directory root location.

server {
    listen 80;
    listen [::]:80;
    root /var/www/html/MyProject/public;
    index  index.php index.html index.htm;

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

    location ~ \.php$ {
       include snippets/fastcgi-php.conf;
       fastcgi_pass             unix:/var/run/php/php7.2-fpm.sock;
       fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;


Save the file and exit.

Step 5: Enable the Laravel

After configuring the VirtualHost above, enable it by running the commands below

sudo ln -s /etc/nginx/sites-available/laravel /etc/nginx/sites-enabled/

Step 6: Restart Nginx

To load all the settings above, restart Nginx by running the commands below.

sudo systemctl restart nginx.service

Then open your browser and browse to the server domain name. You should see Laravel page.

You should then see Laravel default home screen. and you’re ready to begin building your apps based on Laravel PHP framework.

laravel ubuntu install

That’s it!

You may also like the post below:


  1. Enrique Serrano

    Thanks bro, i had a lot of problems

    1. Hello there and thank you very much for this article!
      I had one little problem while getting this to run and wanted to ask if anyone could explain? I followed all steps precisely and it worked as a charm. Couldnt open the laravel app through the server_name (samply.diz) i gave in the config-file though. The thing i needed to do extra, what wasnt explained here, was to add an entry for the server_name in my /etc/hosts-File. I added “ samply.diz” and it right away worked. Is it just assumed everyone knows that this needs to be done and i am just a rookie (what i actually am) or do i have some kind of special case? Answer would be appreciated. Thanks 🙂

  2. I really appreciate the article, it helped me a lot with setting up my first Laravel server, thank you! With that said, though, I think it’s important to point out that the setup presented here is just the very essentials, but for most users more set up will be necessary.
    For example, by the end of this tutorial, no database service has been set. By default Laravel assumes you’ll be using MySQL for data storage. It’s also missing NodeJs (and by extension NPM) which are critical for the application to compile front-end stuff (less, scss, vueJs, …) .

  3. I feel like the following line

    “listen [::]:80;”

    should be

    “listen [::]:80 ipv6only=on default_server;”

    Otherwise, Nginx will can’t see whether the incoming request is for IPv4 or IPv6.

  4. Thanks very much, It was helpful

  5. 403 Forbidden , why?? can help??

  6. I am getting 403 Forbidden.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.