Common Installation

sudo apt-get upgrade -y
sudo apt-get install vim git wget curl zip unzip htop software-properties-common mysql-client awscli -y

Add Swap Memory

sudo fallocate -l 5G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Add Swapiness

sudo sysctl vm.swappiness=10
sudo vi /etc/sysctl.conf
vm.swappiness=10

PHP - Setup

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update -y
sudo apt-get install php8.1 php8.1-fpm php8.1-cli -y
sudo apt-get install -y php8.1-mbstring php8.1-gd php8.1-bcmath php8.1-zip php8.1-xml php8.1-intl php8.1-mysql php8.1-curl
sudo systemctl restart php8.1-fpm.service
sudo systemctl enable php8.1-fpm.service

Composer - Setup

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer

Nginx - Setup

sudo apt-get install -y nginx
sudo systemctl restart nginx
sudo systemctl enable nginx
sudo chown -R ubuntu:ubuntu /var/www/
mkdir -p /var/www/cloud-school.in/current
cd /var/www/cloud-school.in/current
composer create-project laravel/laravel .
sudo vi /etc/nginx/sites-available/default 

Nginx - Config Code

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name _;
    root /var/www/cloud-school.in/current/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

Restart Nginx and Permission

sudo systemctl restart nginx
sudo chmod -R 777 /var/www/cloud-school.in/current/storage