100 lines
3.5 KiB
Bash
Executable File
100 lines
3.5 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# vhost-stack
|
|
# https://git.stack-source.com/msb/vhost-stack
|
|
# Copyright (c) 2022 Matthew Saunders Brown <matthewsaundersbrown@gmail.com>
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
# load include file
|
|
source $(dirname $0)/vhost.sh
|
|
|
|
help()
|
|
{
|
|
thisfilename=$(basename -- "$0")
|
|
echo "Add virtualhost to this server."
|
|
echo ""
|
|
echo "usage: $thisfilename -d <domain> -u <username> [-h]"
|
|
echo ""
|
|
echo " -h Print this help."
|
|
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 " If need be run vhost-user-add.sh first."
|
|
echo " Or use vhost-deploy.sh instead to automatically generate username."
|
|
}
|
|
|
|
vhost:getoptions "$@"
|
|
|
|
# check for domain (virtualhost)
|
|
if [[ -z $domain ]]; then
|
|
echo "domain is required"
|
|
exit
|
|
fi
|
|
|
|
# check for username
|
|
if [[ -z $username ]]; then
|
|
echo "username is required"
|
|
exit
|
|
fi
|
|
|
|
if [[ ! -d /home/$username ]]; then
|
|
echo "home dir for $username does not exist"
|
|
exit 1
|
|
fi
|
|
|
|
if [[ -d /srv/www/$domain ]]; then
|
|
chown $username:$username /srv/www/$domain
|
|
chmod 755 /srv/www/$domain
|
|
else
|
|
install -d -o $username -g $username -m 755 /srv/www/$domain
|
|
fi
|
|
|
|
if [[ -d /srv/www/$domain/html ]]; then
|
|
chown $username:$username /srv/www/$domain/html
|
|
chmod 755 /srv/www/$domain/html
|
|
else
|
|
install -d -o $username -g $username -m 755 /srv/www/$domain/html
|
|
fi
|
|
|
|
if [[ ! -e /home/$username/$domain ]]; then
|
|
ln -s /srv/www/$domain /home/$username/$domain
|
|
chown -h $username:$username /home/$username/$domain
|
|
fi
|
|
|
|
if [[ -d /usr/jails/$username ]]; then
|
|
if [[ ! -d /usr/jails/$username/srv/www/$domain ]]; then
|
|
install -d -o $username -g $username -m 755 /usr/jails/$username/srv/www/$domain
|
|
mount --bind /srv/www/$domain /usr/jails/$username/srv/www/$domain
|
|
echo "/srv/www/$domain /usr/jails/$username/srv/www/$domain 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@$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
|
|
|
|
# create & enable apache config
|
|
/usr/local/bin/vhost-enable.sh -d $domain -m VHostHTTP
|