How to start and stop MAMP server from Terminal

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!

Step 1:
Launch Terminal from the **/Applications/**Utilities folder.

**Step 2:
**We then need to navigate to our home directory. Type the following into Terminal and press enter:

Step 3:

Open your .bash_profile

nano .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.

Step 3:
You can now start editing your file, so drop this in there:

alias startm='cd /Applications/MAMP/bin && ./'
alias stopm='cd /Applications/MAMP/bin && ./'

**Step 4:
**Save your changes by pressing ctrl+o and hitting enter, then exit Nano by pressing ctrl+x.

**Step 5:
**Finally, we need to ‘activate’ our changes, enter:

source ~/.bash_profile

…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 &

We’ll then tell Terminal to run by adding && ./  – 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.

See below:

alias openmamp='open -j /Applications/MAMP/ && terminal-notifier -title "Terminal" -message "MAMP Opened"'
alias startm='cd /Applications/MAMP/bin && ./ && terminal-notifier -title "Terminal" -message "MAMP Servers Started"'
alias stopm='cd /Applications/MAMP/bin && ./ && terminal-notifier -title "Terminal" -message "MAMP Servers Stopped"'

I hope you guys found this useful!