Created
June 28, 2011 18:15
-
-
Save oslego/1051784 to your computer and use it in GitHub Desktop.
Create localhost website folder and add 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/sh | |
# USE AT YOUR OWN RISK. Tested on Ubuntu 11.04 with apache2. | |
# CHECK COMMENTS BEFORE RUNNING | |
# this script creates localhost website folder and adds virtualhost | |
# website name - it will append .lh for the path | |
# ex.: 'example' will be accessed as example.lh in the browser | |
website="$@" | |
if [ -z "$website" ]; then | |
echo "No website, no fun." | |
echo " " | |
exit | |
fi | |
# current user, hosts file path, apache config path and htdocs path | |
user=$(logname) | |
hostsPath="/etc/hosts" | |
apacheConf="/etc/apache2/sites-enabled/zeratul" | |
htdocs="/home/vlad/www/" | |
# virtual host lines; check the logs paths! | |
virtHost=" | |
<VirtualHost *:80> | |
ServerName ${website}.lh | |
DocumentRoot ${htdocs}${website} | |
ErrorLog ${htdocs}logs/error.log | |
CustomLog ${htdocs}logs/access.log combined | |
</VirtualHost>" | |
# create directory | |
mkdir $htdocs$website || continue | |
# change permissions and owner | |
chmod 0775 $htdocs$website | |
chown $user $htdocs$website | |
# add lines to files | |
echo "${virtHost}" >> $apacheConf | |
echo "127.0.0.1 ${website}.lh" >> $hostsPath | |
# let's get it on | |
service apache2 restart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment