#!/bin/bash serverName="nginx" serverPackages="nginx" serverSourceUrl="https://nginx.org/packages/debian/" phpVersion="7.4" phpName="php${phpVersion}" phpPackages="${phpName}-fpm ${phpName}-json ${phpName}-mysql ${phpName}-curl ${phpName}-intl ${phpName}-gd ${phpName}-zip ${phpName}-xml ${phpName}-mbstring php-imagick php-apcu php-redis" aptOpt= step_config() { if [ $QUIET -ne 0 ] ; then aptOpt="-y" fi } step_1_info() { echoinfoArgs "[DEBIAN RELEASE]" echo "Setup latest apt source list for $serverName" echoinfo "$serverSourceUrl" } step_1_alias() { ALIAS="setup"; } step_1() { shift local osRelease=$1 endCheckEmpty osRelease "Debian release not provided" echoseq " [I] Setup apt source for $serverName $serverSourceUrl" local srvSource="deb $serverSourceUrl $osRelease nginx" addConf -s "$srvSource" "$serverSourceLoc" if [ $? -eq 0 ] ; then echoseq " [I] Get repository key for $serverSourceUrl"Y exe apt install gnupg $aptOpt exe apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ABF5BD827BD9BF62 fi } serverSourceLoc="/etc/apt/sources.list.d/nginx.list" step_2_info() { echo "Installation of $serverName packages:" echoinfo "$serverPackages" } step_2_alias() { ALIAS=install; } step_2() { exe apt update exe apt install $serverPackages $aptOpt endReturn -o $? "Failed to install $serverName" } step_3_info() { echo "Basic nginx configuration for initial letsencrypt certificate creation"; } step_3() { # Writing acme-challenge code snipped for certbot web root authentication addConf -c "$snippetLetsencrypt" "$snippetLetsencryptLoc" # Writing minimal default (see below) addConf -c "$siteDefaultIp4" "$siteDefaultLoc" # try fix errors on first install attempt # (possible missing ipv6 support on system) if [ $ERNO -ne 0 ] ; then exe apt install nginx $aptOpt fi # create webroot exe mkdir -p "$siteLetsencryptWww" echoseq -n "Restarting Nginx..." exe service nginx restart && echoseq "ok" endReturn -o $? "Failed to install $serverName" } snippetLetsencryptLoc="/etc/nginx/snippets/letsencrypt.conf" siteLetsencryptWww="/var/www/letsencrypt" snippetLetsencrypt="\ location ^~ /.well-known/acme-challenge/ { default_type \"text/plain\"; root ${siteLetsencryptWww}; }" siteDefaultLoc="/etc/nginx/sites-available/default" siteDefaultIp4="server { listen 80 default_server; include ${snippetLetsencryptLoc}; }" step_4_info() { echo "Installation of $phpName packages:" echoinfo "$phpPackages"; } step_4() { exe apt install $phpPackages $aptOpt } phpFpmConfigLocation="/etc/php/${phpVersion}/fpm/conf.d/90-custom_pi.ini" phpFpmConfig="post_max_size=64M upload_max_filesize=100M max_execution_time=600 apc.enable_cli=1 date.timezone = Europe/Berlin opcache.enable=1 opcache.enable_cli=1 opcache.interned_strings_buffer=8 opcache.max_accelerated_files=10000 opcache.memory_consumption=128 opcache.save_comments=1 opcache.revalidate_freq=1" phpCliConfigLocation="/etc/php/${phpVersion}/cli/conf.d/90-custom_pi.ini" phpCliConfig="\ date.timezone = Europe/Berlin" step_5_info() { echo "Configuration of ${phpName} fpm and cli"; } step_5() { addConf -c "$phpFpmConfig" "$phpFpmConfigLocation" addConf -c "$phpCliConfig" "$phpCliConfigLocation" echoseq -n "Restarting ${phpName} ... " exe service ${phpName}-fpm restart && echoseq "ok" } step_6_info() { echo "Installation notes"; } step_6_alias() { ALIAS="notes"; } step_6() { cat <