-
-
Save marioheber/6109b939f6db17b1db58 to your computer and use it in GitHub Desktop.
Create Virtual Host in Apache server for Terminal Linux usage .
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 | |
# 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