How to Add Modules to the Apache Server on CentOS

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

And then:

# 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.

Check out these top 3 VPS services:

HostArmada
$1.79 /mo
Starting price
Visit HostArmada
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.5
  • Features
    4.5
  • Reliability
    4.5
  • Pricing
    4.0
IONOS
$1.00 /mo
Starting price
Visit IONOS
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.0
  • Features
    4.5
  • Reliability
    4.5
  • Pricing
    4.3
Ultahost
$2.90 /mo
Starting price
Visit Ultahost
Rating based on expert review
  • User Friendly
    4.3
  • Support
    4.8
  • Features
    4.5
  • Reliability
    4.0
  • Pricing
    4.8

How to Edit PHP Settings in Apache on an Ubuntu 18.04 VPS or Dedicated Server

This is a detailed guide on editing and configuring most PHP settings running on
4 min read
Avi Ilinsky
Avi Ilinsky
Hosting Expert

How to Configure Nginx and Apache on the same Ubuntu VPS or Dedicated Server

Nginx and Apache are great and powerful web servers. However, they both have dra
2 min read
Idan Cohen
Idan Cohen
Marketing Expert

Part One: How to Monitor Nginx using Elastic Stack on a CentOS 7 VPS or Dedicated Server

This is Part I of a two-part tutorial explaining how to use the different compon
5 min read
Idan Cohen
Idan Cohen
Marketing Expert

How to Host Multiple Websites on an Ubuntu 18.04 VPS or Dedicated Server

This article will show you how to host two or more websites on a single Virtual
5 min read
Idan Cohen
Idan Cohen
Marketing Expert
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top