Static Pages

L.E.M.P


Before anything begins; first thing first;

$ apt-get update --allow-releaseinfo-change
$ apt-get install --reinstall ca-certificates
$ apt-get upgrade -y
$ apt-get upgrade --fix-missing
$ apt-get install nano wget perl curl sudo -y
$ sudo apt -y dist-upgrade
$ sudo apt --purge autoremove
$ sudo apt update && sudo apt upgrade

$ adduser nginx
$ adduser nginx sudo
$ su - nginx
$ exit
$ apt -y purge Apache2* bind* exim* ufw firewalld libapache2-mod-php* postfix

Step 1. Install Nginx

$ sudo apt-get install nginx -y
$ systemctl start nginx
$ systemctl enable nginx
$ systemctl status nginx
  http://i.p address 
$ chown www-data:www-data /var/www/html -R

Step 2. Install DB

$ apt install mariadb-server mariadb-client -y
$ systemctl start mariadb
$ systemctl status mariadb
$ systemctl enable mariadb

$ mysql_secure_installation
  type y to set the root password
$ mariadb -u root
  exit;  

Step 3. Install PHP

$ sudo apt -y install php software-properties-common 
$ sudo apt -y install php-common php-mysql php-xml php-xmlrpc php-curl php-gd php-imagick php-cli php-fpm php-json php-imap php-mbstring php-opcache php-soap php-dev php-cgi php-zip php-intl php-bcmath php-pear
$ sudo apt -y install libmcrypt-dev libreadline-dev mcrypt 
$ sudo apt -y install php8.2 php8.2-fpm php8.2-common php8.2-mysql php8.2-xml php8.2-xmlrpc 
$ sudo apt -y install php8.2-curl php8.2-gd php8.2-cli php8.2-dev php8.2-imap 
$ sudo apt -y install php8.2-mbstring php8.2-soap php8.2-zip php8.2-cgi 
$ sudo apt -y install php7.4 php7.4-fpm php7.4-common php7.4-mysql php7.4-xml php7.4-xmlrpc $ sudo apt -y install php7.4-curl php7.4-gd php7.4-cli php7.4-dev php7.4-imap php7.4-mbstring $ sudo apt -y install php7.4-soap php7.4-zip php7.4-cgi
$ apt -y purge Apache2* bind* exim* ufw firewalld libapache2-mod-php* postfix
$ sudo nano /etc/php/8.2/fpm/pool.d/www.conf
user = nginx
group = nginx
listen.owner = nginx
listen.group = nginx
$ systemctl start php8.2-fpm
$ systemctl enable php8.2-fpm
$ systemctl status php8.2-fpm

Step 4. Configure Nginx to use PHP Processor

$ sudo nano /etc/nginx/sites-enabled/default
--------------------------------------------
server {
        listen 80 default_server;
        listen [::]:80 default_server;
    server_name _;
    root /var/www/html;
    index index.php index.html index.htm;
    location / {
    try_files $uri $uri/ /index.php?$args;
               }
     location ~ \.php$ {
     include snippets/fastcgi-php.conf;
     fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
                       }
     }
$ sudo nginx -t 
$ sudo systemctl reload nginx 
http://server_IP/

=============Create Website=======================================

Use full domain name or whatever word!
$ sudo mkdir -p /var/www/html/website1
$ sudo nano /var/www/html/website1/index.html
$ nano /etc/nginx/conf.d/domain.conf 
server {
    listen 80;
    server_name website1.com;
    root /var/www/html/website1;
    index index.php index.html index.htm;
     location / {
     try_files $uri $uri/ /index.php?$args;
               }
     location ~ \.php$ {
     include snippets/fastcgi-php.conf;
     fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
                  }
    access_log /var/log/nginx/website1-access.log;
    error_log /var/log/nginx/website1-error.log;
}

------------OR------------------------------------------------

server {
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com;
    root /var/www/html/website1;
    index index.php index.html index.htm;
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
   location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php8.2-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param SCRIPT_NAME $fastcgi_script_name;
    include fastcgi_params;
}
    access_log /var/log/nginx/website1-access.log;
    error_log /var/log/nginx/website1-error.log;
    location ~ /\.ht {
        deny all;
    }
}
$ sudo nginx -t 
$ sudo systemctl restart nginx

Step 5. Automatic restart of Nginx

$ systemctl restart nginx
$ mkdir -p /etc/systemd/system/nginx.service.d/
$ nano /etc/systemd/system/nginx.service.d/restart.conf
 Add the following lines to the file
 [Service]
Restart=always
RestartSec=5s

$ systemctl daemon-reload
$ pkill nginx
$ systemctl status nginx

Step 6. Install Memcached

Memcached allows server side caching for faster data retrieval.
$ sudo apt -y install memcached
$ sudo apt -y install php8.2-memcached
$ sudo service php8.2-fpm restart
$ sudo service nginx restart

Step 7.Install phpMyAdmin with Domain

$ sudo apt -y install phpmyadmin
$ ln -s /usr/share/phpmyadmin /var/www/html
$ cd /var/www/html/phpmyadmin
$ sudo cp config.sample.inc.php config.inc.php
$ sudo nano config.inc.php
         $cfg['blowfish_secret'] = '';
$ chown -R www-data:www-data /var/www/html/phpmyadmin
$ chmod -R 755 /var/www/html/phpmyadmin
sudo rm -rf /var/www/html/phpmyadmin/setup
$ nano /etc/nginx/conf.d/domain.conf  // this is in conf.d not sites_available

server {
        listen 80;
        server_name Domain;
        root /var/www/html/phpmyadmin;
        index index.php index.html index.htm;
        error_log /var/log/nginx/phpmyadmin_error.log;
        access_log /var/log/nginx/phpmyadmin_access.log;
        client_max_body_size 100M;
        location / {
                try_files $uri $uri/ /index.php?$args;
        }
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php8.2-fpm.sock;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
}

$ rm /etc/nginx/sites-enabled/default
$ rm /etc/nginx/sites-available/default
$ nginx -t
$ systemctl reload nginx
http://domain1.com

Step 8 .Install Webmin

$ curl -o setup-repos.sh https://raw.githubusercontent.com/webmin/webmin/master/setup-repos.sh
$ sh setup-repos.sh
$ apt -y install webmin --install-recommends
( change port: $ sudo nano -w /etc/webmin/miniserv.conf )
Reduce the size of the initramfs
$ nano /etc/initramfs-tools/conf.d/compress COMPRESS=xz reduce it further with sed -i s,MODULES=most,MODULES=dep,g /etc/initramfs-tools/initramfs.conf update-initramfs -u
Install Let’s Encrypt on Your Domain
$ add-apt-repository ppa:certbot/certbot $ apt-get update -y $ apt-get install python-certbot-nginx -y $ certbot --nginx -d example.com Set Up Let’s Encrypt SSL Certificate Auto-Renewal $ crontab -e Add the following line: 12 8 * * * root /usr/bin/certbot renew >/dev/null 2>&1 Renew the SSL certificate manually: $ certbot renew --dry-run