Install Nginx on Ubuntu

Instal Nginx

apt-get update -y
apt-get upgrade -y
apt-get install nginx -y
systemctl start nginx
systemctl enable nginx
nginx -v

Install PHP7.4

apt-get install php7.4 -y
php --version
apt-get install php7.4-fpm php7.4-cli php7.4-mysql php7.4-curl php7.4-json -y
systemctl start php7.4-fpm
systemctl enable php7.4-fpm

Nginx Configuration

nano /etc/nginx/sites-available/example.conf
server {

    listen 80;

    server_name test.example.com;

    root /var/www/html;

    index index.php index.html index.htm;



    location ~ \.php$ {

        include snippets/fastcgi-php.conf;

        fastcgi_pass unix:/run/php/php7.4-fpm.sock;

    }

}
ln -s /etc/nginx/sites-available/example.conf /etc/nginx/sites-enabled/

Check configuration

nginx -t
systemctl restart nginx

Setup Firewall

ufw allow 80/tcp
ufw allow 443/tcp

Install cerbot for SSL

apt install certbot python3-certbot-nginx
certbot --nginx -d example.com -d www.example.com

Comments