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

Hi,

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

Thanks,
gali
galiganuAsked:
Who is Participating?

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

x
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.

ixtiCommented:
There's no built-in functions to do it.
You can use exec() or passthru() to call your external program which can do it.
ixtiCommented:
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,
gali
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?
ixtiCommented:
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:
C:\php\php.exe
E:\usr\local\php.exe

So when you call it through passthru(), you can parse results like this:
<?php
$a = explode("\n", passthru("search.exe php.exe"));
var_dump($a);
?>

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
ConceitedCommented:
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
ixtiCommented:
Conceited,
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).
ConceitedCommented:
Well the $_SERVER var should be accessible it also contain path related info

imo ixti's solution is time exausting
ixtiCommented:
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
PHP

From novice to tech pro — start learning today.