-
-
Save fcenobi/670a64121d203ad63677836e39eeed12 to your computer and use it in GitHub Desktop.
Apache VirtualHost Template with variable replacement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<VirtualHost *:80> | |
ServerAdmin {USER}@cslavoie.com | |
ServerName {DOMAIN} | |
ServerAlias www.{DOMAIN} | |
ServerAlias {USER}.localhost | |
ServerAlias {USER}.static.cslavoie.com | |
DocumentRoot {DOC_ROOT} | |
<Directory {DOC_ROOT}> | |
AllowOverride All | |
Order allow,deny | |
Allow From All | |
</Directory> | |
AddHandler php-script .php | |
Action php-script /php5.fastcgi virtual | |
Alias /php5.fastcgi /var/www/fastcgi/php5.fastcgi | |
FastCGIExternalServer /var/www/fastcgi/php5.fastcgi -socket /var/run/php-fpm/{USER}.sock | |
LogLevel warn | |
CustomLog /var/log/apache2/{USER}.access.log combined | |
ErrorLog /var/log/apache2/{USER}.error.log | |
</VirtualHost> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Apache VirtualHost Template with variable replacement | |
if [ $# -lt 2 ]; then | |
echo "Usage: $(basename $0) user domain" >&2 | |
exit 1 | |
fi | |
user="$1" | |
domain="$2" | |
path="/home/$user/www" | |
template="/etc/apache2/sites-available/apache-template" | |
if [ ! -d "$path" ]; then | |
echo "Web directory $path doesn’t exists" >&2 | |
exit 2 | |
fi | |
if [ ! -f "$template" ]; then | |
echo "Template $template doesn’t exists" >&2 | |
exit 2 | |
fi | |
# Escape slashes | |
doc_root=$(echo "$path" | sed 's/\//\\\//g'); | |
sed -e "s/{USER}/$user/g" -e "s/{DOC_ROOT}/$doc_root/g" -e "s/{DOMAIN}/$domain/g" $template |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment