Ubuntu Server Setup For Nginx, PHP, MariaDB And Security Configuration
sudo apt-get update -y sudo apt-get upgrade -y sudo apt-get install nginx -y sudo apt install net-tools -y
sudo apt install software-properties-common sudo add-apt-repository ppa:ondrej/php sudo apt-get install php8.1-fpm -y sudo apt-get install php8.1-pdo php8.1-mysql php8.1-curl -y
sudo apt-get install vnstat
sudo apt install mariadb-server -y
mariadb
ALTER USER 'root'@'localhost' IDENTIFIED BY 'KerryKing61'; exit
sudo mysql_secure_installation
mysql -u root -p
CREATE DATABASE HANGADELEN; CREATE USER 'HANGADELEN'@'localhost' IDENTIFIED BY 'KerryKing61'; GRANT ALL PRIVILEGES ON *.* TO 'HANGADELEN'@'localhost'; FLUSH PRIVILEGES; exit
sudo visudo
www-data ALL=(ALL) NOPASSWD: /root/ufw.sh www-data ALL=(ALL) NOPASSWD: /usr/sbin/ufw www-data ALL=(ALL) NOPASSWD: /sbin/reboot www-data ALL=(ALL) NOPASSWD: /usr/sbin/service nginx restart www-data ALL=(ALL) NOPASSWD: /usr/sbin/service mysql restart www-data ALL=(ALL) NOPASSWD: /usr/sbin/service php8.1-fmp restart
crontab -e
* * * * * /usr/bin/php /var/www/html/security/cron/cron.php && /usr/bin/php /var/www/html/security/cron/nginx-cron.php && /usr/bin/php /var/www/html/security/cron/referer-cron.php && /usr/bin/php /var/www/html/security/cron/logs-clear.php */10 * * * * /usr/sbin/service nginx reload */10 * * * * /usr/bin/php /var/www/html/security/cron/nginx-clear.php 0 3 * * 1 cd /usr/share/GeoIP && wget -O GeoLite2-Country.tar.gz "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key=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&suffix=tar.gz" && wget -O GeoLite2-ASN.tar.gz "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-ASN&license_key=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&suffix=tar.gz" && tar -xzf GeoLite2-Country.tar.gz --strip-components=1 --wildcards '*/GeoLite2-Country.mmdb' && tar -xzf GeoLite2-ASN.tar.gz --strip-components=1 --wildcards '*/GeoLite2-ASN.mmdb' && rm -f GeoLite2-*.tar.gz && systemctl restart nginx >> /var/log/nginx/HANGADELEN/maxmind_logs.log 2>&1 0 */2 * * * /root/ufw.sh
sudo apt install libnginx-mod-http-geoip2 mmdb-bin
mkdir -p /usr/share/GeoIP cd /usr/share/GeoIP
wget -O GeoLite2-Country.tar.gz "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key=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&suffix=tar.gz" wget -O GeoLite2-ASN.tar.gz "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-ASN&license_key=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&suffix=tar.gz"
tar -xzf GeoLite2-Country.tar.gz --strip-components=1 --wildcards '*/GeoLite2-Country.mmdb' tar -xzf GeoLite2-ASN.tar.gz --strip-components=1 --wildcards '*/GeoLite2-ASN.mmdb' rm -f GeoLite2-*.tar.gz
sudo chmod -R 777 /etc/nginx
sudo chmod -R 777 /var/log/nginx
sudo chmod -R 777 /var/www
sudo chmod 777 /root/god.sh sudo chmod 777 /root/ufw.sh
sudo nano /etc/systemd/system/log-monitor.service
[Unit] Description=Nginx Log Monitor After=nginx.service [Service] Type=simple ExecStart=/bin/bash /root/god.sh Restart=always RestartSec=5 [Install] WantedBy=multi-user.target
sudo systemctl daemon-reload sudo systemctl enable log-monitor.service sudo systemctl start log-monitor.service
sudo systemctl edit nginx
[Service] Restart=always RestartSec=5 LimitNOFILE=65535
sudo nano /etc/security/limits.conf
www-data soft nofile 65535 www-data hard nofile 65535 * soft nofile 65535 * hard nofile 65535 root soft nofile 65535 root hard nofile 65535
sudo nano /etc/pam.d/common-session
session required pam_limits.so
sudo systemctl daemon-reload sudo systemctl restart nginx sudo systemctl restart mysql sudo systemctl restart php8.1-fpm