Take the 2-minute tour ×

How can I find out the path of the httpd.conf file on apache (PHP)? I do not know whether my script will be runned in windows apache or linux, i need to know where i can find this file in order to find a parameter from there. thanks!

share|improve this question
have a look into the php.ini file –  Mian Khurram Ijaz Nov 12 '12 at 9:34
add comment

7 Answers

I think its not exposed to PHP. Run httpd -V in terminal and you will find it there (command name depends on your system/apache version, it can be also apache -V):

bash-3.2# httpd -V
Server version: Apache/2.2.22 (Unix)
Server built:   Aug 24 2012 17:16:58
Server's Module Magic Number: 20051115:30
Server loaded:  APR 1.4.5, APR-Util 1.3.12
Compiled using: APR 1.4.5, APR-Util 1.3.12
Architecture:   64-bit
Server MPM:     Prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APACHE_MPM_DIR="server/mpm/prefork"
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D HTTPD_ROOT="/usr"
 -D SUEXEC_BIN="/usr/bin/suexec"
 -D DEFAULT_PIDLOG="/private/var/run/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D SERVER_CONFIG_FILE="/private/etc/apache2/httpd.conf"     <-- HERE IT IS

but if you only want to know the value of some configuration variable then phpinfo(), getenv() or apache_getenv() should be enough

share|improve this answer
Best answer so far. But there're additional problems: 1) Apache might not be in system's path 2) Apache instance might not be using default values -- Honestly, I doubt it's worth the effort. Whatever the problems is, there must be a better way to solve it than parsing Apache settings files (yes, there're normally more than one). –  Álvaro G. Vicario Nov 12 '12 at 9:50
Yeah, thats true, but if I would like to describe how to find config on every custom configuration I would have to write a book ;) In most cases that solution should work. –  lupatus Nov 12 '12 at 10:09
That's my point: there isn't a simple solution :) –  Álvaro G. Vicario Nov 12 '12 at 10:13
add comment

Look at the start of the output you get from phpinfo(), the basic apache configuration fodlers are shown there. So easiest is to make a trivial php script and call it once:

<?php phpinfo(); ?>

Likewise you can also directly query these settings. Check the documentation!

share|improve this answer
Hi, I dont seem to be able to query all the settings that are diplayed in phpinfo();. Like in the apache2handler section there is Server Root that gives C:/AppServ/Apache2.2 which is exactly what I need. But ini_get('Server Root'); returns nothing.. –  user1700262 Nov 12 '12 at 9:58
This is indeed correct, you can only query phps own ini commands/settings. Maybe you can use apaches mod_info? httpd.apache.org/docs/current/mod/mod_info.html –  arkascha Nov 12 '12 at 10:05
Ah, and obviously you can 'scrape' that setting from the html output you get from phpinfo() by using a simple regex. –  arkascha Nov 12 '12 at 10:07
how do i get the html text from phpinfo(); without printing it out? –  user1700262 Nov 12 '12 at 13:14
$info=file_get_contents('http://localhost/debug/info.php'); or wherever you have a phpinfo() call in a script. note that file_get_contents accepts urls as well as file paths. Not exactly elegant, but it works. –  arkascha Nov 12 '12 at 13:30
show 1 more comment

This is a classic way to locate httpd.conf file:

# find / -name 'httpd.conf' -print

Also you can file locate the file using

locate httpd.conf
share|improve this answer
add comment

I know that in windows, if you are using xampp it is in \xampp\apache\conf folder

share|improve this answer
add comment

if you are using xampp the file would be in this dir xampp\apache\conf

share|improve this answer
add comment

If it isn't listed in phpinfo(), perhaps use

apache_getenv(/* variable */)


share|improve this answer
add comment

httpd -V

It will shows all compile settings.

share|improve this answer
add comment

Your Answer


