hiryu85
8/30/2016 - 4:44 PM

Crea nuovo virtual host

Crea nuovo virtual host

#!/bin/sh
# Crea nuovo virtual host
# Autore: Chialastri Mirko <chialastri.mirko@gmail.com>

# Configuration
VHOST_BASE="/Users/Hiryu/Apps"
APACHE_VHOST_ROOT="/etc/apache2"
# End Configuration


echo "Nome virtual host:"
read -r DOMAIN

HTTPD_CONTENT="`cat <<EOF
<VirtualHost *:80>
	DocumentRoot "${VHOST_BASE}/${DOMAIN}"
	ServerName  ${DOMAIN}

	CustomLog  /dev/null combined

	<IfModule mod_fastcgi.c>
	</IfModule>

	<Directory "${VHOST_BASE}/${DOMAIN}">
		Options FollowSymLinks
		AllowOverride All
		Require all granted
	</Directory>
</VirtualHost>
EOF`"

echo $DOMAIN
echo '---'
echo  "${HTTPD_CONTENT}"
echo

read -p "Confermi? [Y/y/N/n] " -n 1 -r
if [[ ! $REPLY =~ ^[Yy]$ ]]
	then
	echo
	exit 0
fi;

echo
HTTPD_CONF="${VHOST_BASE}/${DOMAIN}/httpd.conf"

# Si assicura che la cartella di destinazione esista
mkdir -p ${VHOST_BASE}/${DOMAIN}

echo $HTTPD_CONTENT > ${HTTPD_CONF}

echo "Creo collegamento simbolico ${HTTPD_CONF} -> ${APACHE_VHOST_ROOT}/sites-enabled/${DOMAIN}"
sudo ln -s ${HTTPD_CONF} ${APACHE_VHOST_ROOT}/sites-enabled/${DOMAIN}