C++ application server module for apache2

Cette page est disponible en français


This is a module for apache2 whiche enables compilation, loading and execution of C++ classes and HTML pages with c++ embeded. I work on this module for over 4 years and I use it in prod uction on several applications (both professionally and personally). It is stable and reactive. Web applications development is very pleasant and quite fast.

Here is a list of features and characteristics.

As the module is today :


But why ?

Because I found j2ee concept very interesting, because the Java running environment is not within reach of a Cobalt Qube with only 64 MB of memory  (also try to run a php page on a Qube... and I'm not talking about RoR). And because I had to throw myself into C++, since the time I told myself ! Moreover, even if we do a lot of things with j2ee, I do not like Java.

But how ?

Api is similar to that provided by javax.servlet.http. But unlike Java, C++ does not have a garbage collector, you should see this as an advantage because the use of smart pointers whith reference counting can safely manage memory allocation (see the Raii idiom).


A debian, from etch (tested on mips (el), powerpc, i686 and em64t), with packages g++, libapache2-mod-apreq2, libapreq2, libapreq2-dev, apache2-mpm-worker, apache2-threaded-dev, libapr1, libapr1-dev, libvmime0, et libvmime-dev. Pour les connecteurs  libsqlite0, libsqlite0-dev, sqlite, libsqlrelay-0.39, sqlrelay-dev,libpq5 et libpq-dev.

cobalt:~# apt-get install g++ libapache2-mod-apreq2 libapreq2 libapreq2-dev \
apache2-mpm-worker apache2-threaded-dev libsqlrelay-0.39 \
sqlrelay-dev libapr1 libapr1-dev libvmime0 libvmime-dev \
libsqlite0 libsqlite0-dev sqlite libpq5 libpq-dev bison flex


Actualy not a screenshot but pieces of programs

a controler ( /ctrl.C ) :

#include <raii.H>

using namespace raii;
using namespace raii::sql;

class SERVLET(index) : public HttpServlet {

void service( HttpServletRequest& request, HttpServletResponse& response) {

String action=request.getParameter("action");

if ( action.empty() || action == "index" ) {
new String( String("hello ")
+ request.getParameter("name") + "!" ) );
else if ( action == "plop" ) {
//do something
else {
throw ServletException("Unknown action");


a view  ( /view/index.csp ) :

ptr my_attr=request.getAttribute("my_attr");
if ( ! my_attr )
throw ServletException("plop");
bonjour <%= *my_attr %><br/>
hello <%= request.getRemoteAddr() %> !

Vector<String> headers=request.getHeaderNames();
for ( Vector<String>::const_iterator it=headers.begin();
it != headers.end();
++it) {
<td><%= *it %></td>
<td><%= request.getHeader(*it) %></td>
<% } %>

with a customized tag

<%:table<Vector<String> > in=request.getHeaders(); th="header"; th="value"; cond=self.begin()%>
<td><%= *self.elem %></td>
<td><%= request.getHeader(*self.elem) %></td>
<%/table<Vector<String> > %>
response << "PLOP!";


You can download sources on GitHub  or debian packages for i686 (it also works great on mipsel, powerpc and x86_64)(BSD 3-Clause License). (or these outdated debian packages)

Installation from sources

$ git clone
$ cd libapache2-mod-raii
$ SU0=su0 make install

If you do not have su0 :

$ make
$ su -c "make install"

or to build debian packages

$ git clone
$ cd libapache2-mod-raii
$ fakeroot debian/rules binary

Then you need to tell apache that there is a new module to load (without forgetting to turn on apreq)

# cat > /etc/apache2/mods-available/raii.load
LoadModule raii_module /usr/lib/apache2/modules/
SegfaultHandler on
# a2enmod apreq
# a2enmod raii

Installing debian packages

# dpkg -i libapache2-mod-raii*XXX*ARCH.deb
# a2enmod apreq
# a2enmod raii


Because the operation of this module, you must use mpm-worker version of apache and run a single server process. However, there is no limitation on the number of threads (take care of the memory used by each thread's stack). This give the file /etc/apache2/apache2.conf

 StartServers         1
ServerLimit 1
ThreadLimit 25
MaxClients 25
ThreadsPerChild 25
MinSpareThreads 5
MaxSpareThreads 15
MaxRequestsPerChild 0

and finally restart apache :

# apache2ctl restart

And then ?

You can install Not So Original, a photo gallery that processe your raw files, TinyCMS or loudspeaker.

Help !

In case of problems, please drop a mail to me. " raii AT blackmilk o fr".