how to install Laravel on Ubuntu with Nginx

Step 1 – Installing Nginx

sudo apt update

sudo apt install nginx

Step 2 – Adjusting the Firewall

Before testing Nginx, the firewall software needs to be adjusted to allow access to the service. Nginx registers itself as a service with ufw upon installation, making it straightforward to allow Nginx access.

List the application configurations that ufw knows how to work with by typing:

sudo ufw app list

You should get a listing of the application profiles:

Available applications:
  Nginx Full
  Nginx HTTP
  Nginx HTTPS

As demonstrated by the output, there are three profiles available for Nginx:

Nginx Full: This profile opens both port 80 (normal, unencrypted web traffic) and port 443 (TLS/SSL encrypted traffic)

Nginx HTTP: This profile opens only port 80 (normal, unencrypted web traffic)

Nginx HTTPS: This profile opens only port 443 (TLS/SSL encrypted traffic)

It is recommended that you enable the most restrictive profile that will still allow the traffic you’ve configured. Right now, we will only need to allow traffic on port 80.

You can enable this by typing:

sudo ufw allow 'Nginx HTTP'

Step 3 – Checking your Web Server

Systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2020-04-20 16:08:19 UTC; 3 days ago
     Docs: man:nginx(8)
 Main PID: 2369 (nginx)
    Tasks: 2 (limit: 1153)
   Memory: 3.5M
   CGroup: /system.slice/nginx.service
           ├─2369 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
           └─2380 nginx: worker process

Step 4 – Install PHP 8.0

- sudo apt update
- sudo apt install lsb-release ca-certificates apt-transport-https software-properties-common -y - sudo add-apt-repository ppa:ondrej/php - sudo apt install php8.0- php8.0-amqp php8.0-common php8.0-gd php8.0-ldap php8.0-odbc php8.0-readline php8.0-sqlite3 php8.0-xsl php8.0-curl php8.0-gmp php8.0-mailparse php8.0-opcache php8.0-redis php8.0-sybase php8.0-ast php8.0-dba php8.0-igbinary php8.0-mbstring php8.0-pgsql php8.0-rrd php8.0-tidy php8.0-yaml php8.0-bcmath php8.0-dev php8.0-imagick php8.0-memcached php8.0-phpdbg php8.0-smbclient php8.0-uuid php8.0-zip php8.0-bz2 php8.0-ds php8.0-imap php8.0-msgpack php8.0-pspell php8.0-snmp php8.0-xdebug php8.0-zmq php8.0-cgi php8.0-enchant php8.0-interbase php8.0-mysql php8.0-psr php8.0-soap php8.0-xhprof php8.0-cli php8.0-fpm php8.0-intl php8.0-oauth php8.0-raphf php8.0-solr php8.0-xml -y
Now, we can create a file in Nginx root directory. Let's call it test PHP. Run the following command: 
- sudo vi /etc/nginx/sites-available/web.conf

Config: (you can using chown www-data:www-data -R folder)

server {

        listen 80;

        server_name website_name;

        index index.html index.htm index.php;

        root  /var/www/website/public;

        charset utf-8;

        gzip off;

        error_log /var/log/nginx/website.error.log;

        access_log /var/log/nginx/website.access.log;

        location / {

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


        client_max_body_size 2048M;

        location ~ \.php$ {

            fastcgi_keep_conn on;

            fastcgi_pass   unix:/run/php/php8.0-fpm.sock;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;

            fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;

            fastcgi_param PATH_INFO $fastcgi_path_info;

            fastcgi_param  APPLICATION_ENV production;

            include        fastcgi_params;

            fastcgi_buffer_size 32k;

            fastcgi_busy_buffers_size 64k;

            fastcgi_buffers 4 32k;