#!/usr/bin/env bash # Author : Allan Christensen # First Created : 05012022 (DD-MM-YYYY) # Description : Installs Nginx on Ubuntu 24.04 # License : MIT License (see LICENSE file for details) # # Are we root # if [[ $(id -u) -ne 0 ]]; then echo "" && echo "Must be root or use sudo" && echo "" ; exit 1; fi # # Check if services are allready running # for svc in nginx php*-fpm; do if systemctl is-active --quiet "$svc"; then printf "\n%s is already running, cannot continue...\n\n" "${svc^}" ; exit 1 ; fi ; done # # Let's go # clear # # Install and configure Nginx # apt install -y nginx rm /var/www/html/index.nginx-debian.html > /dev/null 2>&1 rm /etc/nginx/snippets/snakeoil.conf > /dev/null 2>&1 mkdir -p /var/cache/nginx/fcgi mkdir -p /etc/nginx/static-sites # # Clone nginx-snippets; if nginx-snippets exists then just pull latest changes # nginxsnippets="/etc/nginx/nginx-snippets" repo="https://git.x-files.dk/webserver/nginx-snippets.git" if [[ -d "$nginxsnippets/.git" ]]; then git -C "$nginxsnippets" pull --quiet; else git clone --quiet "$repo" "$nginxsnippets"; fi # # Install Php-Fpm # apt install -y php-fpm php-curl php-dom php-gd php-imagick php-ldap php-mbstring php-mysql php-pear php-soap php-xml php-zip # # Determine Php version # phpver=$(php -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;') phpfpm="php${phpver}-fpm" phpclidir="/etc/php/$phpver/cli" phpfpmdir="/etc/php/$phpver/fpm" # # Configure Nginx # cp "$phpclidir"/php.ini "$phpclidir"/php.ini.orig cp "$phpfpmdir"/php.ini "$phpfpmdir"/php.ini.orig cp "$nginxsnippets"/nginxconf/nginx.conf /etc/nginx cp "$nginxsnippets"/nginxconf/nginx.conf.high.perf /etc/nginx cp "$nginxsnippets"/nginxconf/default /etc/nginx/sites-available/default sed -i "s/PHPVERSION/$phpfpm/" /etc/nginx/nginx.conf sed -i "s/PHPVERSION/$phpfpm/" /etc/nginx/nginx.conf.high.perf # # Creating a high performance www.conf file for optional or later use # cp /etc/php/"$phpver"/fpm/pool.d/www.conf /etc/nginx/www.conf.high.perf sed -i "s/pm.max_children = 5/pm.max_children = 50/" /etc/nginx/www.conf.high.perf sed -i "s/pm.start_servers = 2/pm.start_servers = 15/" /etc/nginx/www.conf.high.perf sed -i "s/pm.max_spare_servers = 3/pm.max_spare_servers = 10/" /etc/nginx/www.conf.high.perf sed -i "s/;pm.process_idle_timeout = 10s/pm.process_idle_timeout = 10s/" /etc/nginx/www.conf.high.perf sed -i "s/;pm.max_requests = 500/pm.max_requests = 500/" /etc/nginx/www.conf.high.perf # # Adjusting php.ini with stuff I usually forget # sed -i 's/;max_input_vars = 1000/max_input_vars = 3000/' "$phpclidir"/php.ini sed -i 's/;max_input_vars = 1000/max_input_vars = 3000/' "$phpfpmdir"/php.ini sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 50M/' "$phpfpmdir"/php.ini sed -i 's/max_file_uploads = 20/max_file_uploads = 100/' "$phpfpmdir"/php.ini sed -i 's/;date.timezone =/date.timezone = Europe\/Copenhagen/' "$phpclidir"/php.ini sed -i 's/;date.timezone =/date.timezone = Europe\/Copenhagen/' "$phpfpmdir"/php.ini # # Restart Nginx and Php-Fpm # systemctl restart "$phpfpm" systemctl restart nginx # # All done # printf "\n\nAll Done...\n\n" # # End of script #