Apache2 server configuration - novalexei/mod_servlet GitHub Wiki

###Apache2 server configuration.

OK, now when mod_servlet is built and installed into you Apache2 httpd server you need to configure it properly. Let's start from httpd.conf

####httpd.conf

The Apache2 httpd configuration file usually located in conf directory of your server and called httpd.conf. If it is not so check out your documentation. In that file we will need:

  1. Load module:

    LoadModule servlet_module modules/mod_servlet.so
    
  2. Configure module location:

    <Location "/">
        SetHandler servlet
    </Location>

    In this example I configured all requests (starting from root "/") will go to mod_servlet, but you can limit it to your liking.

  3. mod_servlet specific configuration. There are two configuration directives which can be used in httpd.conf file:

    • WebAppRoot - location of root directory where web applications will be deployed. It can be either absolute or relative, in which case it will be resolved against Apache2 server root.
    • ServletConfigurationFile (optional) - location of configuration file for mod_servlet. It can be wither absolute or relative, in which case it will be resolved against Apache2 server root. If this directive is not found the default location ${WebAppRoot}/servlet.ini. Full reference for servlet.ini file.
  4. Limit number of Apache processes to 1.

    This is optional but highly recommended step. Use threads instead of processes. This problem with processes is that you'll need to make an effort to synchronize you web application data between processes. It is seldom trivial. Currently mod_servlet doesn't share http_session instances between different processes.

    In order to limit the number of processes you'll need to configure the MPM (Multi-Processing Module) to run on single process. See the relevant documentation. For event MPM this configuration will look in httpd.conf something like this:

    <IfModule mpm_event_module>
        StartServers             1
        ServerLimit              1
        MinSpareThreads         10
        MaxSpareThreads         64
        ThreadLimit            400
        ThreadsPerChild         64
        MaxRequestWorkers       64
        MaxConnectionsPerChild   0
    </IfModule>
  5. SSL configuration.

    This is only relevant if you're using SSL (which you really should). Apache2 mod_ssl should be configured to produce environment variables in order for SSL_information to be available in the application.

    SSLOptions +StdEnvVars +ExportCertData
    

    Full mod_ssl documentation you can find here

####Environment.

Usually after above configuration you can start Apache2 httpd server and use mod_servlet. But the chances are, you'll see something like this:

httpd: Syntax error on line 154 of /opt/favordata/apache-httpd/2.4/conf/httpd.conf: Cannot load modules/mod_servlet.so into server: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.22' not found (required by /opt/favordata/apache-httpd/2.4/modules/mod_servlet.so)

If you didn't see it, stop reading and go celebrate. Otherwise read on. This error means that Apache2 server doesn't see all the shared libraries used by mod_servlet and usually it happens when you compiled the module with custom C++ compiler (see "mod_servlet build instructions"). For example, if you compiled it with flag -DCMAKE_CXX_COMPILER=/home/me/gcc/6.1.0/bin/g++, than Apache2 httpd will want to have an access to the libraries of this compiler. There are two ways to fix it:

  1. Set LD_LIBRARY_PATH (or whatever voodoo you do on Windows):

    export LD_LIBRARY_PATH=/home/me/gcc/6.1.0/lib:$LD_LIBRARY_PATH
    
  2. Just add all the necessary libraries to Apache2 lib. Find in your Apache2 server root directory lib (if it's not there, create it) and copy or link there the libraries (for g++ it is usually libstdc++.so)

⚠️ **GitHub.com Fallback** ⚠️