How start & stop MAMP PRO using command line?

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.


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


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.


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.