Find the Location of Apache Web Server Configuration Files in Unix Like Systems

In most Unix-like or Unix-based systems, be it Mac OS or FreeBSD or different Linux distributions like Ubuntu, Debian, CentOS, Fedora, etc., a standard installation of the Apache HTTP Web Server would have its configuration stored in a file called httpd.conf or apache2.conf somewhere on the filesystem.

It is super useful to know what’s the exact location storing the httpd configuration and in what file so that you can operate well around debugging, setting up virtual hosts, installing and enabling modules, configuring ports, configuring logging and whatever else is possible.

From one system to another the location of the configuration files can differ and there’s a pretty simple solution to finding that out.

Apachectl – HTTPD Control Interface

apachectl is a command line tool that acts as a frontend to the Apache HTTP Web Server and ships with the package. So if you have the web server installed, you already have apachectl installed. Run the following command:

$ apachectl -V
Server version: Apache/2.4.29 (Ubuntu)
Server built:   2020-03-13T12:26:16
Server's Module Magic Number: 20120211:68
Server loaded:  APR 1.6.3, APR-UTIL 1.6.1
Compiled using: APR 1.6.3, APR-UTIL 1.6.1
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 enabled)
 -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="/etc/apache2"
 -D SUEXEC_BIN="/usr/lib/apache2/suexec"
 -D DEFAULT_PIDLOG="/var/run/apache2.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="mime.types"
 -D SERVER_CONFIG_FILE="apache2.conf"

As you can see a lot of information is dumped. The relevant ones here are HTTPD_ROOT and SERVER_CONFIG_FILE. From this output if you concatenate the value of both the variables then you know that the configuration file on this machine is stored at /etc/apache2/apache2.conf. This is also your main server configuration file. If you cd into /etc/apache2, then you should find the other configuration files there as well.

The output can definitely differ from system to system. For instance take a look at this from my Mac OS:

$ apachectl -V
Server version: Apache/2.4.41 (Unix)
Server built:   Oct 17 2019 18:04:28
Server's Module Magic Number: 20120211:88
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 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=256
 -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 AP_TYPES_CONFIG_FILE="/private/etc/apache2/mime.types"
 -D SERVER_CONFIG_FILE="/private/etc/apache2/httpd.conf"

You can’t really rely on the value of HTTPD_ROOT in this case but SERVER_CONFIG_FILE does the job and the other configuration files can be found at /private/etc/apache2.

Using the httpd Binary Directly

In some cases, like CentOS, apachectl can no longer be used as a front end to the HTTP server. The alternative here is to use the httpd or apache binary directly (whichever is available for you).

$ httpd -V
Server version: Apache/2.4.37 (centos)
...
Server compiled with....
 ...
 -D HTTPD_ROOT="/etc/httpd"
 ...
 -D SERVER_CONFIG_FILE="conf/httpd.conf"

Leave a Reply

Your email address will not be published.