Home > Apache HTTP Server Module > Create the first Apache Module

Create the first Apache Module

Let’s create our first Apache module.

1. Environment & Requirements

Ubuntu Linux (or any Linux distro)
Apache HTTPD Server 2.x
APXS - APache eXtenSion tool
libtool (distributed w/ Apache package in Ubuntu)

2. Create 

First, create the module package for development, including source code in C and the pre-created makefile:

$ apxs2 -g -n hello
Creating [DIR]  hello
Creating [FILE] hello/Makefile
Creating [FILE] hello/modules.mk
Creating [FILE] hello/mod_hello.c
Creating [FILE] hello/.deps

Access to ‘~/hello’ directory, now let’s make

$ make

Some libraries package will be created.
Now we need to create the shared memory object library (.so file) to load into Apache:

$ sudo apxs2 -i -a -c mod_hello.c

To check whether the library ‘mod_hello.so’ is installed, you can verify by following command:

$ ls /usr/lib/apache2/modules

If ‘mod_hello.so” is there, then it’s ready to load.
Next step is to edit the Apache Configuration file to load at server startup:

$ sudo vi /etc/apache2/httpd.conf

Paste the following script to the config file:

# httpd.conf
LoadModule hello_module libexec/mod_hello.so
<Location /hello>
   SetHandler hello

It’s done for setup. Now let’s restart the Apache Server:

$ sudo apachectl restart

Open web browser and navigate to the following to verify our first module working or not: http://localhost/hello

3. References:

APache eXtenSion tool

“Hello World” in C API

A Hello World Apache Module with KDevelop on Ubuntu

If you have any regards, comments or suggestions, feel free to contact me.

Pete Houston

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: