Howto compile apache module mod_example.c on Ubuntu

26 Oct

I need to write an apache module and looked around for a quick start on how to get started developing apache modules under ubuntu. I didn’t find anything 1,2,3, so here’s what I came up with:

  1. sudo apt-get install apache2-prefork-dev
  2. mkdir ~/mod_example && cd ~/mod_example
  3. wget -O mod_example.c “http://svn.apache.org/viewvc/httpd/httpd/tags/2.2.14/modules/experimental/mod_example.c?revision=818301&view=co ( adjust as necessary for your version of httpd )
  4. sudo apxs2 -c -i mod_example.c ( this builds and installs the module. )
  5. sudo su
  6. echo “LoadModule example_module /usr/lib/apache2/modules/mod_example.so” > /etc/apache2/mods-available/example.load
  7. vi /etc/apache2/mods-available/example.conf Paste the following:
    <Location /example-info>
    SetHandler example-handler
    </Location>
    
  8. cd /etc/apache2/mods-enabled && ln -s ../mods-available/example.* .
  9. service apache2 restart
  10. To test, browse to http://localhost/example-info.

    References: