I’m always looking for more ways to streamline my development process, and recently I’ve found myself getting mildly annoyed with having to launch the MAMP GUI anytime I wanted to begin building – so why not stop & start the servers via Terminal?
Turns out, this can easily be done by creating an alias in
.bash_profile , so I thought I’d share with the world how to do it!
Launch Terminal from the /Applications/**Utilities** folder.
*We then need to navigate to our home directory. Type the following into Terminal and press enter:
Open your .bash_profile
If you don’t already have a .bash_profile, this command will create one – if .bash_profile does exist, then it will simply open the existing file in Terminals text editor – Nano.
You can now start editing your file, so drop this in there:
alias startm='cd /Applications/MAMP/bin && ./start.sh' alias stopm='cd /Applications/MAMP/bin && ./stop.sh'
*Save your changes by pressing *ctrl+o and hitting enter, then exit Nano by pressing ctrl+x.
*Finally, we need to ‘activate’ our changes, enter:
…and that’s it! Now, whenever you enter
startm into the Terminal, MAMP will turn its servers on, while
stopm will turn them off.
What’s happening here?
The alias issues two commands:
cd /Applications/MAMP/bin tells Terminal to change directory into the MAMP app’s ‘bin’ folder, which contain shell scripts that MAMP uses to initialise its services. The two scripts we want to run are start.sh & stop.sh.
We’ll then tell Terminal to run start.sh by adding
&& ./start.sh. – the double ampersands are to ensure thatÂ the next command will execute only if the previous command was successful.
*Going the extra mile
*I decided to take this one step further by including an alias that will open the MAMP app in a minimised state, as well as adding Terminal Notifier into the mix, which will display a native system notification when each command has been successfully executed.
alias openmamp='open -j /Applications/MAMP/MAMP.app/ && terminal-notifier -title "Terminal" -message "MAMP Opened"' alias startm='cd /Applications/MAMP/bin && ./start.sh && terminal-notifier -title "Terminal" -message "MAMP Servers Started"' alias stopm='cd /Applications/MAMP/bin && ./stop.sh && terminal-notifier -title "Terminal" -message "MAMP Servers Stopped"'
I hope you guys found this useful!