Skip to content

Instantly share code, notes, and snippets.

@bvandreunen
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bvandreunen/5f39580ee796bff914e3 to your computer and use it in GitHub Desktop.
Save bvandreunen/5f39580ee796bff914e3 to your computer and use it in GitHub Desktop.
Generate vhosts
# ************************************
# Vhost template
# ************************************
<VirtualHost *:80>
ServerName %template%
## Vhost docroot
DocumentRoot "/var/www/%template%/app/html"
<Directory "/var/www/%template%/app/html">
Options Indexes FollowSymlinks MultiViews
AllowOverride All
Require all granted
<FilesMatch "\.php$">
Require all granted
SetHandler proxy:fcgi://127.0.0.1:9000
</FilesMatch>
</Directory>
## Logging
ErrorLog "/var/log/apache2/%template%_error.log"
ServerSignature Off
CustomLog "/var/log/apache2/%template%_access.log" combined
## SetEnv/SetEnvIf for environment variables
SetEnv APP_ENV dev
</VirtualHost>
# ************************************
# Vhost template
# ************************************
<VirtualHost *:80>
ServerName %template%
## Vhost docroot
DocumentRoot "/var/www/%template%/app/www"
<Directory "/var/www/%template%/app/www">
Options Indexes FollowSymlinks MultiViews
AllowOverride All
Require all granted
<FilesMatch "\.php$">
Require all granted
SetHandler proxy:fcgi://127.0.0.1:9000
</FilesMatch>
</Directory>
## Logging
ErrorLog "/var/log/apache2/%template%_error.log"
ServerSignature Off
CustomLog "/var/log/apache2/%template%_access.log" combined
## SetEnv/SetEnvIf for environment variables
SetEnv APP_ENV dev
</VirtualHost>
#!/bin/bash
#
# Usage: $ ./vhost.sh loc.sitename.com
#
# No need for sudo in vagrant/puphpet setup
#sudo -v
echo "Creating a vhost for $1"
sudo cp /etc/apache2/sites-available/template.conf /etc/apache2/sites-available/$1.conf
sudo sed -i 's/%template%/'$1'/g' /etc/apache2/sites-available/$1.conf
echo "Creating subdomain vhost for static HTML site"
sudo cp /etc/apache2/sites-available/template-html.conf /etc/apache2/sites-available/html.$1.conf
sudo sed -i 's/%template%/html.'$1'/g' /etc/apache2/sites-available/html.$1.conf
sudo a2ensite $1.conf
sudo a2ensite html.$1.conf
sudo service apache2 reload
echo "Done: vhosts for http://$1 and http://html.$1 configured."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment