Delicious Bookmark this on Delicious

Computer Forums

Installing an Apache server on Linux - Compiling from Source - Adding Apache modules without recompiling the Apache server



Once your Apache server is compiled with all the desired Apache modules, there might be a number of reasons why you might want to recompile your server. The most important one is to upgrade the components of the server. Nonetheless, you can add at any time modules to your compiled server by linking them as shared libraries (.so files). This is easily done by compiling the required module independently and editing the httpd.conf file accordingly; for instance, if you want to add back the userdir module, you will need to add the following lines to your httpd.conf file (before any call to the module itself):

LoadModule userdir_module modules/mod_userdir.so

This means that the shared library object mod_userdir.so will be loaded at runtime. Of course, this implies that it is first compiled and placed in the modules directory. In order to compile the module, look for the source code first (you should find it in httpd-2.2.19/modules/mappers/). Place yourself within this directory by running:

cd /home/Username/Desktop/httpd-2.2.19/modules/mappers

Now run the command:

apxs2 -c mod_userdir.c

This just compiled the mod_userdir.so module. Note that you need to use the apxs2 command with Apache 2 (with Apache 1 you would have used the apxs command). Now look for the mod_userdir.so file: normally it has been created in the hidden folder modules/.lib/. If you can't find it there, run:

sudo updatedb
locate mod_userdir.so

Place mod_userdir.so in the modules/ directory: you are all done ! Before proceeding further, you can verify that the userdir module is indeed part of these modules loaded at runtime; run the following command to list all Apache modules (static: ie compiled within the server AND shared via a .so file):

sudo /home/Username/Desktop/httpd-2.2.9/bin/apachectl -t -D DUMP_MODULES

You will get the result below:

All Apache modules loaded

You can now restart your Apache server and the userdir module will be up and running ...

A couple of important remarks:
  • In order to be able to link a shared library (.so file) dynamically at runtime, you must have compiled your Apache server with the so module mod_so (--enable-so)
  • If the .so file (Apache module) you're trying to link refers to a module that's already been compiled with the Apache server, you'll get an error:

    module is built-in and can't be loaded

In this tutorial, we have seen how to setup an Apache server by compiling it from source. We also learned how to add modules dynamically to your server without having to recompile it. Your next step will be to learn how to properly configure this server by editing the configuration file (httpd.conf and related files). Or maybe you would prefer to learn first how to add php to your server, and then how to add mysql.

Computer Forums

Next tutorial: Installing an Apache server on Linux - Configuring an Apache server


Back to computer forums