Skip to content

Instantly share code, notes, and snippets.

@trey
Created March 3, 2009 22:32
Show Gist options
  • Save trey/73578 to your computer and use it in GitHub Desktop.
Save trey/73578 to your computer and use it in GitHub Desktop.
Create virtual hosts with `sudo vhost site-name`. By Jason Tan.
#!/bin/sh
DIR=/Users/$SUDO_USER/Sites/$1
if [[ ! -d $DIR && `id -u` -eq 0 ]]; then
sudo -u $SUDO_USER mkdir $DIR
sudo -u $SUDO_USER cp ~/Webs/site-template/html5.html $DIR/index.html
echo ""
echo "copied $1/index.html ..."
sudo -u $SUDO_USER cp ~/Webs/site-template/.htaccess $DIR
echo "copied $1/.htaccess ..."
sudo -u $SUDO_USER cp ~/Webs/site-template/robots.txt $DIR
echo "copied $1/robots.txt ..."
sudo -u $SUDO_USER cp -R ~/Webs/site-template/css $DIR
echo "copied $1/css/ ..."
sudo -u $SUDO_USER cp -R ~/Webs/site-template/js $DIR
echo "copied $1/js/ ..."
sudo -u $SUDO_USER cp -R ~/Webs/site-template/img $DIR
echo "copied $1/img/ ..."
VHOST=/etc/apache2/users/$SUDO_USER.conf
echo "<VirtualHost *:80>" >> $VHOST
echo "\tDocumentRoot \"$DIR\"" >> $VHOST
echo "\tServerName $1.dev" >> $VHOST
echo "</VirtualHost>\n" >> $VHOST
echo "VirtualHost created ..."
echo "127.0.0.1\t$1.dev" >> /etc/hosts
echo "host file updated ..."
apachectl restart
mate $DIR
open http://$1.dev
echo ""
echo "Done!"
else
echo "usage: sudo vhost directory"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment