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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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...
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,
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

galiganuAuthor Commented:
thanks ixti

what this program should do? search the entire hard drive for this executables?
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"));

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.