0

I want to know the path of the php interpreter from within a php script.

Such the result will be /usr/bin/php for example

I want this to work both for windows and unix.

How can I do it?

edit: I need this information in runtime, so parsing the result of phpinfo() is less than ideal solution

3
  • 3
    Possible duplicate: stackoverflow.com/questions/4943501/… Commented Aug 10, 2011 at 21:56
  • What do you need this for anyway? Commented Aug 10, 2011 at 22:47
  • Yes, it is indeed a duplicate of that question. Commented Aug 10, 2011 at 23:09

3 Answers 3

1

From a command line PHP script, try $_SERVER['_']. The location of PHP in a web-based script doesn't really have much meaning, since PHP is embedded into the webserver for the most part, and won't have any executable path.

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

2 Comments

I heard this, but not quite understand. Does it mean that php is compiled into servers executable? Otherwise, the server should be running other process which is php
No. PHP is rarely (if ever) compiled into the webserver. Usually it's loaded as a library, which allows you to upgrade either without having to recompile both.
1

To get all the detailed information about your PHP installation, place a call to phpinfo() in a blank file and it will display what you need.

http://php.net/manual/en/function.phpinfo.php

<?php
    phpinfo();
?>

Just remember to delete the file when you push it to production.

Comments

0

For Linux, you could use $result = exec("which php");

For Windows, I saw this kind of link (I don’t know Windows enough I can verify it to work)

1 Comment

I find it funny that you say that about Windows. Usually Windows is the OS that most people know the most, even the techies. Though it is just not as powerful and flexible as Linux/Unix.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.