45

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!

amateur barista
  • 478
  • 3
  • 7
  • 21
Claudiu
  • 1,157
  • 5
  • 18
  • 27

5 Answers5

56

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.

Zayne S Halsall
  • 1,902
  • 15
  • 19
  • 2
    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 http://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` – Jason S Dec 01 '13 at 03:16
  • also does not work with when using apache installed via macports -- answer by msandord works for me! – pgee70 Jun 17 '14 at 09:53
23

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

chrisjlee
  • 955
  • 2
  • 11
  • 21
  • On macOS, the command to find out which config files the running instance of https is **actually** using is `apachectl -t -D DUMP_INCLUDES`. – fbitterlich Apr 06 '22 at 12:03
13

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.

msanford
  • 1,427
  • 15
  • 27
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

Creaforge
  • 141
  • 2
  • 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'". – Tom Auger Nov 07 '19 at 19:35
0

First, check which is the startup script for Apache. For macOS, it should be /Library/LaunchDaemons. That might include a working directory, or similar information.

You could also debug the running process itself with dtruss. You can connect to the running process using dtruss -p <pid>. Then, if you HUP it, you can probably pore over the output to see where it's grabbing its config from. Alternately, just start Apache by calling dtruss directly with dtruss start_apache_command.

You could always just do a system-wide search for httpd.conf with find / -name httpd.conf.

apaderno
  • 123
  • 9
Christopher Karel
  • 6,442
  • 1
  • 26
  • 34