[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2006-04-18
11
Medium Priority
?
233 Views
Last Modified: 2006-11-18
Hi,

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

Thanks,
gali
0
Comment
Question by:galiganu
  • 5
  • 2
  • 2
9 Comments
 
LVL 6

Expert Comment

by:ixti
ID: 16485172
There's no built-in functions to do it.
You can use exec() or passthru() to call your external program which can do it.
0
 
LVL 6

Expert Comment

by:ixti
ID: 16485177
But you have to write a program that can do it before...
0
 

Author Comment

by:galiganu
ID: 16485183
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
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:galiganu
ID: 16485199
thanks ixti

what this program should do? search the entire hard drive for this executables?
0
 
LVL 6

Accepted Solution

by:
ixti earned 100 total points
ID: 16485944
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);
?>
0
 
LVL 1

Assisted Solution

by:Conceited
Conceited earned 100 total points
ID: 16486093
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
0
 
LVL 6

Expert Comment

by:ixti
ID: 16486458
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).
0
 
LVL 1

Expert Comment

by:Conceited
ID: 16487610
Well the $_SERVER var should be accessible it also contain path related info

imo ixti's solution is time exausting
0
 
LVL 6

Expert Comment

by:ixti
ID: 16495307
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.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses
Course of the Month19 days, 11 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question