move php-fpm config from vhost-add to user-add

This commit is contained in:
Matthew Saunders Brown 2023-04-16 10:50:42 -07:00
parent a4cc2542d1
commit 5425e7a168
3 changed files with 52 additions and 38 deletions

View File

@ -13,12 +13,11 @@ 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> [-x <fpmmax>] [-h]" echo "usage: $thisfilename -d <domain> -u <username> [-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."
} }
@ -37,11 +36,6 @@ 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
@ -74,29 +68,19 @@ if [[ -d /usr/jails/$username ]]; then
fi fi
fi fi
# php-fpm pool # set sendmail_path in php-fpm, but only if not already set
vhost::set-phpVersion vhost::set-phpVersion
if [[ ! -f /etc/php/$phpVersion/fpm/pool.d/$username.conf ]]; then if [[ -f /etc/php/$phpVersion/fpm/pool.d/$username.conf ]]; then
# create /etc/php/$phpVersion/fpm/pool.d/$username.conf if ! /bin/grep -q "^php_admin_value\[sendmail_path\]" /etc/php/$phpVersion/fpm/pool.d/$username.conf; then
echo "[$username]" > /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 "user = $username" >> /etc/php/$phpVersion/fpm/pool.d/$username.conf # restart php-fpm if it's active
echo "group = $username" >> /etc/php/$phpVersion/fpm/pool.d/$username.conf if systemctl is-active --quiet php$phpVersion-fpm ; then
if [ -d /usr/jails/$username ]; then # check for valid config before restarting
echo "chroot = /usr/jails/$username" >> /etc/php/$phpVersion/fpm/pool.d/$username.conf if /usr/sbin/php-fpm$phpVersion -t >/dev/null 2>&1 ; then
fi systemctl reload php$phpVersion-fpm
echo "listen = /run/php/php$phpVersion-fpm-$username.sock" >> /etc/php/$phpVersion/fpm/pool.d/$username.conf else
echo "listen.owner = www-data" >> /etc/php/$phpVersion/fpm/pool.d/$username.conf echo "WARNING: php-fpm$phpVersion configuration test failed"
echo "listen.group = www-data" >> /etc/php/$phpVersion/fpm/pool.d/$username.conf fi
echo "pm = ondemand" >> /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 "php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -fwebmaster@$domain" >> /etc/php/$phpVersion/fpm/pool.d/$username.conf
# restart php$phpVersion-fpm
if systemctl is-active --quiet php$phpVersion-fpm ; then
if /usr/sbin/php-fpm$phpVersion -t >/dev/null 2>&1 ; then
systemctl reload php$phpVersion-fpm
else
echo "WARNING: php-fpm$phpVersion configuration test failed"
fi fi
fi fi
fi fi

View File

@ -93,11 +93,15 @@ if ! grep -q "^$username:" /etc/passwd; then
if [[ -z "$password" ]]; then if [[ -z "$password" ]]; then
password=`/usr/bin/pwgen 12 1` password=`/usr/bin/pwgen 12 1`
fi fi
# check for and set php-fpm process manager max children
if [[ -z $fpmmax ]]; then
fpmmax=$FPM_MAX
fi
# add user # add user
if [[ -n $write ]]; then if [[ -n $write ]]; then
/usr/local/bin/vhost-user-add.sh -u $username -p "$password" -w /usr/local/bin/vhost-user-add.sh -u $username -p "$password" -x $fpmmax -w
else else
/usr/local/bin/vhost-user-add.sh -u $username -p "$password" /usr/local/bin/vhost-user-add.sh -u $username -p "$password" -x $fpmmax
fi fi
# if jail option is set then jail user # if jail option is set then jail user
if [[ -n $jail ]]; then if [[ -n $jail ]]; then
@ -108,13 +112,8 @@ 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 -x $fpmmax > /dev/null 2>&1 /usr/local/bin/vhost-add.sh -d $domain -u $username > /dev/null 2>&1
# add mysql database # add mysql database
if [[ -n $write ]]; then if [[ -n $write ]]; then

View File

@ -13,12 +13,13 @@ help()
thisfilename=$(basename -- "$0") thisfilename=$(basename -- "$0")
echo "Add system user to server." echo "Add system user to server."
echo "" echo ""
echo "usage: $thisfilename -u <username> [-p <password> [-i <uid>] [-w] [-h]" echo "usage: $thisfilename -u <username> [-p <password> [-i <uid>] [-x <fpmmax>] [-w] [-h]"
echo "" echo ""
echo " -h Print this help." echo " -h Print this help."
echo " -u <username> System username to add to server." echo " -u <username> System username to add to server."
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 " -i <uid> Numberic User ID to assign to user. Optional, next available uid set if none specified." echo " -i <uid> Numberic User ID to assign to user. Optional, next available uid set if none specified."
echo " -x <fpmmax> PHP-FPM pm.max_children. Optional, defaults to 4, recommended range 2-12 on Shared Server."
echo " -w Write user info to /home/username/.passwd." echo " -w Write user info to /home/username/.passwd."
exit exit
} }
@ -87,3 +88,33 @@ if [[ -n $write ]]; then
echo "$userpasswdinfo" > /home/$username/.passwd echo "$userpasswdinfo" > /home/$username/.passwd
fi fi
fi fi
# php-fpm pool
vhost::set-phpVersion
if [[ ! -f /etc/php/$phpVersion/fpm/pool.d/$username.conf ]]; then
# create /etc/php/$phpVersion/fpm/pool.d/$username.conf
echo "[$username]" > /etc/php/$phpVersion/fpm/pool.d/$username.conf
echo "user = $username" >> /etc/php/$phpVersion/fpm/pool.d/$username.conf
echo "group = $username" >> /etc/php/$phpVersion/fpm/pool.d/$username.conf
if [ -d /usr/jails/$username ]; then
echo "chroot = /usr/jails/$username" >> /etc/php/$phpVersion/fpm/pool.d/$username.conf
fi
echo "listen = /run/php/php$phpVersion-fpm-$username.sock" >> /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 "pm = ondemand" >> /etc/php/$phpVersion/fpm/pool.d/$username.conf
# check for and set php-fpm process manager max children
if [[ -z $fpmmax ]]; then
fpmmax=$FPM_MAX
fi
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
# restart php$phpVersion-fpm
if systemctl is-active --quiet php$phpVersion-fpm ; then
if /usr/sbin/php-fpm$phpVersion -t >/dev/null 2>&1 ; then
systemctl reload php$phpVersion-fpm
else
echo "WARNING: php-fpm$phpVersion configuration test failed"
fi
fi
fi