Ponting Ponting - 6 months ago 11
PHP Question

How to get path of the php binary on server where it is located

I am using exec command as below in PHP :

exec("/usr/bin/php /path/to/Notification.php >> /path/to/log_file.log 2>&1 &");


In local environment(MAMP),I know the php installation path so I can replace
/usr/bin/php
with
/Applications/MAMP/bin/php/php5.4.10/bin/php
. But I dont know where php installation(php binary) is located on production server?

Answer

It's usually /usr/bin/php but you could try to capture and parse the output of the command 'whereis php'.

Or better yet, use the constant PHP_BINARY. Have a look here.