18

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 Answers 3

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.

Sign up to request clarification or add additional context in comments.

6 Comments

I want to find it on server(Production),not on local machine.
Yes, so have your script run whereis php on the server, then parse the output with a regex to get the path.
Can you explain,What is regex ?
Thanks dude.Can you tell me by default where it is located on the server?Because I don't have authority to check this command on server.
@Ponting It's not a command, just use the constant PHP_BINARY in your PHP script.
|
10

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(); 

Comments

-1

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".

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.