In this post, we will see how to configure a Laravel project with PHP 7.2 using Nginx as web server on Ubuntu Linux version 18.x

Let’s jump directly into the steps:

    1. Add php repository
      add-apt-repository ppa:ondrej/php
    2. Update ubuntu
      sudo apt-get update
    3. Install utility programs
      sudo apt-get install git zip unzip
    4. Install nginx
      sudo apt-get install nginx
    5. Install PHP 7.2 and dependencies
      sudo apt-get install php7.2 php7.2-mysql php7.2-fpm php7.2-mbstring php7.2-curl php7.2-xml
    6. Configure nginx for php
      sudo nano /etc/nginx/sites-available/default

      Under server {, add index.php in the file list. The line will look like:

      index index.php index.html index.htm index.nginx-debian.html;

      Next step is to specify the location of php processor. There is a block in the file that starts with location ~ \.php$ {. Un-comment it and make it look like this:

      location ~ \.php$ {
             include snippets/fastcgi-php.conf;
             ## With php-fpm (or other unix sockets):
             fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
             ## With php-cgi (or other tcp sockets):
             # fastcgi_pass;
    7. Press Ctrl +X , Y + Enter to save and exit
    8. Restart nginx with the command:
      sudo service nginx restart
    9. Install composer
      sudo apt-get -y install composer
    10. Install MySQL
      sudo apt-get -y install mysql-server mysql-client
    11. Secure MySQL installation
      sudo mysql_secure_installation
    12. Install phpmyadmin
      sudo apt-get -y install phpmyadmin

      Do not select any web server when asked as nginx is not in the list. Simply press tab key to move to OK button

    13. We need to tell nginx how to find phpmyadmin. By default nginx looks everything in /var/www/html directory whereas phpmyadmin is installed in /usr/share directory.
      Hence, we need to create a symbolic link for phpmyadmin in the /var/www/html directory. Execute the following command:

      sudo ln -s /usr/share/phpmyadmin /var/www/html
    14. Now we will setup a new laravel project. The web directory for nginx is /var/www/html
      cd /var/www/html
    15. Next, we will create a new laravel project named laratest. Execute following commands one after another:
      sudo composer create-project laravel/laravel laratest

      Note: There could be a warning that don’t run composer as root, but for now, you can ignore it as we are only creating a new project

    16. Make nginx as the owner of the project with the command:
      sudo chown -R www-data:www-data laratest
    17. Laravel needs to write data in its storage directory, so we need to set write permission for this directory. Execute the command:
      cd laratest
      sudo chmod -R 755 storage bootstrap/cache
    18. Laravel is setup now and you can access your website in browser at URL: