Add vhost.sh
This commit is contained in:
commit
3dbb601e93
1 changed files with 77 additions and 0 deletions
77
vhost.sh
Normal file
77
vhost.sh
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
#!/bin/bash -e
|
||||
|
||||
# Requires proftp, apache 2.4 and php7
|
||||
|
||||
if [$1 == 0]
|
||||
then
|
||||
echo "No argument given"
|
||||
break
|
||||
else
|
||||
continue
|
||||
fi
|
||||
|
||||
echo " Creating user..."
|
||||
PASSWD=$(openssl rand -base64 10)
|
||||
USER=$(openssl rand -base64 5)
|
||||
mkdir -p /srv/${1}/{htdocs,log/{http,https}}
|
||||
useradd --shell /bin/ftponly --home /srv/${1} -U ${USER}
|
||||
echo "${USER}:${PASSWD}" | chpasswd
|
||||
chown -R ${USER}: /srv/${1}/
|
||||
echo " User ${USER} is created with the password ${PASSWD} "
|
||||
|
||||
echo " Creating mysql database and user..."
|
||||
|
||||
mysql --execute"create database ${USER};"
|
||||
mysql --execute"create user '${USER}'@'%' identified by '${PASSWD}';"
|
||||
mysql --execute"grant all on ${USER}.* to '${USER}'@'%' identified by '${PASSWD}' "
|
||||
|
||||
echo " mysql is configure with the user ${USER} and database ${USER} with the passwowd ${PASSWD} "
|
||||
|
||||
echo "MYSQL DATABASE : ${USER}" >> /srv/${1}/info.txt
|
||||
echo "MYSQL USER/PASSWORD : ${USER}" >> /srv/${1}/info.txt
|
||||
echo "FTP USER : ${USER}" >> /srv/${1}/info.txt
|
||||
echo "FTP PASSWORD : ${PASSWD}" >> /srv/${1}/info.txt
|
||||
|
||||
|
||||
echo "Creating apache vhost..."
|
||||
|
||||
echo "<VirtualHost *:80>" >> /etc/apache2/sites-enabled/${1}.conf
|
||||
echo "ProxyPassMatch ^/(.*\.php(/.*)?)$ unix:/run/php/${1}.sock|fcgi://127.0.0.1:9000/srv/${1}/htdocs/ retry=1" >>/etc/apache2/sites-enabled/${1}.conf
|
||||
echo "ServerName ${1}" >> /etc/apache2/sites-enabled/${1}.conf
|
||||
echo "#ServerAlias" >> /etc/apache2/sites-enabled/${1}.conf
|
||||
echo "DocumentRoot /srv/${1}/htdocs" >>/etc/apache2/sites-enabled/${1}.conf
|
||||
echo "<Directory /srv/${1}/htdocs>" >>/etc/apache2/sites-enabled/${1}.conf
|
||||
echo "Options FollowSymLinks" >>/etc/apache2/sites-enabled/${1}.conf
|
||||
echo "AllowOverride All" >> /etc/apache2/sites-enabled/${1}.conf
|
||||
echo "Require all granted" >> /etc/apache2/sites-enabled/${1}.conf
|
||||
echo "</Directory>" >> /etc/apache2/sites-enabled/${1}.conf
|
||||
echo "ErrorLog /srv/${1}/log/plain/error.log" >> /etc/apache2/sites-enabled/${1}.conf
|
||||
echo "CustomLog /srv/${1}/log/plain/access.log common" >> /etc/apache2/sites-enabled/${1}.conf
|
||||
echo "</VirtualHost>" >> /etc/apache2/sites-enabled/${1}.conf
|
||||
|
||||
echo " Vhost is created in /etc/apache2/sites-enabled/${1}.conf"
|
||||
|
||||
echo " Creating PHP7.0 pool..."
|
||||
|
||||
echo "[${1}]" >> /etc/php/7.0/fpm/pool.d/${1}.conf
|
||||
echo "user = ${USER}" >> /etc/php/7.0/fpm/pool.d/${1}.conf
|
||||
echo "group = ${USER}" >> /etc/php/7.0/fpm/pool.d/${1}.conf
|
||||
echo "listen = /var/run/php/$pool.sock" >> /etc/php/7.0/fpm/pool.d/${1}.conf
|
||||
echo "listen.owner = www-data" >> /etc/php/7.0/fpm/pool.d/${1}.conf
|
||||
echo "listen.group = www-data" >> /etc/php/7.0/fpm/pool.d/${1}.conf
|
||||
echo "pm = dynamic" >> /etc/php/7.0/fpm/pool.d/${1}.conf
|
||||
echo "pm.max_children = 8" >> /etc/php/7.0/fpm/pool.d/${1}.conf
|
||||
echo "pm.start_servers = 2" >> /etc/php/7.0/fpm/pool.d/${1}.conf
|
||||
echo "pm.min_spare_servers = 1" >> /etc/php/7.0/fpm/pool.d/${1}.conf
|
||||
echo "pm.max_spare_servers = 3" >> /etc/php/7.0/fpm/pool.d/${1}.conf
|
||||
echo "chdir = /" >> /etc/php/7.0/fpm/pool.d/${1}.conf
|
||||
echo "pm.process_idle_timeout = 10" >> /etc/php/7.0/fpm/pool.d/${1}.conf
|
||||
echo "php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f no-reply@${1}" >> /etc/php/7.0/fpm/pool.d/${1}.conf
|
||||
echo "php_admin_value[mail.log] = /srv/${1}/log/mail.log" >> /etc/php/7.0/fpm/pool.d/${1}.conf
|
||||
echo "php_admin_value[open_basedir] = /srv/${1}:/tmp:/usr/bin" >> /etc/php/7.0/fpm/pool.d/${1}.conf
|
||||
|
||||
service php7.0-fpm restart
|
||||
service apache2 restart
|
||||
|
||||
" You can find logins for FTP and database in /srv/${1}/info.txt "
|
||||
exit 0
|
||||
Loading…
Reference in a new issue