Last active
December 11, 2018 17:19
-
-
Save jonathanstark/8580207 to your computer and use it in GitHub Desktop.
Serve the current directory with MAMP from the command line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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