Where on my server is the PHP version that serves

2019-09-10 10:40发布

问题:

I'm on a shared server. When I save a script with phpinfo() and open it in the browser, the script tells me "PHP Version 5.6.18":

When I visit my server through SSH and look in /usr/local/bin, ls shows me PHP versions from 4 to 5.5, but no version 5.6:

When I search for PHP with which php, I get the following (with results from ... -v in parentheses):

/usr/bin/php (4.4.9)
/usr/bin/php4.4
/usr/bin/php5.2
/usr/bin/php5.4
/usr/bin/php5.5
/usr/bin/php5.4-cli
/usr/bin/php5.5-cli
/usr/bin/php4.4-cli
/usr/bin/php5.2-cli
/usr/lib/php (directory, contains extensions)
/usr/lib/php4.4
/usr/lib/php5.4
/usr/lib/php5.5
/usr/lib/php5.2
/usr/local/bin/php (4.4.9)
/usr/local/bin/php5.4
/usr/local/bin/php5.5
/usr/local/bin/php4.4
/usr/local/bin/php5.2
/usr/local/lib/php.ini-nourl
/usr/include/php4.4
/usr/include/php5.4
/usr/include/php5.5
/usr/include/php5.2
/usr/local/php (4.4.9)
/usr/share/php (directory, contains: libzend-framework-php  wp-cli)

So where is PHP 5.6?

I want to run a script through a cronjob using the same PHP or a similar version as the one serving web pages, e.g.

0 * * * *  /usr/local/bin/php5.6 -f/path/to/script.php

but I don't know where PHP 5.6 lives.

How can I find PHP 5.6 on my server?

I'm on a shared Linux server running Apache. I called my hosting provider but the weekend staff has no idea and asked me to call on Monday. Can you help me before then?

回答1:

PHP constant PHP_BINARY keeps info of current PHP interpreter:

<?php var_dump(PHP_BINARY); ?>

It'll return soomething like this: string(13) "/usr/bin/php5". Then:

$ /usr/bin/php5 -v

In your specific case probably php5 is the PHP v5.6.



回答2:

use /usr/local/bin/php, since the higher version of php in your server is 5.6 the default php file is the 5.6 version