I want to use the -f
command-line option for the Apache server so that I can store the conf files in a separate place (a data diectory) from the server binaries.
The problem is that I use the Include directive to separate and organize the configurations, but when I use a command like Include "addons/SVN.conf"
, it fails because Apache looks for addons/SVN.conf in relative to the ServerRoot directory instead of the ServerConfigFile directory.
I can work around this by using absolute paths (eg Include "e:\foo\bar\baz\Apache\conf\addons\svn.conf"
, but I don’t like that since it means I would have to change each and every Include directive if I move the conf folder as opposed to simply changing the -f option.
Does anyone know of a way to get the Include directive to work relative to the conf file that Apache is passed. I tried Include "./addons/SVN.conf"
, but that too was relative to the ServerRoot. This forced relative-to-ServerRoot Include behavior kind of defeats the whole purpose of specifying an alternate config file to the one in ServerRoot/conf.
Thanks.
Okay, I figured it out (thanks joschi for suggesting changing ServerRoot, that was part of the solution).
What I have is two Apache related locations, eg:
Y:\Servers\HTTP\Apache
- binariesX:\Docs\Settings\Apache
- configuration filesSo what I did was:
I moved the
conf
andlogs
directories from the binaries directory to the docs directory. In…Settings\Apache\conf
is httpd.conf which is nearly identical to httpd.conf.default. It has the following entry:ServerRoot "Y:\Servers\HTTP\Apache"
#as normalThen at the bottom of the file, I added
ServerRoot "X:\Docs\Settings\Apache"
- change the ServerRootInclude "conf/Includes.conf"
- include customizationsThe next step was simply to edit a couple of my Includ-ed .conf files that use LoadModule, and passing the full path to the .so file.
If I had lots of LoadModule calls in my customized .conf files, instead of using absolute paths, what I would do is to create two new .conf files, (eg BinLoc.conf and ConfLoc.conf) each containing a single ServerRoot directive to set it to the binary/docs directories. Then I could wrap the LoadModule calls as such:
Include "conf/BinLoc.conf"
LoadModule ssl_module modules/mod_ssl.so
Include "conf/ConfLoc.conf"
(Unfortunately the second Include would have to use an absolute path to the settings directory, so it would kind of defeat the purpose.)
Finally, I set Apache to load the httpd.conf file from my docs directory (ie load
X:\Docs\Settings\Apache\httpd.conf
). There were several ways to do this. The installer uses the ConfigArgs registry entry for the Apache service, but I decided not to use that and emptied it out. I tried setting HKLM\SOFTWARE\Apache Software Foundation\Apache\2.2.15\ServerRoot toX:\Docs\Settings\Apache
, but Apache doesn’t seem to pick that up. I decided to go with the command-line. I modified my Install.bat so that when it creates the Apache service, it passes the httpd.conf file using the-f
argument (editing a batch file is much easier/faster than modifying a multi-string in the registry).In fact, I was already passing the .conf file using the
-f
before, so ultimately the only changes that were required (other than moving the folders to my docs directory) were to add an extra ServerRoot directive to httpd.conf to reset the configuration directory and to change the few LoadModule directives in my non-default (ie customized) .conf files to use absolute paths (though if there were lots of them, I could set it back to the binary .Apache now runs just fine, and the (replaceable) binaries and the (irreplaceable) configuration files are nice and separate.
:)
(Oh, and the logs are elsewhere, eg
X:\Docs\Logs\Apache
. The log-related entries in httpd.conf use an absolute path to that, but should I ever change the log directory, it’s a simple matter of search-and-replace-in-files to update, just like it would be with the absolute paths for the LoadModule directives in my custom .conf files if I changed the location of the binaries.)Just set ServerRoot to the directory you need or use the
-d
command line parameter. TheServerRoot
directive doesn't have to point to the directory which contains the binaries and libraries for Apache httpd.