Search code examples
phpmacosxamppmamp

Upgrading PHP CLI version on mac


I just now bought new Macbook Pro for development purpose. I did a small research and install MAMP on Mojave OS for my current project but happen to see my PHP CLI version is 7.1.23 and was unable to upgrade, coming from Windows background I have a lot of experience in XAMPP. I found the MAC OS installer and did my in installation with latest version of PHP available. As I wanted latest PHP for my project.

Now when I see phpinfo(); through my XAMPP localhot I can see PHP version 7.3 but when I go to terminal I see the same old version. I tried updating the PHP using this link but no luck in updating PHP CLI version.

PHP Xampp Version

And in CLI

CLI Version

Help me out with this. Thanks.


Solution

  • Run this command:

    alias php='/Applications/MAMP/bin/php/php7.2.7/bin/php'
    

    and replace 7.2.7 with your version number.

    This will only work until you restart the terminal, in order to keep this change when re-opening the terminal you need to do the following:

    • Open ~/.bash_profile with a text editor of your choice (eg. nano)

      nano ~/.bash_profile

    • Go down to the bottom and add the line from earlier.

      Add alias php='/Applications/MAMP/bin/php/php7.2.7/bin/php' to the bottom of the file. Of course you can replace 7.2.7 with the version of your choice.

    Similarly we can do it for XAMPP, like this:

    export XAMPP_HOME=/Applications/XAMPP 
    export PATH=${XAMPP_HOME}/bin:${PATH} 
    export PATH