Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Execting php-scripts from the command line now does not work. When executing a script starting with #!/usr/bin/env php. I get this error message:

env: php: No such file or directory.

So it seems I can not run php as an executable script with /usr/bin/php.

I think what's causing my problem is that I followed these instructions for allowing MAMP’s copy of PHP to run from the terminal.

sudo mv /usr/bin/php /usr/bin/php-old

appears not to be working. php is not renamed.

If I should add something to my path. What should I add? When running echo $PATH:


Btw (don't know if it is related): MySQL is running but I can't access http://localhost/ when running:

sudo apachectl start
share|improve this question
What happens when you enter which php? Does it find your PHP installation? Does it work for every user account, or only for yours? – Daniel Beck Jul 7 '11 at 9:01
I did sudo mv /usr/bin/php-old /usr/bin/php. No I get /usr/bin/php. – r4. Jul 7 '11 at 9:06
up vote 2 down vote accepted

That's why you should never mess around with /usr/bin, but keep local installations of binaries.

If you did the following

sudo mv /usr/bin/php /usr/bin/php-old

you will be able to revert by just doing

sudo mv /usr/bin/php-old /usr/bin/php

then /usr/bin/env php should work.

If you decide to continue with the MAMP installation, you can of course move your default php to php-old. But then you also need to execute the following after moving php to php-old:

sudo ln -s /Applications/MAMP/bin/php5/bin/php /usr/bin/php

in order to have the php shipped with MAMP available under /usr/bin/phpagain.

But I can't promise that will work as expected at all. Again, you shouldn't move stuff in /usr/bin.

share|improve this answer

You can just use the path of your PHP installation directly in the script.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .