Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am using the exec command as below in PHP :

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

In my 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 don't know where the PHP installation (PHP binary) is located on the production server.

like image 730
Ponting Avatar asked Sep 06 '13 11:09

Ponting


People also ask

Where is the PHP binary located?

Usually the binary is located here: /usr/bin/php5.

Where is PHP directory Linux?

The default location for the php. ini file is: Ubuntu 16.04: /etc/php/7.0/apache2.


2 Answers

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

Or better yet, use the constant PHP_BINARY if it is available. Have a look here.

like image 155
alexg Avatar answered Oct 06 '22 02:10

alexg


Most of the time, the PHP_BINARY predefined constant should do the job.

If you need something more developed, you can make use of Symfony's Process component, by using its PhpExecutableFinder class:

// composer require symfony/process

use Symfony\Component\Process\PhpExecutableFinder;

(new PhpExecutableFinder)->find();
like image 20
Gras Double Avatar answered Oct 06 '22 02:10

Gras Double