25

I am trying to find a way by which I can start and stop MAMP PRO's Apache and mysql using command line. So far whatever I have search has only helped me start MAMP PRO.

Thanks.

11 Answers 11

50

As of at least MAMP 3.0.6, the following works for both Free and Pro versions:

Open MAMP Pro or Free, depending on the one you use:

Pro: open /Applications/MAMP\ PRO/MAMP\ PRO.app/

Free: open /Applications/MAMP/MAMP.app/

Then, cd into MAMP/bin:

cd /Applications/MAMP/bin

To start Apache & MySQL:

./start.sh

To stop Apache & MySQL:

./stop.sh

Note that you might need to sudo the commands above.

2
  • 2
    This works for MAMP, but I'm looking for something for MAMP PRO Sep 17, 2013 at 19:05
  • 1
    If you're running a linux environment you can add this to your .bash_profile for quick on and off: alias startmamp='open /Applications/MAMP/MAMP.app;bash /Applications/MAMP/bin/start.sh' alias stopmamp='bash /Applications/MAMP/bin/stop.sh' Nov 28, 2016 at 10:11
18

After much trial and error:

Note that I have my ports set to the application's respective defaults (Apache: 80, MySQL: 3306), and as such these commands reflect that, AND you must use sudo with Apache (which you will in MAMP as well if you're using port 80).

Apache

sudo /Applications/MAMP/Library/bin/httpd -f "/Library/Application Support/appsolute/MAMP PRO/conf/httpd.conf" -k start

sudo /Applications/MAMP/Library/bin/httpd -f "/Library/Application Support/appsolute/MAMP PRO/conf/httpd.conf" -k stop

sudo /Applications/MAMP/Library/bin/httpd -f "/Library/Application Support/appsolute/MAMP PRO/conf/httpd.conf" -k restart

MySQL

To start MySQL:

sh -c '/Applications/MAMP/Library/bin/mysqld_safe --defaults-file=/Applications/MAMP/tmp/mysql/my.cnf --port=3306 --socket=/Applications/MAMP/tmp/mysql/mysql.sock --user=alex --pid-file=/Applications/MAMP/tmp/mysql/mysql.pid --log-error=/Applications/MAMP/logs/mysql_error_log.err --tmpdir=/Applications/MAMP/tmp/mysql/tmpdir --datadir=/Library/Application\ Support/appsolute/MAMP\ PRO/db/mysql &'

(for some reason you must hit enter again to regain your prompt)

To stop MySQL:

sh -c '/Applications/MAMP/Library/bin/mysqladmin -u root -proot --socket=/Applications/MAMP/tmp/mysql/mysql.sock shutdown'

As a bonus, the indicators in the MAMP PRO.app GUI show the correct status of these apps in real time, so you can continue to rely on that.

I have MAMP PRO v2.0.3.

4
  • This works mostly; but then phpMyAdmin cannot write sessions...Is there another way? Aug 28, 2015 at 18:33
  • Are you using sudo as mentioned in the answer?
    – Astockwell
    Aug 28, 2015 at 20:14
  • Is there a way to specify the ports here? You said you use 80 and "[the] commands reflect that", but I see nowhere where you specify the ports. And also, the reason you must type enter is because you used a "&" at the end, I know the comment is almost 3 years old but whatever. Apr 3, 2016 at 23:29
  • Thanks! I added this to my ~/.bash_profile: mpache() { sudo /Applications/MAMP/Library/bin/httpd -f "/Library/Application Support/appsolute/MAMP PRO/conf/httpd.conf" -k $1 } I can now simply do: mpache [start/stop/restart]
    – Jammer
    Jul 19, 2016 at 12:48
12

http://pastebin.com/avn0BFap

Save the script and give executable rights such as: chmod +x start.sh

Then use it like ./start.sh Start or ./start.sh Stop or ./start.sh Restart

0
6

Best Solution for MAMP 3 on OSX

(should work for MAMP Pro as well).

Look inside of the folder:

/Applications/MAMP/Library/bin

You'll see the scripts used for starting and stoping Apache & MySQL.

Look inside any of the scripts:

start.sh or stop.sh or startApache.sh etc

You will see that they use the program:

apachectl

You can use the restart command with apachectl. So, just set-up an alias in your ~/.bash_rc file:

alias rap='sudo /Applications/MAMP/Library/bin/apachectl restart'

rap is the acronym I gave for 'Restart Apache'. Presto! One step from the command line without having to open the MAMP application. Use the same logic if you want to set this up for MySQL.

1
  • On my version these files are here: /Applications/MAMP/bin
    – Jammer
    Jul 19, 2016 at 12:29
3

To start it on MAMP pro version 4 it's

/Applications/MAMP\ PRO/MAMP\ PRO.app/Contents/MacOS/MAMP\ PRO cmd startServers

To stop it it's

/Applications/MAMP\ PRO/MAMP\ PRO.app/Contents/MacOS/MAMP\ PRO cmd stopServers

Sadly

Based on the advice given here

"https://deliciousbrains.com/automating-local-wordpress-site-setup-scripts-part-3-automating-rest"

And found then discovered - it's HIDDEN in the documentation right here.

https://documentation.mamp.info/en/MAMP-PRO-Mac/How-Tos/General/CreateHostDatabaseCommandLine

3

Nearly the same with MAMP Pro 5:

/Applications/MAMP\ PRO.app/Contents/MacOS/MAMP\ PRO cmd stopServers

start:

/Applications/MAMP\ PRO.app/Contents/MacOS/MAMP\ PRO cmd startServers
0

If you are using MAMP PRO there is an easier way to stop MySQL.

MAMP PRO creates a shell script in your Library folder. If you've changed the password for the root user (which you should), the updated password will also be reflected in the script. The file can be found at:

~/Library/Application Support/appsolute/MAMP PRO/stopMysql.sh

In order to type that on the command line you need to escape the spaces by adding a backslash in front of them like the command below.

Stop MySQL Shell Script for MAMP PRO

~/Library/Application\ Support/appsolute/MAMP\ PRO/stopMysql.sh

The other thing that I found on my system was that the file didn't have the execute bit set on it. I cheated and used Path Finder to set the file as executable but you can easily find information about how to do it through the command line with chmod.

Unfortunately I can't find a proper start script created by MAMP PRO. I wanted to find something simple to use for the start command in MySQLWorkbench but for now I just left it blank because the default MAMP script does not work. I may create a script based on the helpful commands Astockwell posted in response to this question.

0

I found /Applications/MAMP PRO/MAMP PRO.app/Contents/Resources/MAMP.startup, which works for me in MAMP PRO, with custom ports.

Just run

/Applications/MAMP PRO/MAMP PRO.app/Contents/Resources/MAMP.startup start

or

/Applications/MAMP PRO/MAMP PRO.app/Contents/Resources/MAMP.startup stop

etc.

0

Simple way would be to shut down and restart the application, MAMP PRO will start and stop Apache and MySQL.

start MAMP PRO

open -a MAMP\ PRO

stop MAMP PRO

osascript -e 'quit app "MAMP PRO"'
0

For MAMP Pro 5 use

sudo /Applications/MAMP/Library/bin/apachectl -f"/Library/Application Support/appsolute/MAMP PRO/conf/httpd.conf" -k restart

remember, you must use sudo

0

For MAMP5.5, search for this script file in your MAMP bin folder: startMysql.sh

It would have few lines:

#!/bin/sh

/Applications/MAMP/Library/bin/mysqld_safe --port=8889 --socket=/Applications/MAMP/tmp/mysql/mysql.sock --pid-file=/Applications/MAMP/tmp/mysql/mysql.pid --log-error=/Applications/MAMP/logs/mysql_error_log &

Copy Paste the entire command on your OSX shell and just press enter, your Mysql server would start.

Open a new shell and start using Mysql from command line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.