How to Deploy Laravel Application with Nginx on Ubuntu?

Laravel is a PHP Framework and Nginx is a Web-Browser which can be installed on Ubuntu. Nginx is more popular nowadays because it is lightweight. Here, we will deploy a Laravel application on Nginx.

First of all, your server should have installed Nginx and PHP-FPM. Please click on this link to install and configure PHP-FPM and Nginx. We believe you have already have installed this so we are proceeding further.

We need to access the server with the root or sudo user because we will edit the Nginx virtual host files to deploy our Laravel Application.

  1. Update Ubuntu repository with its package.

    # sudo apt update
    # sudo apt upgrade
  2. Let us reboot the server once.

  3. Once server is up, Install Nginx using below command.

    # sudo apt install nginx -y
  4. Install PHP 7.2 and PHP-FPM.

    # 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
  5. Start and Enable php 7.2

    # systemctl start php7.2-fpm
    # systemctl enable php7.2-fpm
  6. You can verify PHP-FPM running under socke file with the below command.

    # netstat -pl | grep php7.2-fpm
  7. Install MariaDB using the below Command.

    # sudo apt install mariadb-server mariadb-client -y
  8. Start and Enable MariaDB.

    # service mysql start
    # service enable mysql
  9. Here, we will configure MariaDB root password with the 'mysql_secure_installation'

    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
  10. Install PHP Composer with below Command.

    # sudo apt install composer -y
  11. Once you run the composer command, it will give the same screen as below. This means the composer is PHP Composer is installed.
  12. Let us configure the nginx virtual host for Laravel. Here, we will use '/var/www/laravel_tet' directory for our project. First, we will create the same directory.

    # mkdir -p /var/www/laravel_test
  13. We should test nginx to make sure there is no error.

    ln -s /etc/nginx/sites-available/laravel_test /etc/nginx/sites-enabled/nginx -t
  14. Restart the nginx service.

    # service nginx restart
  15. Go to the folder laravel_test which we have defined earlier.

    # cd /var/www/laravel_test
  16. Run the following composer command to install Laravel.

    # composer create-project laravel_test/laravel_test
  17. Now, change the ownership of the Laravel project directory to 'www-data' user. Change the permission of the storage directory to 755.

    # chown -R www-data:root /var/www/laravel_test
    # chmod 755 /var/www/laravel_test
  18. Inorder to test the Laravel, we will need to access the Domain name which we have added in the virtual host configuration file. Once you access the Domain name, it should give the laravel hostname.

Related Articles

How to block an IP address using .htaccess?

You can block traffic coming from any specific IP addresses with .htaaccess file. Please refer to...

How to Manage Linux VPS (SSD and Traditional) from VPS Management Portal?

We offer SolusVM VPS management portal with SSD Linux VPS and Ttraditional Linux VPS plans....

How to Change LiteSpeed WebServer Port on cPanel?

Please refer to the following steps to change the LiteSpeed WebServer Port on cPanel. Login to...

How to install FFmpeg on CentOS7 VPS?

FFmpeg is a multimedia codex that can convert audio and video files into different formats....

How to Install MySQL on CentOS 7.x?

MySQL is one of the popular database management systems. For now, MySQL is no longer within...

  • 0 Users Found This Useful

Was this answer helpful?