How to Set the Correct MAMP PHP Version in the Terminal

Learn how to properly configure your terminal to use the correct MAMP PHP version. Avoid compatibility issues and streamline your development workflow with this step-by-step guide.

MAMP is a popular local development environment for macOS that includes Apache, MySQL, and PHP. However, one of the biggest pain points developers face is that macOS defaults to its system-installed PHP when running commands in the terminal. This becomes problematic when trying to use Composer, install dependencies, or run PHP scripts that require a specific MAMP PHP version. Without the proper setup, you might encounter compatibility errors, unexpected behaviors, or even broken projects due to version mismatches.

To avoid these issues, it is crucial to configure your terminal to use the correct MAMP PHP version as the default. By doing so, you ensure that your projects run on the expected PHP version and prevent conflicts with macOS’s built-in PHP. In this guide, we’ll walk you through the necessary steps to properly set MAMP’s PHP version in your terminal, whether for a temporary session or as a permanent configuration.

References:


Table of Contents


Finding the Installed MAMP PHP Versions

MAMP installs multiple PHP versions, typically stored in:

/Applications/MAMP/bin/php/

To list available PHP versions, run:

ls /Applications/MAMP/bin/php/

Choose the version you need (e.g., php8.1.12).

Temporarily Set the MAMP PHP Version in Your Terminal

To use a specific MAMP PHP version for the current terminal session, run:

export PATH="/Applications/MAMP/bin/php/php8.1.12/bin:$PATH"

Replace php8.1.12 with your desired version.

Verify it worked by checking the PHP version:

php -v

Permanently Set the MAMP PHP Version as Default

To make this change permanent, add the export command to your shell configuration file.

For zsh (default shell in macOS Catalina and later):

echo 'export PATH="/Applications/MAMP/bin/php/php8.1.12/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

For bash (macOS Mojave and earlier):

echo 'export PATH="/Applications/MAMP/bin/php/php8.1.12/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile

This ensures your terminal always uses the correct MAMP PHP version.

Confirming the Active PHP Version

Check which PHP version is currently being used:

which php

If the output is /Applications/MAMP/bin/php/php8.1.12/bin/php, your terminal is correctly configured.

Resolving Conflicts with Other PHP Installations

If another PHP version (e.g., from Homebrew or pyenv) overrides MAMP, check your PATH:

echo $PATH

If necessary, move MAMP’s PHP to the front:

export PATH="/Applications/MAMP/bin/php/php8.1.12/bin:$(echo $PATH)"

This ensures MAMP’s PHP version takes precedence over other installations.

Conclusion

Configuring your terminal to use the correct MAMP PHP version is essential for a smooth development workflow, especially when working with Composer and PHP scripts. Without the proper setup, you may encounter frustrating errors, version mismatches, and unexpected behavior that can slow down your development process. Ensuring that your terminal runs the correct PHP version eliminates these headaches and streamlines your workflow.

By following these steps, you can take full control of your development environment, ensuring compatibility and avoiding potential pitfalls. Whether you are setting up a temporary session or making the change permanent, configuring the correct MAMP PHP version properly will provide stability and consistency in your projects. Happy coding!

Leave a Reply

Your email address will not be published. Required fields are marked *

Comments (

)

  1. Gia Hackett

    My brother recommended I might like this web site He was totally right This post actually made my day You cannt imagine just how much time I had spent for this information Thanks

    1. Sam Galope

      That’s awesome! Huge thanks to your brother for the recommendation, and I’m really glad the post made your day. Knowing it helped makes all the effort worthwhile!

      If you’re up for more hands-on projects, you might enjoy this guide:
      How to Monitor Soil Moisture Levels with an ESP32 and Soil Moisture Sensor using MicroPython

      Thanks for reading, and I appreciate your support! 🚀

  2. Hilbert Weber

    Your blog is a testament to your dedication to your craft. Your commitment to excellence is evident in every aspect of your writing. Thank you for being such a positive influence in the online community.

    1. Sam Galope

      Wow, I truly appreciate your kind words! It means a lot to know that the effort I put into these articles is making a positive impact. Open-source and tech education are my passions, and it’s always rewarding to connect with like-minded people.

      If you’re interested in more hands-on projects, you might enjoy this guide:
      How to Monitor Soil Moisture Levels with an ESP32 and Soil Moisture Sensor using MicroPython

      Thanks again for your support—it keeps me motivated to keep sharing! 🚀

  3. Donald Lowe

    Your writing is a true testament to your expertise and dedication to your craft. I’m continually impressed by the depth of your knowledge and the clarity of your explanations. Keep up the phenomenal work!

    1. Sam Galope

      Wow, that means a lot—thank you! I truly appreciate your kind words and am glad you find the content valuable. Writing about open-source and tech is a passion of mine, and it’s great to know it resonates with readers like you.

      If you’re interested in more hands-on projects, you might enjoy this guide:
      How to Monitor Soil Moisture Levels with an ESP32 and Soil Moisture Sensor using MicroPython

      Thanks again for your support—it keeps me motivated to keep sharing! 🚀

  4. Kelvin Torphy

    Hi Neat post There is a problem along with your website in internet explorer would test this IE still is the market chief and a good section of other folks will pass over your magnificent writing due to this problem

    1. Sam Galope

      Thanks for the heads-up! I appreciate you taking the time to point that out. I’ll look into the issue and see if there’s a fix for Internet Explorer compatibility. That said, IE is a bit of a relic now—if possible, I’d recommend using a modern browser like Firefox, Chrome, or Edge for a better experience.

      In the meantime, if you’re interested in more projects, check out this guide:
      How to Monitor Soil Moisture Levels with an ESP32 and Soil Moisture Sensor using MicroPython

      Thanks again for the feedback! 🚀

  5. Marlin

    This post has helped me solve my issue, thanks a ton!

    1. Sam Galope

      That’s awesome to hear! I’m glad the post helped you out. If you’re looking for more cool projects, check this out:

      How to Monitor Soil Moisture Levels with an ESP32 and Soil Moisture Sensor using MicroPython.

      Happy coding! 🚀