How can I tell which config file Apache is using?

83,861

Solution 1

With any *nix application, the easiest method is to query the binary itself. In the case of httpd, I'd imagine the process would be something like this:

$ whereis httpd
/usr/sbin/httpd
$ /usr/sbin/httpd -V
Server version: Apache/2.2.11 (Unix)
Server built:   Jun 17 2009 14:55:13
Server's Module Magic Number: 20051115:21
Server loaded:  APR 1.2.7, APR-Util 1.2.7
Compiled using: APR 1.2.7, APR-Util 1.2.7
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"

As you can see - my OS X says the binary, if not directed otherwise, will use the config file: /private/etc/apache2/httpd.conf

If that doesn't help, perhaps Christopher's suggestion of find is the next step.

Solution 2

There's another serverfault question regarding this. If you're using a debian based server you can use apache2ctl to determine which config file is being used:

apache2ctl -V

More on this:

How to find out which httpd.conf apache is using at runtime

Solution 3

Try

ps ax | grep httpd

and you should (might) get output like

1633   ??  Ss     0:00.21 /usr/sbin/httpd -f /etc/httpd.conf

Additionally, how exactly are you restarting the server? Just curious in case you somehow aren't actually re-reading the config file.

Solution 4

Because some configs use Server app, brew or whatever, and because one liners FTW :

$(ps ax -o comm | grep -m 1 httpd) -V | grep SERVER_CONFIG_FILE

This command do the following :

  • Find an active httpd process
  • Output config info
  • Grep the config file

Tested on Sierra & El Capitan

Share:
83,861

Related videos on Youtube

Claudiu
Author by

Claudiu

Updated on September 17, 2022

Comments

  • Claudiu
    Claudiu almost 2 years

    I'm trying to set up virtual hosts on Mac OS X. I've been modifying httpd.conf and restarting the server, but haven't had any luck in getting it to work. Furthermore, I notice that it's not serving files in the DocumentRoot mentioned in httpd.conf (Libraries/WebServer/Documents), but in a different directory (/usr/local/apache2/htdocs). I don't see this folder mentioned anywhere in httpd.conf. Furthermore, PHP works, but the "LoadModule php5_module" line is commented out. This makes me think it's using another .conf file. How can I figure out which config is actually being loaded?

    Update: I just deleted that httpd.conf and apache behaves the same after restart, so it definitely wasn't using it!

  • Claudiu
    Claudiu about 14 years
    hm it doesn't have the -f flag in it
  • Knaggi
    Knaggi over 10 years
    This won't work if you're using Apache via the Server.app In that case you'll need the process list in the answer from @msanford serverfault.com/a/155114/187798 which shows that the Server.app starts httpd with a different configuration file as shown here from my installation (Mavericks) /usr/sbin/httpd -D FOREGROUND -f /Library/Server/Web/Config/apache2/httpd_server_app.conf -D WEBSERVICE_ON
  • Knaggi
    Knaggi over 10 years
    +1 As this is the only answer that works for all cases, that is if you're configuring Apache yourself or if you're using Apache via Server.app
  • Tom Auger
    Tom Auger over 4 years
    The $ is important (it's not the command line prompt in this case). If converts the statement in parens into a command, to which we pass the -V flag. Leaving it out results in: "syntax error near unexpected token `-V'".
  • Jean-Luc Barat
    Jean-Luc Barat almost 3 years
    It doesn't work for me, may due to my current error conf....
  • fbitterlich
    fbitterlich about 2 years
    On macOS, the command to find out which config files the running instance of https is actually using is apachectl -t -D DUMP_INCLUDES.