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!
-
I note that some shared hosting platforms, e.g., those at InMotion, refuse to allow customers to view the httpd.conf file or even to obtain the settings. Commands liked httpd are disabled when you open a shell terminal in your root (though clearly available elsewhere since man pages are available). So the location is not really helpful. Execute in a php file to see system, e.g., Linux ecngx, Server API, e.g., FPM/FastCGI , etc. To know Apache settings like Override status for particular apache directives you might put in .htaccess instead, you have to test blindly. – Dalton Bentley May 09 '23 at 13:36
6 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_HAS_SENDFILE
-D APR_HAS_MMAP
-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
-D APR_USE_FLOCK_SERIALIZE
-D APR_USE_PTHREAD_SERIALIZE
-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
-D APR_HAS_OTHER_CHILD
-D AP_HAVE_RELIABLE_PIPED_LOGS
-D DYNAMIC_MODULE_LIMIT=128
-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_LOCKFILE="/private/var/run/accept.lock"
-D DEFAULT_ERRORLOG="logs/error_log"
-D AP_TYPES_CONFIG_FILE="/private/etc/apache2/mime.types"
-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

- 4,208
- 17
- 19
-
2Best 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 González Nov 12 '12 at 09: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
-
apache2 -V worked for me to show me the location of the conf file. But apache2 -v actually showed me the version info. – codescribblr Aug 24 '17 at 01:16
-
mostly lower case `v` is assigned to version or verbose mode (but of course there is no such rule), my answer contains capital `V` – lupatus Aug 28 '17 at 21:22
-
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

- 6,498
- 3
- 17
- 16
-
Thanks for this. I tried all of the other solutions on this thread and a couple others, but I kept getting `"conf/httpd.conf"` (a relative path). Using the `find` command was the only way I could get the absolute path for the configuration file. – Spencer D Nov 23 '15 at 18:14
httpd -V
It will shows all compile settings, in the middle of the results you will find:
- The Apache root directory:
/usr/local/apache
- The Apache config file path from the root directory:
conf/httpd.conf
Apache conf file:
/usr/local/apache/conf/httpd.conf
root@host [~]# httpd -V
Server version: Apache/2.4.16 (Unix)
Server built: Dec 15 2015 10:01:02
Cpanel::Easy::Apache v3.32.6 rev9999
Server's Module Magic Number: ...
Server loaded: APR 1.5.2, APR-UTIL 1.5.4
Compiled using: APR 1.5.2, APR-UTIL 1.5.4
Architecture: 64-bit
Server MPM: prefork
threaded: no
forked: yes (variable process count)
Server compiled with....
-D APR_HAS_SENDFILE
-D APR_HAS_MMAP
-D APR_HAVE_IPV6 (IPv4-mapped addresses disabled)
-D APR_USE_SYSVSEM_SERIALIZE
-D APR_USE_PTHREAD_SERIALIZE
-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
-D APR_HAS_OTHER_CHILD
-D AP_HAVE_RELIABLE_PIPED_LOGS
-D DYNAMIC_MODULE_LIMIT=256
-D HTTPD_ROOT="/usr/local/apache"
-D __SUEXEC_BIN="/usr/local/apache/bin/suexec"
-D DEFAULT_PIDLOG="logs/httpd.pid"
-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
-D DEFAULT_ERRORLOG="logs/error_log"
-D AP_TYPES_CONFIG_FILE="conf/mime.types"
-D SERVER_CONFIG_FILE="conf/httpd.conf"

- 2,080
- 3
- 25
- 32

- 815
- 12
- 35
-
Thanks for the being the only answer that tells a n00b like me that the full path was combining these paths: `HTTPD_ROOT` + `SEVER_CONFIG_FILE` ⭐ was confused bc I only looked at the config file path – Prid Aug 01 '22 at 19:11
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!

- 41,620
- 7
- 58
- 90
-
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 09:58
-
This is indeed correct, you can only query phps own ini commands/settings. Maybe you can use apaches mod_info? http://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