5

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.

Synetech
  • 908
  • 1
  • 12
  • 27

2 Answers2

2

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    - binaries
  X:\Docs\Settings\Apache   - configuration files

So what I did was:

  1. I moved the conf and logs 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 normal

  2. Then at the bottom of the file, I added

      ServerRoot "X:\Docs\Settings\Apache"   - change the ServerRoot
      Include "conf/Includes.conf"           - include customizations

  3. The 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.)

  4. 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 to X:\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.)

Synetech
  • 908
  • 1
  • 12
  • 27
1

Just set ServerRoot to the directory you need or use the -d command line parameter. The ServerRoot directive doesn't have to point to the directory which contains the binaries and libraries for Apache httpd.

joschi
  • 20,747
  • 3
  • 46
  • 50
  • Ah, I see. I was under the impression that ServerRoot was where the server, that is the binaries, are located (probably because every example I’ve seen has the conf files in the same place as the binaries). I actually do have the `-d` argument, but since the installer automatically sets it to the location of the binaries, I thought that’s what it was. (Fortunately, that I store my log files in another folder is not a problem.) I’ll update the setting in about 2½ minutes. :) Thanks! – Synetech May 08 '10 at 15:09
  • Apache looks for its modules (ie *binaries*) in ServerRoot so that didn’t quite work. – Synetech May 08 '10 at 15:29
  • You could place a symlink to the `modules` directory the directory you point `ServerRoot` to. – joschi May 08 '10 at 17:59
  • Actually I can’t; the disk is FAT32. – Synetech May 09 '10 at 16:23