92 lines
3.1 KiB
Bash
Executable File
92 lines
3.1 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# vhost-stack
|
|
# https://git.stack-source.com/msb/vhost-stack
|
|
# MIT License Copyright (c) 2021 Matthew Saunders Brown
|
|
|
|
# load include file
|
|
source $(dirname $0)/vhost.sh
|
|
|
|
# check for and set virtualhost
|
|
if [ -n "$1" ]; then
|
|
if vhost::validate_domain $1; then
|
|
virtualhost=$1
|
|
else
|
|
echo "ERROR: $1 is not a valid domain name."
|
|
exit 1
|
|
fi
|
|
else
|
|
echo "virtualhost not set"
|
|
exit 1
|
|
fi
|
|
|
|
# check for and set username
|
|
if [ -n "$2" ]; then
|
|
username=$2
|
|
else
|
|
echo "username not set"
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -d /home/$username ]; then
|
|
echo "home dir for $username does not exist"
|
|
exit 1
|
|
fi
|
|
|
|
if [ -d /srv/www/$virtualhost ]; then
|
|
chown $username:$username /srv/www/$virtualhost
|
|
chmod 755 /srv/www/$virtualhost
|
|
else
|
|
install -d -o $username -g $username -m 755 /srv/www/$virtualhost
|
|
fi
|
|
|
|
if [ -d /srv/www/$virtualhost/html ]; then
|
|
chown $username:$username /srv/www/$virtualhost/html
|
|
chmod 755 /srv/www/$virtualhost/html
|
|
else
|
|
install -d -o $username -g $username -m 755 /srv/www/$virtualhost/html
|
|
fi
|
|
|
|
if [ ! -e /home/$username/$virtualhost ]; then
|
|
ln -s /srv/www/$virtualhost /home/$username/$virtualhost
|
|
chown -h $username:$username /home/$username/$virtualhost
|
|
fi
|
|
|
|
if [ -d /usr/jails/$username ]; then
|
|
if [ ! -d /usr/jails/$username/srv/www/$virtualhost ]; then
|
|
install -d -o $username -g $username -m 755 /usr/jails/$username/srv/www/$virtualhost
|
|
mount --bind /srv/www/$virtualhost /usr/jails/$username/srv/www/$virtualhost
|
|
echo "/srv/www/$virtualhost /usr/jails/$username/srv/www/$virtualhost none bind 0 0" >> /etc/fstab.jails
|
|
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
|
|
echo "pm.max_children = 12" >> /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@$virtualhost" >> /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
|
|
|
|
# create & enable apache config
|
|
/usr/local/bin/vhost-enable.sh VHostHTTP $virtualhost
|