Being one of the most widely used server technologies in the world, chances are that you too are using a Linux server. At its core, Apache is strictly an HTTP server, presenting web pages upon request. Depending on what you’re using your web server for, you may have requirements that fall a little outside of what Apache provides out of the box. Luckily, Linux provides for Modules.
Modules provide extensibility for Apache, granting it new abilities and functionalities, expanding its capabilities. By default, Apache comes with a shortlist of barebones modules. Some of these include the Core, the Apache HTTP Server features; Prefork, which implements a non-threaded, pre-forking web server; and Worker, a multi-processing module implementing a hybrid web server.
Modules may be compiled into the HTTPD binary when the server is built however additional modules may be included, separate from the HTTPD binary, and loaded as necessary. These additional Apache modules are referred to as Dynamically Shared Objects (DSOs). In order to use DSOs you must ensure that at build time, your server included the Shared Objects Module or SO Module (mod_so).
The SO Module is responsible for the loading of executable code and modules into the server at startup. This module must be a part of the HTTPD binary and cannot be added after the server’s initial build, for obvious reasons. If it was not included, and you wish to have modular extensibility, then you must rebuild your server, making sure that the mod_so is included is included.
If you’d like to check to see if mod_so is a part of the HTTPD binary, run the following command:
$ apachectl -M
- This command will present a list of modules included in the HTTPD server on their respective systems.
- The module mod_so should be a part of the displayed list.
Normally, DSOs are loaded through a directive in the HTTPD.conf file. In order to include additional modules to Apache, you need to modify the HTTPD.conf file. This requires two things: root access to the Apache server and experience in, or knowledge of, modifying configuration files. If you do not have root access or are not sufficiently experienced or knowledgeable in configuring configuration files then we highly suggest having this task completed by a system administrator or technical support team.
Adding a Module
Include the module on your server and note its location. For this exercise, we will use a fictional Foo module (mod_foo.so). It will be located in the modules/ on Server Root (modules/mod_foo.so). To include the module we will use the LoadModule directive. The LoadModule directive is a function of the SO Module (hence its necessity).
As we said before, adding a module requires modifying the HTTPD.conf file. Open the Apache configuration file and add the following line:
LoadModule foo modules/mod_foo.so
This directive links the object file (mod_foo.so) or library filename (modules/mod_foo.so) and adds the module structure named foo to the list of active modules.
Note: If you would like to deactivate or remove a module then simply open the HTTPD.conf and either comment out or delete the LoadModule entry for that particular module.
Once a module has been added or deleted, the Apache Server must be restarted or reloaded.
Stopping, Starting and Restarting the Server
Restarting or Reloading the Server
The following method restarts the Apache web server.
# systemctl restart httpd.service
Stopping the Server
The following method stops the Apache web server.
# systemctl stop httpd.service
Starting the Server
The following method starts the Apache web server.
# systemctl start httpd.service
If you have correctly modified your HTTPD.conf file and restarted your server then the module should load successfully. If you are still experiencing problems then you may have to consider resourcing your module or compiling it yourself from trusted source code.
Compiling a Module from Source Code
New modules may be compiled and installed using the Apache Extension tool (apxs). If the apxs tool is not present then it may be installed by installing the httpd-development package which contains the include files, header files, and the Apache extension application.
Execute the following command to download and install the httpd-development package:
# yum install httpd-devel
# yum groupinstall 'Development tools'
APXS (Apache Extension tool) is used to build and install extension modules for the Apache HTTPD Server. It builds DSO files from one or more object or source files. These source files may be any C source file (.c), object file (.o), or library archive (.a).
For example, if we have the source code for the foo module (foo.c), we will compile it into a shared object suitable for loading as an Apache module.
Navigate to the folder containing the source code and run the following series of commands:
# apxs -i -a -c mod_foo.c
This command compiles the object files from the C source file, links them into a dynamic shared object file, loads them into Apache’s module directory and automatically adds the Include line in the main configuration file.
Once your module has been compiled and installed you restart your server as advised above. Once the server is back up, run the following command to ensure that the module is enabled:
# apachectl -M | grep foo
If it returns the module as active then this confirms a successful installation.