Find Apache httpd.conf file location

By | 12 October, 2015

So i was in the middle of a serious error debug session where some of the errors seemed to be apache’s fault. Probably some configuration adjustments, but for that i needed to see the current configuration (and change it if need be). But where is the httpd.conf file? After some practice, we easily look for it on the default places, depending on the linux distro (oh, i am assuming we are looking for it on a linux server), but let’s imagine we dont have a clue where it is. Now what? Read on.

Several ways to do it. But let’s take some time explaining the process:

[user]$ ps -ef

the ps -ef command lists all processes. You can pipe it to less to make it scrollable. Hell, you can pipe it to kingdom come, since its linux.

[user]$ ps -ef|grep apache

The grep apache command looks for the word “apache” on the ps -ef command results

You will get something like this (depending on your server and on how well you are into typing commands without messing up):

apache 20760 20753 0 Oct11 ? 00:00:56 /usr/sbin/httpd

Knowing that path, you can do this:

[user]$ /usr/sbin/httpd -V

That -V switch will show the httpd compile settings, where you will see tons of info (out of this post’s scope).
The line you want is:

-D SERVER_CONFIG_FILE="[your httpd.conf path will be here]"

To make things easier, we can do another grep on the results to get the exact info we need:

[user]$ /usr/sbin/httpd -V|grep SERVER_CONFIG_FILE

Which will get you just the line you need:

-D SERVER_CONFIG_FILE="conf/httpd.conf"

Again, your results may vary.

A note:

Like the example above, your path can show as relative and not absolute. But relative to what? With the /usr/sbin/httpd -V command, you will also get info about HTTPD_ROOT:

-D HTTPD_ROOT="/etc/httpd"

So your config file location will be relative to exactly that.

[user]$ cd /etc/httpd/conf

or go straight for the kill:

[user]$ sudo nano /etc/httpd/conf/httpd.conf

Hope this helps someone. Yes, either of the 4 people that read this.

References:

commanigy post about this
– linux reference about the ps command
– linux reference about the grep command