Kira Resari
Kira Resari

Reputation: 2440

Apache ~ Configuring Server Root for Relative Paths

I am having trouble with an Apache Server service not finding the module files when I try to use relative paths.

The essence of the issue is that my project has an Apache service subfolder, and that the Apache service needs to be able to run from regardless of where the user decides to install the program.

The file where the Apache files can be found in the project are as follows:

Now, how can I configure the ServerRoot in the httpd.conf to recognize the correct root?

My current setup is:

 ServerRoot ".."

This works fine when running the xxx.exe directly. However, it fails when trying to install it as a service. I assume this is because the service does not run the xxx.exe directly, but rather executes it from another directory, so naturally ServerRoot ".." does not work anymore. The error message this produces in the Application Log is:

 >>> xxx.exe: Syntax error on line 81 of C:/Release Static/Apache2.4/conf/httpd.conf: Cannot load modules/mod_access_compat.so into server: The specified module could not be found.     .

My first approach to fix this was trying to log the exact path where Apache is trying to look for the file. For this purpose, I tried having Apache log something in the error log by writing a LogMessage directive in the httpd.conf before the line that caused the error. However, I was unable to even log something as simple as a test message. The code I tried using was:

 LoadModule log_config_module "C:/Release Static/Apache2.4/modules/mod_log_config.so"
 LoadModule log_debug_module "C:/Release Static/Apache2.4/modules/mod_log_debug.so"
 ErrorLog "C:/Release Static/Apache2.4/logs/error.log"
 LogLevel debug rewrite:trace8
 LogMessage "Test"

This apparently worked since the error continued to occur only later when trying to load modules with relative paths. However, it did not log "Test" in the error.log either, so there apparently is something else that I'm missing.

If I got this much to work, my next step would be trying to figure out a way for Apache to return me the absolute path of the ServerRoot directory it tries to use, and then modify the value accordingly until I have a solution where the relative path always points to the installation directory.

Upvotes: 2

Views: 2916

Answers (2)

Thomas
Thomas

Reputation: 10105

If you run httpd.exe from a batch file, you could also use an environment variable.


D:\Unexpected Folder\Totally Unexpected Folder\run.bat

set APACHE_SERVER_ROOT=%cd%\apache-2.4
%APACHE_SERVER_ROOT%\bin\httpd.exe

D:\Unexpected Folder\Totally Unexpected Folder\apache-2.4\conf\httpd.conf

# ...

Define SRVROOT "${APACHE_SERVER_ROOT}"

ServerRoot "${SRVROOT}"

# ...

Upvotes: 0

Kira Resari
Kira Resari

Reputation: 2440

Okay, after a lot of trial and error I have found out a configuration that works:

One method for configuring the ServerRoot to use a relative path is to not set the ServerRoot at all.

This will apparently cause Apache to default the server root to the first root of whatever directory you start the server file from.

For example, I started the service from:

D:\Unexpected Folder\Totally Unexpected Folder\NBL\Apache2.4\bin

...and it successfully found all modules in the NBL\Apache2.4\modules folder and started writing log files in the NBL\Apache2.4\logs folder.

Upvotes: 1

Related Questions