1. Update the package index and upgrade the existing packages on the server:
    sudo apt update
    sudo apt upgrade
  2. Install Nginx:
    sudo apt install nginx
  3. Allow Nginx through the firewall:
    sudo ufw allow 'Nginx HTTP'
  4. Check if Nginx is running by visiting your server’s IP address in a web browser:
    http://your_server_ip_address
  5. Install MySQL:
    sudo apt install mysql-server
  6. Run a secure installation of MySQL and set the root password:
    sudo mysql_secure_installation
  7. Install PHP and necessary extensions:
    sudo apt install php-fpm php-mysql
  8. Configure Nginx to use PHP:
    sudo nano /etc/nginx/sites-available/default
    Replace the contents of the file with the following:
    server {
      listen 80;
      root /var/www/html;
      index index.php index.html index.htm;
      server_name your_domain;
      location / {
        try_files $uri $uri/ =404;
      }
      location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
      }
    }

    Save and close the file.
  9. Restart Nginx:
    sudo systemctl restart nginx
  10. Create a test PHP file:
    sudo nano /var/www/html/info.php
    Add the following code and save the file:
    <?php
    phpinfo();
    ?>
  11. Visit the test PHP file in a web browser by entering the following URL:
    http://your_server_ip_address/info.php
  12. Delete the test PHP file after verifying the installation:
    sudo rm /var/www/html/info.php

Leave a Reply