Skip to content

Instantly share code, notes, and snippets.

@micahbrich
Forked from asimpson/bash_function
Last active November 3, 2015 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micahbrich/a367e3042bea6fe7b0df to your computer and use it in GitHub Desktop.
Save micahbrich/a367e3042bea6fe7b0df to your computer and use it in GitHub Desktop.
This little script sets up a custom domain in MAMP and your hosts file.
#!/bin/bash
RED="\033[0;31m"
YELLOW="\033[33m"
REDBG="\033[0;41m"
BLACKBG="\033[0;40m"
WHITE="\033[1;37m"
NC="\033[0m"
mkdir -p /Applications/MAMP/Library/vhosts;
mkdir -p /Applications/MAMP/Library/vhosts/domains;
if [ "$1" ] || [ "$2" ]; then
DOMAIN=$1;
DOCUMENTROOT=$2
# Add vhost
touch /Applications/MAMP/Library/vhosts/domains/$domain;
echo "<VirtualHost *>
DocumentRoot "$DOCUMENTROOT"
ServerName $DOMAIN
<Directory "$DOCUMENTROOT">
Options All
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>" >> /Applications/MAMP/Library/vhosts/domains/$DOMAIN;
echo "127.0.0.1 $DOMAIN" >> /etc/hosts;
# Restart MAMP
/Applications/MAMP/bin/apache2/bin/apachectl restart;
# echo out the domain name and copy domain to clipboard
echo -e "Finished. ${BLACKBG}${WHITE} $DOMAIN ${NC} has been copied to your clipboard.";
echo "$DOMAIN" | pbcopy;
fi
if [ "$1" = "remove" ] || [ "$1" = "delete" ]; then
echo -e "${RED}Here are the current custom local domains:${NC}"
for file in /Applications/MAMP/Library/vhosts/domains/*
do
if [ -f "$file" ];then
echo -e "${YELLOW}${file##/*/}${NC}"
fi
done
echo -e "${RED}Enter the site name you wish to remove:${NC}"
read siteName;
sed -i.bak "/$siteName/d" /etc/hosts;
rm /Applications/MAMP/Library/vhosts/domains/$siteName;
echo -e "${YELLOW}$siteName removed."
fi
@micahbrich
Copy link
Author

MAMP Virtual Host Creation Script

  1. Download the script & cd to it
  2. chmod +x ./vhost
  3. mv ./vhost /usr/local/bin
  4. subl /Applications/MAMP/conf/apache/httpd.conf and add the following line at the end of the file:
Include vhosts/*

Then, to use:

$ vhost wildebeest.dev ~/sites/wildebeest/wildebeest

That should be it. Open wildebeest.dev in your browser and confirm it's working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment