a local development site on my OS X Mavericks uses an exec("which php")-command. The result of this exec()-Command is "/usr/bin/php", which is actually wrong, it should return "opt/local/php5/bin/php". "opt/local/php5/bin/php" is the result of the command "which php" in my Terminal-Session. How can i fix this?
-
possible duplicate of [Get current PHP executable from within script?](http://stackoverflow.com/questions/2372624/get-current-php-executable-from-within-script) – andy Oct 15 '14 at 09:03
-
Which "php" is used by your apache ? – Anas Oct 15 '14 at 09:04
1 Answers
If you ask the wrong question, you get the wrong result. ;)
The which
command returns you the full path to an executable file. Those locations where which
looks for the command, are defined in the $PATH
environment variable, and it looks something like this:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/opt/android-sdk/sdk/platform-tools:/opt/android-sdk/sdk/tools
These are common command paths, separated by colons.
Apparently you have multiple installations of PHP on your machine. What you get, is the path to the primary one, probably installed by your packet manager.
The one in /opt
will only be found if you add /opt/local/php5/bin
to the envinonment of your webserver user, and it has to be before /usr/bin
.
Now, how do you set the $PATH
of your webserver? Depending on your server (Apache, Nginx, …) and your distro, there are different possibilities. For Apache on a Debian-like system, it's usually /etc/apache2/envvars
.
If there's no PATH
defined yet, simply add the following line:
export PATH="/opt/local/php5/bin:$PATH"
(Note that the PATH
at the beginning doesn't have a $
sign.)
Then restart your webserver.

- 12,375
- 12
- 51
- 73