Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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