Unleash MAMP’s Power! Start MAMP from Terminal & Access MySQL/PHP Anywhere (Easy Guide)

Muhammad Sameer
3 min readApr 2, 2024

--

If you’re reading this post, no doubt you love the convenience of MAMP for your local development, but do you want to streamline your workflow? This guide will walk you through some tips and tricks that helped me and now gonna help you as well. These hacks will save you time and give you more control over your development environment. Before we get started, here’s a brief list of benefits:

  • Faster Startup: Bypass the MAMP application and launch directly.
  • Scripting Integration: Automate server starts, stops, and restarts for development workflow.
  • Easy Access: Use MySQL, mysqldump and PHP commands from any directory in your terminal (Cool, Isn’t it?).
  • Improved Workflow: No more switching between the MAMP interface and Terminal.

Prerequisites

  • MAMP installed on your system.
  • Basic familiarity with the Terminal application (pre-installed on Mac).

Starting, Stopping and Restarting MAMP from Terminal (Step-by-Step Guide)

  1. Open Terminal: Navigate to “Applications” > “Utilities” and launch “Terminal”.
  2. Open .zshrc file: Open the ~/.zshrc file in the code editor. If you’re a VS Code fan and have VS Code installed in your PATH then simply, type code ~/.zshrc or open it vianano ~/.zshrc
  3. Create aliases for the start, stop, and restart commands:
alias startm='/Applications/MAMP/bin/start.sh'
alias stopm='/Applications/MAMP/bin/stop.sh'
alias restartm='/Applications/MAMP/bin/stop.sh && /Applications/MAMP/bin/start.sh'

4. Save and Close file: If you’ve used nano then press Ctrl+O to save and Ctrl+X to exit. Finally, source the changes (optional)

source ~/.zshrc

What have we done so far? we created alias commands that run scripts from MAMP’s bin directory. In the restart command, we are just concatenating the two scripts 😅. Lastly, we are sourcing .zshrc file to access these aliases in our current terminal instance.

Going the extra mile

I wrote a bash function that is more manageable and throws notifications. You can replace the code in step #3 with the following Github Gist code

Adding MAMP’s MySQL and PHP to PATH (Optional but Recommended)

Note: This step modifies system settings. Proceed with caution if you’re unfamiliar with the terminal.

  1. Open the .zshrc file: You can follow the above steps to open the file in your favorite code editor.
  2. Update the Path: PATH is a special variable, whenever we type something in our terminal it looks that command the PATH variable and then runs it. So, let's update it by adding this code at the end of the file:
# Custom php path from MAMP
export PATH=/Applications/MAMP/bin/php/<your php version>/bin/:$PATH
# Custom MySQL path from MAMP
export PATH=/Applications/MAMP/Library/bin/:$PATH

Replace the<your php version>with your current MAMPs PHP version, the final output should look something like export PATH=/Applications/MAMP/bin/php/php7.4.33/bin/:$PATH save and close the file and that's it.

Testing Your Changes:

  1. Open a new Terminal window. This ensures the changes to your PATH are loaded.
  2. Start MAMP: Type mamp start and press Enter. If you get the notification that says MAMP started congratulations you did it.
  3. Verify MySQL access: Type mysql -v and press Enter. If MySQL is accessible, you'll see the version information.
  4. Verify PHP access: Type php -v and press Enter. This should display the installed PHP version.

Conclusion

By mastering these techniques, you’ve unlocked the full potential of MAMP from the command line! Now you can streamline your development workflow and leverage the power of the terminal for a more efficient development experience.

--

--