Skip to content

Instantly share code, notes, and snippets.

@sebbdk
Forked from ribeiroevandro/create-site
Last active December 29, 2015 10:19
Show Gist options
  • Save sebbdk/7656161 to your computer and use it in GitHub Desktop.
Save sebbdk/7656161 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Script for creating Virtual Servers On Apache
# Check for the correct parameters
if [ $# -eq 0 ]; then
echo 'domain param missing'
echo 'example: create-site your-domain.com'
exit 0
fi
# Assign Variables
SITE=$1 + ".dev.com";
# Create the Directory which will contain your Virtual Site
if [ ! -d /var/www/$SITE ]; then
mkdir /var/www/$SITE
fi
# Create the Config file for your virtual site
echo "<VirtualHost *:80>" > /etc/apache2/sites-available/$SITE
echo " # Admin email, Server Name (domain name) and any aliases" >> /etc/apache2/sites-available/$SITE
echo " ServerAdmin webmaster@localhost" >> /etc/apache2/sites-available/$SITE
echo " ServerName $SITE" >> /etc/apache2/sites-available/$SITE
echo " ">>/etc/apache2/sites-available/$SITE
echo " DocumentRoot /var/www/$SITE" >> /etc/apache2/sites-available/$SITE
echo " LogLevel warn" >> /etc/apache2/sites-available/$SITE
echo " ErrorLog /var/log/$SITE-error.log" >> /etc/apache2/sites-available/$SITE
echo " CustomLog /var/log/$SITE-access.log combined" >> /etc/apache2/sites-available/$SITE
echo " <Directory "/var/www/$SITE">" >> /etc/apache2/sites-available/$SITE
echo " Options Indexes FollowSymLinks" >> /etc/apache2/sites-available/$SITE
echo " AllowOverride All" >> /etc/apache2/sites-available/$SITE
echo " Order allow,deny" >> /etc/apache2/sites-available/$SITE
echo " Allow from all" >> /etc/apache2/sites-available/$SITE
echo " </Directory>" >> /etc/apache2/sites-available/$SITE
echo "</VirtualHost>" >> /etc/apache2/sites-available/$SITE
# Create the Sym Link to enable your Virtual Site
if [ ! -L /etc/apache2/sites-enabled/$SITE ]; then
ln -s /etc/apache2/sites-available/$SITE /etc/apache2/sites-enabled/
fi
# Include server name (domain name) and any aliases in file hosts
echo "127.0.0.1 $SITE" >> /etc/hosts
echo "127.0.1.1 $SITE" >> /etc/hosts
echo "" >> /etc/hosts
# Reload in service the apache2
service apache2 reload
# Change the user and group of the folder in apache
chown -Rf 755 /var/www/$SITE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment