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

I use the exec command as shown 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 installation path for PHP, so I can replace /usr/bin/php with /Applications/MAMP/bin/php/php5.4.10/bin/php . But I do not know where the PHP installation (PHP binary) is located on the production server.

+4
source share
2 answers

Usually /usr/bin/php , but you can try to capture and whereis php output of the command " whereis php " or " which php' ".

Or better yet, use the PHP_BINARY constant, if available. Take a look here .

+9
source

In most cases, the job execution should be performed by a PHP_BINARY predefined constant .

If you need something more advanced, you can use the Symfony component of the process using the PhpExecutableFinder class:

 // composer require symfony/process use Symfony\Component\Process\PhpExecutableFinder; (new PhpExecutableFinder)->find(); 
+2
source

Source: https://habr.com/ru/post/1500912/


All Articles