lemp ubuntu code example

Example: ubuntu lemp

// NGINX
sudo apt update
sudo apt install nginx

// MYSQL
sudo apt install mysql-server
sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
FLUSH PRIVILEGES;

exit;
sudo mysql -u root -p

// PHP
sudo apt install php-fpm php-mysql

// Website
sudo mkdir /var/www/your_domain
sudo chown -R $USER:$USER /var/www/your_domain

// Website Configuration
sudo nano /etc/nginx/sites-available/your_domain

server {
    listen 80;
    server_name your_domain www.your_domain;
    root /var/www/your_domain;

    index index.html index.htm index.php;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
     }

    location ~ /\.ht {
        deny all;
    }

}

sudo ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx



// Place your application in your folder
nano /var/www/your_domain/index.html

// Check PHP 
nano /var/www/your_domain/info.php

<?php
phpinfo();