Page 35 - Open Soource Technologies 304.indd
P. 35
Open Source Technologies
Notes mod, it is generally a pain to rebuild all of Apache for every little change/addition you make
to your mod.
The second way to include a mod is to build Apache to load mods at start up. It build them with
the following commands (detailed more fully at http://httpd.apache.org/docs-2.0/install.html):
>./configure —prefix=PREFIX —enable-so
>make
>make install
Then it, for simplicity, make the user and group in httpd.conf match my own. They will look
something like this:
User billyboebob
Group billyboebob
3.1.3 Hello World
Next you need a mod to run. Here is the code for a Hello World. We’ll look at what it does in
more detail shortly.
#include “httpd.h”
#include “http_config.h”
#include “http_core.h”
#include “http_log.h”
#include “http_protocol.h”
#include “ap_compat.h”
static void register_hooks(apr_pool_t *p);
static int helloworld2_handler(request_rec *r);
static void register_hooks(apr_pool_t *p)
{
ap_hook_handler(helloworld2_handler, NULL, NULL, APR_HOOK_MIDDLE);
}
static int helloworld2_handler(request_rec *r)
{
r->content_type = “text/html”
ap_send_http_header(r);
ap_rputs(“<H1>Hello <i>Apache 2.0</i> World!</H1>”, r);
return OK;
}
30 LOVELY PROFESSIONAL UNIVERSITY