Better configuration creation for php

This commit is contained in:
2022-02-08 12:06:00 +01:00
parent d2fd71d5c9
commit a9491aa84a

View File

@@ -5,7 +5,7 @@ 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"
phpPackages="${phpName}-{fpm,gd,mysql,curl,xml,zip,intl,mbstring,bz2,ldap,apcu,bcmath,gmp,imagick,igbinary,redis,smbclient,cli,common,opcache,readline} imagemagick"
aptOpt=
step_config() {
@@ -84,34 +84,75 @@ include ${snippetLetsencryptLoc};
step_4_info() { echo "Installation of $phpName packages:"
echoinfo "$phpPackages"; }
step_4_alias() { ALIAS="php"; }
step_4() {
exe apt install $phpPackages $aptOpt
exe apt install $(eval echo $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
phpFpmConfig="memory_limit = 1024M
apc.enable_cli=1
output_buffering = Off
max_execution_time = 3600
max_input_time = 3600
post_max_size = 10240M
upload_max_filesize = 10240M
date.timezone = Europe/Berlin
session.cookie_secure = True
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.memory_consumption=128
opcache.revalidate_freq=1
opcache.save_comments=1
opcache.revalidate_freq=1"
allow_url_fopen = 1"
phpFpmConfigBu="register_argc_argv=on"
phpCliConfigLocation="/etc/php/${phpVersion}/cli/conf.d/90-custom_pi.ini"
phpCliConfig="\
apc.enable_cli=1
output_buffering = Off
max_execution_time = 3600
max_input_time = 3600
post_max_size = 10240M
upload_max_filesize = 10240M
date.timezone = Europe/Berlin"
phpPoolConfigLocation="/etc/php/${phpVersion}/fpm/pool.d/www.conf"
phpFpmIniLocation="/etc/php/${phpVersion}/fpm/php-fpm.conf"
step_5_info() { echo "Configuration of ${phpName} fpm and cli"; }
step_5() {
local AvailableRAM=$(awk '/MemAvailable/ {printf "%d", $2/1024}' /proc/meminfo)
local AverageFPM=$(ps --no-headers -o 'rss,cmd' -C php-fpm8.0 | awk '{ sum+=$1 } END { printf ("%d\n", sum/NR/1024,"M") }')
local FPMS=$((AvailableRAM/AverageFPM))
local PMaxSS=$((FPMS*2/3))
local PMinSS=$((PMaxSS/2))
local PStartS=$(((PMaxSS+PMinSS)/2))
addConf -c "$phpFpmConfig" "$phpFpmConfigLocation"
addConf -c "$phpCliConfig" "$phpCliConfigLocation"
addConf -a "" "$phpFpmIniLocation"
exe sed -i "s|;emergency_restart_threshold.*|emergency_restart_threshold = 10|g" "$phpFpmIniLocation"
exe sed -i "s|;emergency_restart_interval.*|emergency_restart_interval = 1m|g" "$phpFpmIniLocation"
exe sed -i "s|;process_control_timeout.*|process_control_timeout = 10|g" "$phpFpmIniLocation"
addConf -a "" "$phpPoolConfigLocation"
exe sed -i "s/;env\[HOSTNAME\] = /env[HOSTNAME] = /" "$phpPoolConfigLocation"
exe sed -i "s/;env\[TMP\] = /env[TMP] = /" "$phpPoolConfigLocation"
exe sed -i "s/;env\[TMPDIR\] = /env[TMPDIR] = /" "$phpPoolConfigLocation"
exe sed -i "s/;env\[TEMP\] = /env[TEMP] = /" "$phpPoolConfigLocation"
exe sed -i "s/;env\[PATH\] = /env[PATH] = /" "$phpPoolConfigLocation"
exe sed -i 's/pm.max_children =.*/pm.max_children = '$FPMS'/' "$phpPoolConfigLocation"
exe sed -i 's/pm.start_servers =.*/pm.start_servers = '$PStartS'/' "$phpPoolConfigLocation"
exe sed -i 's/pm.min_spare_servers =.*/pm.min_spare_servers = '$PMinSS'/' "$phpPoolConfigLocation"
exe sed -i 's/pm.max_spare_servers =.*/pm.max_spare_servers = '$PMaxSS'/' "$phpPoolConfigLocation"
exe sed -i "s/;pm.max_requests =.*/pm.max_requests = 1000/" "$phpPoolConfigLocation"
echoseq -n "Restarting ${phpName} ... "
exe service ${phpName}-fpm restart && echoseq "ok"
}