Skip to content

Instantly share code, notes, and snippets.

@kneath
Created October 22, 2008 01:55
Show Gist options
  • Save kneath/18513 to your computer and use it in GitHub Desktop.
Save kneath/18513 to your computer and use it in GitHub Desktop.
#!/bin/sh
# VHostit
# Simple bash script to add a virtual host to apache & your hosts file on OS X
#
# Installation
# Throw vhostit.sh somewhere in your path. I like to copy it to /usr/local/bin/vhostit
# Usage
# `vhostit domain.tld` from within the directory you want to host.
# The domain.tld will be added to your hosts file and a VirtualHost added to your apache's httpd.conf\
usage(){
echo "vhostit by Kyle Neath (http://warpspire.com)"
echo ""
echo "Adds the current directory to your httpd & hosts file under the domain you choose"
echo "Assumes default OS X locations (/etc/hosts & /etc/apache2/httpd.conf)"
echo ""
echo "Usage $0 [domain]"
exit
}
case $1 in
-h) usage;;
--help) usage;;
esac
HOSTS_FILE="/etc/hosts"
HTTPD_FILE="/etc/apache2/httpd.conf"
if [ -n "$1" ]; then
NEW_HOSTS="127.0.0.1\t$1"
$(echo $NEW_HOSTS >> $HOSTS_FILE)
NEW_HTTPD="\n<VirtualHost *:80>\n\tServerName $1\n\tDocumentRoot \"$(pwd)\"\n\t<directory \"$(pwd)\">\n\t\tOrder allow,deny\n\t\tAllow from all\n\t</directory>\n</VirtualHost>"
$(echo $NEW_HTTPD >> $HTTPD_FILE)
$(apachectl restart)
else
usage;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment