Question

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
Was it helpful?

Solution

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

OTHER TIPS

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.

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.

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)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top