Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

How to determine which PHP is being used?

For example, if there are /usr/local/bin/php and usr/local/bin/php5, how do I know which one is being used by my PHP scripts?

share|improve this question

8 Answers 8

up vote 5 down vote accepted

If you are using the PHP CLI, then try using theese shell commands (i'm assuming that you are using linux here)

which php - will locate the php executable (this should be the default php used by you)
whereis php - The first path displayed will be the location of the php executable
echo $PATH - will print a list of paths separated by ":" where the system looks for commands

If you are using PHP as an Apache module then phpinfo() will tell you the php version used, and the php config files, NOT the php path. If you have 2 versions of the php executable then this will help you. If they are the same version then it wont really matter which one is who:)

If you want to find out the php version, then php -v will print the php version in the CLI and any Zend modules installed.

If you want to find out the ini files included then php --ini will display th list of ini files loaded by the php module (this applies for the CLI version).

share|improve this answer
    
Thanks for all the inputs. Apparently, the which command is what I needed. –  Randell Aug 26 '09 at 3:07

Just add a simple script

<?php phpinfo(); ?>
share|improve this answer

Assuming You are Using through Web Server:
You can put the following function in a script:

<?php 
phpinfo(); 
?>

If this doesn't work, it could be because this function is disabled in the php.ini . This is often done for security. If this is the case, you will have a line in your php.ini like:

disable_functions = phpinfo

If this is the case, temporarily change it to

disable_functions =

If you are Using php for Shell Scripts:

  1. There should be the 'shebang line' at the top, something like

    #!/usr/local/bin/php -q

  2. Are you sure one isn't a smybolic link to the other? do

    ls -l /usr/local/bin/php

  3. Don't ;-)

share|improve this answer

Also from the commandline:

$ php -v

PHP 5.2.6-3ubuntu4 with Suhosin-Patch 0.9.6.2 (cli) (built: Mar 31 2009 02:11:31) Copyright (c) 1997-2008 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies

share|improve this answer
<?php
// prints e.g. 'Current PHP version: 4.1.1'
echo 'Current PHP version: ' . phpversion();
?>
share|improve this answer

If you are talking about your web-scripts that are called by your Apache webserver and PHP is configured as an Apache module then the answer is NONE.

The locations you mentionend in your question are command line script interpreters that would be called by shebang notation like

 #!/usr/local/bin/php

at the top of your php-command line script

you can call the interpreters you mentioned separately, since they have different names

# php

would call /usr/local/bin/php and

# php5

would call /usr/local/bin/php5

Neither one of those is used if you use PHP via the Apache module. If you use the CGI-Version of php it should show up in the phpinfo(); output.

share|improve this answer
<?php phpinfo(); ?>
share|improve this answer
<?php echo shell_exec('which php'); ?>

This works even if you don't have shell access. ;-)

share|improve this answer
    
I don't think this does what the person asking was looking for. This only tells you what the shell environment would end up using in a PATH lookup. That isn't necessarily the same PHP as the one which a script is executed with. –  Theuni Dec 8 '12 at 22:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.