Skip to content

Instantly share code, notes, and snippets.

@jonathanstark
Last active December 11, 2018 17:19
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jonathanstark/8580207 to your computer and use it in GitHub Desktop.
Serve the current directory with MAMP from the command line
function mamp() {
#
# Default location of the apache conf file for MAMP
CONF_FILE="/Applications/MAMP/conf/apache/httpd.conf"
#
# Fish existing doc root out of conf file
LINE=$(cat $CONF_FILE | grep ^DocumentRoot)
QUOTED_STRING=${LINE/DocumentRoot /}
OLD_DOC_ROOT=${QUOTED_STRING//\"/}
#
# Set new doc root to current directory
NEW_DOC_ROOT=$(pwd)
#
# Replace doc root strings in conf file
sed -i.bak -e "s|${OLD_DOC_ROOT}|${NEW_DOC_ROOT}|g" $CONF_FILE
#
# Restart server
sudo /Applications/MAMP/Library/bin/apachectl -k restart && sleep 2 && open "http://localhost:8888/"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment