Skip to content

Instantly share code, notes, and snippets.

@marioheber
Forked from tsi/newsite
Last active August 29, 2015 14:01
Show Gist options
  • Save marioheber/6109b939f6db17b1db58 to your computer and use it in GitHub Desktop.
Save marioheber/6109b939f6db17b1db58 to your computer and use it in GitHub Desktop.
Create Virtual Host in Apache server for Terminal Linux usage .
#!/bin/bash
# This script creates virtual hosts.
# You should put export PATH="path to this file" in .bashrc
# and run it with sudo addvhost
# Default path
www=/var/www
# Uncomment this block for input different path for localhost
# echo "Enter path (default value: $www)"
# read path
# ### Check inputs
# if [ "$path" != "" ]
# then
# echo "New path $path"
# www=$path
# fi
# Set the path to your localhost
echo "Enter directory name under $www"
read dn
echo "Enter site name "
read sn
# Create the file with VirtualHost configuration in /etc/apache2/site-available/
echo "<VirtualHost *:80>
DocumentRoot $www/$dn
ServerName $sn
<Directory $www/$dn/>
Options +Indexes +FollowSymLinks +MultiViews +Includes
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/$sn-error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/$sn-access.log combined
</VirtualHost>" > /etc/apache2/sites-available/$sn.conf
# Add the host to the hosts file
echo 127.0.0.1 $sn >> /etc/hosts
# Enable the site
a2ensite $sn.conf
# Reload Apache2
/etc/init.d/apache2 restart
echo "Your new site is available at http://$sn"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment