How to find out PHP, APACHE and MySQL install directories from a php script?


I need to find out PHP, APACHE and MySQL install directories from a php script.
It is possible?

Who is Participating?
This program must search for given filename as parametr and return list of all found files. For example, you wrote search.exe an when you type
C:\search.exe php.exe

it must return for example:

So when you call it through passthru(), you can parse results like this:
$a = explode("\n", passthru("search.exe php.exe"));
There's no built-in functions to do it.
You can use exec() or passthru() to call your external program which can do it.
But you have to write a program that can do it before...
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

galiganuAuthor Commented:
Just to be more clear: I need to find the paths to php, apachectl and mysqld executables.
Also to MySQL databases location.

Thanks again,
galiganuAuthor Commented:
thanks ixti

what this program should do? search the entire hard drive for this executables?
There is an easier solution if you have have the proper permission;

$_ENV["_"]  - this variables hold the path and apache executable
$_ENV["PATH"] - this holds the path vairables of your OS (linix, windows) and most likely (99%) mysql excecutable will reside in one of the given paths

Finding the php exececutable is little more troublesome
1. First you can check in the $_ENV["PATH"]
2. Next you can check in a directory above php extension_dir var
3. Or check directory above include_path var
4. Or parse the apache.conf for php path
for example, I don't have any of paths related with Apache, MySQL and PHP in my PATH enviroment... But this is one the easier solution anyway (if this enviroment is set).
Well the $_SERVER var should be accessible it also contain path related info

imo ixti's solution is time exausting
I totally agree that my solution is VERY exhausting. But:

1. Superglobal arrays may not have necessary data for Conceited solution.

2. There's no way to do this in simple and beautiful way. There's no built-in functions. So even if everythin what you need will be present in enviroment or server variables, even in this case you'll got to open, then parse config files...

3. You can do <?php $a = array(); exec('dir c:\php.exe /S', $a); ?> and then extract data you need. Or simply make a lightweight program that do the same as "dir C:\php.exe /S" but returns only paths, so you can grab them to array and do what you want.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.