add PHP-FPM pm.max_children variable option

This commit is contained in:
Matthew Saunders Brown 2023-04-10 11:36:52 -07:00
parent d6a484f95a
commit 424d6c36fd
3 changed files with 24 additions and 5 deletions

View File

@ -13,11 +13,12 @@ help()
thisfilename=$(basename -- "$0") thisfilename=$(basename -- "$0")
echo "Add virtualhost to this server." echo "Add virtualhost to this server."
echo "" echo ""
echo "usage: $thisfilename -d <domain> -u <username> [-h]" echo "usage: $thisfilename -d <domain> -u <username> [-x <fpmmax>] [-h]"
echo "" echo ""
echo " -h Print this help." echo " -h Print this help."
echo " -d <domain> Domain name to add as a VirtualHost. www. subdomain is automatically aliased." echo " -d <domain> Domain name to add as a VirtualHost. www. subdomain is automatically aliased."
echo " -u <username> Username to install VirtualHost for. Username must already exist." echo " -u <username> Username to install VirtualHost for. Username must already exist."
echo " -x <fpmmax> PHP-FPM pm.max_children. Optional, defaults to 4, recommended range 2-12 on Shared Server."
echo " If need be run vhost-user-add.sh first." echo " If need be run vhost-user-add.sh first."
echo " Or use vhost-deploy.sh instead to automatically generate username." echo " Or use vhost-deploy.sh instead to automatically generate username."
} }
@ -36,6 +37,11 @@ if [[ -z $username ]]; then
exit exit
fi fi
# check for php-fpm process manager max children
if [[ -z $fpmmax ]]; then
fpmmax=4
fi
if [[ ! -d /home/$username ]]; then if [[ ! -d /home/$username ]]; then
echo "home dir for $username does not exist" echo "home dir for $username does not exist"
exit 1 exit 1
@ -82,7 +88,7 @@ if [[ ! -f /etc/php/$phpVersion/fpm/pool.d/$username.conf ]]; then
echo "listen.owner = www-data" >> /etc/php/$phpVersion/fpm/pool.d/$username.conf echo "listen.owner = www-data" >> /etc/php/$phpVersion/fpm/pool.d/$username.conf
echo "listen.group = www-data" >> /etc/php/$phpVersion/fpm/pool.d/$username.conf echo "listen.group = www-data" >> /etc/php/$phpVersion/fpm/pool.d/$username.conf
echo "pm = ondemand" >> /etc/php/$phpVersion/fpm/pool.d/$username.conf echo "pm = ondemand" >> /etc/php/$phpVersion/fpm/pool.d/$username.conf
echo "pm.max_children = 12" >> /etc/php/$phpVersion/fpm/pool.d/$username.conf echo "pm.max_children = $fpmmax" >> /etc/php/$phpVersion/fpm/pool.d/$username.conf
echo "pm.process_idle_timeout = 3s;" >> /etc/php/$phpVersion/fpm/pool.d/$username.conf echo "pm.process_idle_timeout = 3s;" >> /etc/php/$phpVersion/fpm/pool.d/$username.conf
echo "php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -fwebmaster@$domain" >> /etc/php/$phpVersion/fpm/pool.d/$username.conf echo "php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -fwebmaster@$domain" >> /etc/php/$phpVersion/fpm/pool.d/$username.conf
# restart php$phpVersion-fpm # restart php$phpVersion-fpm

View File

@ -13,12 +13,13 @@ help()
thisfilename=$(basename -- "$0") thisfilename=$(basename -- "$0")
echo "Add virtualhost to this server, including shell user and MySQL database." echo "Add virtualhost to this server, including shell user and MySQL database."
echo "" echo ""
echo "usage: $thisfilename -d <domain> [OPTIONS]" echo "usage: $thisfilename -d <domain> [-u <username>] [-p <password>] [-x <fpmmax>] [-j] [-w] [-h]"
echo "" echo ""
echo " -h Print this help." echo " -h Print this help."
echo " -d <domain> Domain name of VirtualHost to remove." echo " -d <domain> Domain name of VirtualHost to remove."
echo " -u <username> Username to use for this virtualhost. Optional, defaults to first 8 alphanumeric characters of virtualhost." echo " -u <username> Username to use for this virtualhost. Optional, defaults to first 8 alphanumeric characters of virtualhost."
echo " -p <password> Password for username. Optional, random password generated if none specified." echo " -p <password> Password for username. Optional, random password generated if none specified."
echo " -x <fpmmax> PHP-FPM pm.max_children. Optional, defaults to 4, recommended range 2-12 on Shared Server."
echo " -j Whether or not to jail the user. Optional, default is to not jail user." echo " -j Whether or not to jail the user. Optional, default is to not jail user."
echo " -w Write user & mysql info to files. Warning! This inlcudes the unencrypted passwords." echo " -w Write user & mysql info to files. Warning! This inlcudes the unencrypted passwords."
exit exit
@ -107,8 +108,13 @@ if ! grep -q "^$username:" /etc/passwd; then
fi fi
fi fi
# check for php-fpm process manager max children
if [[ -z $fpmmax ]]; then
fpmmax=4
fi
# add virtualhost # add virtualhost
/usr/local/bin/vhost-add.sh -d $domain -u $username > /dev/null 2>&1 /usr/local/bin/vhost-add.sh -d $domain -u $username -x $fpmmax > /dev/null 2>&1
# add mysql database # add mysql database
if [[ -n $write ]]; then if [[ -n $write ]]; then

View File

@ -53,7 +53,7 @@ function vhost::validate_domain () {
function vhost:getoptions () { function vhost:getoptions () {
local OPTIND local OPTIND
while getopts "cd:i:m:o:p:u:jhnvw" opt ; do while getopts "cd:i:m:o:p:u:jhnvwx:" opt ; do
case "${opt}" in case "${opt}" in
h ) # display help and exit h ) # display help and exit
help help
@ -97,6 +97,13 @@ function vhost:getoptions () {
w ) # write - store data in file w ) # write - store data in file
write=true write=true
;; ;;
x ) # php-fpm pm.max_children
fpmmax=${OPTARG}
if [[ $fpmmax != +([[:digit:]]) ]] || [[ $fpmmax -eq 0 ]]; then
echo "ERROR: $fpmax for -x max_children not a valid number."
exit
fi
;;
\? ) \? )
echo "Invalid option: $OPTARG" echo "Invalid option: $OPTARG"
exit 1 exit 1