Created
September 9, 2012 07:23
-
-
Save turbod/3683156 to your computer and use it in GitHub Desktop.
Setting up Apache virtualhost and project dir.
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/zsh | |
# Setting up Apache virtualhost and project dir. | |
# Is localhost subdomain the project url? | |
localhostSubdomain=0 | |
# The document root inside the project dir. | |
root="" | |
# The workspace directory. | |
workpspace="$HOME/www/" | |
while getopts :p:r:l opt | |
do | |
case "$opt" in | |
p) | |
project="$OPTARG" | |
;; | |
r) | |
root="/$OPTARG" | |
;; | |
l) | |
localhostSubdomain=1 | |
;; | |
*) echo "Unknown option: $opt";; | |
esac | |
done | |
shift $[ $OPTIND - 1 ] | |
# Is localhost subdomain the project | |
if [[ $localhostSubdomain -eq 1 ]]; then | |
projectHost="$project.localhost" | |
else | |
echo "$project" | |
fi | |
subdomainRootDir="$workpspace$project$root" | |
tpl="<VirtualHost *:80> | |
ServerAdmin webmaster@localhost | |
ServerName $projectHost | |
DocumentRoot $subdomainRootDir | |
<Directory /> | |
Options FollowSymLinks | |
AllowOverride All | |
Allow from All | |
</Directory> | |
ErrorLog /var/log/apache2/error.$project.log | |
# Possible values include: debug, info, notice, warn, error, crit, | |
# alert, emerg. | |
LogLevel warn | |
CustomLog /var/log/apache2/access.$project.log combined | |
</VirtualHost>" | |
echo $tpl > $project.tmp | |
sudo mv $project.tmp /etc/apache2/sites-available/$project | |
sudo a2ensite $project | |
temp=$HOME/hosts.tmp | |
exec < /etc/hosts | |
while read line | |
do | |
echo "$line" >> $temp; | |
done | |
echo "127.0.0.1 $projectHost" >> $temp | |
sudo mv $temp /etc/hosts; | |
sudo service apache2 restart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment