How to get path of the php binary on server where

2020-08-21 07:08发布

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.

3条回答
Melony?
2楼-- · 2020-08-21 07:36

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.

查看更多
3楼-- · 2020-08-21 07:38

Try these two steps: updatedb (only needs to be run once to update the locate index) locate php | grep -P "/php$"

The locate command should show you all files on the server with "php" in their filename or folder name. The "grep" pipe filters down the results down to just things that end in "/php".

查看更多
甜甜的少女心
4楼-- · 2020-08-21 07:56

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();
查看更多
登录 后发表回答