47

I have MAMP installed. Now I am trying to run a script from the command line, but I can't seem to get it to work.

How should I set up my environment so that I can run a script from the command line and use the PHP version I installed with MAMP?

Update: I agree with jjeaton below, here is a nice solution of creating an alias to MAMP's PHP:

# add this to your ~/.bash_profile
alias phpmamp='/Applications/MAMP/bin/php/php5.3.6/bin/php'

Now you can use it from the command line:

$ phpmamp --help
2
  • 2
    This answer has a better solution that won't mess with your stock php install. Commented Feb 20, 2012 at 12:50
  • 1
    Don't forget the to enter : source ~/.bash_profile to reload your bash profile ! Commented Jan 23, 2017 at 5:57

5 Answers 5

40

Please note that with version 2.0.5 of MAMP, the path has changed. It is now one of the following:

/Applications/MAMP/bin/php/php5.2.17/bin/
/Applications/MAMP/bin/php/php5.3.6/bin/

Therefore the command to add MAMP's php command should probably look like this:

export PATH=/Applications/MAMP/bin/php/php5.2.17/bin/:$PATH

or like this (depending on which version of PHP you want to use):

export PATH=/Applications/MAMP/bin/php/php5.3.6/bin/:$PATH
Sign up to request clarification or add additional context in comments.

Comments

11

Another way that works that may be a little cleaner with regard to PHP versions is to create an alias in your bash profile that points to the specific php binary that you want to run when you run things like composer or other cli tools. This has the benefit of avoiding some potential library and php.ini config compatibility issues with the installed version of php in OSX.

For instance, if you want to point to php 5.4.1 in MAMP, edit your .bash_profile file in your editor of choice (nano, vi, etc.):

# nano ~/.bash_profile

Add this below your PATH statement:

alias php=/Applications/MAMP/bin/php/php5.4.10/bin/php

Save and quit (CTRL+X in nano, :wq in vi). Quit Terminal. The next time you try to call php from the cli, you'll be using the 5.4.10 version installed with MAMP.

Remember to update this path if you update MAMP with a more recent version of PHP.

3 Comments

Do you need to restart your machine for this to take effect?
for me this is the best option so I can create different aliases for different projects that need different php versions on the cli, ie php7.2, php7.1, etc...
Mr. Concolato you dont need to restart your server but instead you need to either open a new terminal or re-read the .bash_profile with source ~/.bash_profile. Note that for me my .bash_profile was not working because it had a source ~/.profile at the beginning and the file ~/.profile did not exist (I didnt put that there..) after commenting this line with # I was able to run source ~/.bash_profile without errors
10

Run this in your Terminal:

export PATH=/Applications/MAMP/bin/php5/bin/:$PATH

Should do the trick. It will - as Tom Haigh mentioned - add the MAMP PHP executable to the path so you can use "php" instead of the full path.

5 Comments

php -i | grep php.ini - this should give you the MAMP php ini location if it is working properly, rather than /etc
Andrew, you can use "which php" to get the path of the php executable that the php command will use.
In MAMP 1.9.4, this needs to be export export PATH=/Applications/MAMP/bin/php5.3/bin:$PATH - since /Applications/MAMP/bin/php5/bin/ no longer exists. This points to PHP 5.3, but there may be a way to point at whatever MAMP is set to use instead.
@Alex King, that depends on what version of PHP you are using.
Hi @phidah only your solution worked for me on Mountain Lion 10.8.5 with MAMP 2.2. But I cannot seem have it listed neither in ~/.profile nor in ~/.bash_profile. Just wondering Where has this been added. Even its working good.
2

Yes, I think it is here: /Applications/MAMP/bin/php5/bin/php

You can either add /Applications/MAMP/bin/php5/bin/ to the front of your path or create a symlink in /usr/bin (there probably is one there already for the default PHP installation)

2 Comments

so would the PHP CLI be built in to /Applications/MAMP/bin/php5/bin/php because I don't see anything about PHP CLI in /Applications/MAMP/bin/php5/bin
I thought that the php binary was in there on mine, but maybe not. It will just be called 'php'. I will have a look on my Mac later.
0

Just replace the PHP version in this command:

/Applications/MAMP/bin/php/php7.4.21/bin/php  index.php

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.