Page 36 - Open Soource Technologies 304.indd
P. 36

Unit 3: Apache Server



             module AP_MODULE_DECLARE_DATA helloworld2_module =                                   Notes

            {
            STANDARD20_MODULE_STUFF, /* stuff that needs to be declared in
                                             every 2.0 mod */
            NULL,                 /* create per-directory config structure   */

            NULL,                 /* merge per-directory config structures */
            NULL,                 /* create per-server config structure              */

            NULL,                 /* merge per-server config structures              */
            NULL,                          /* command apr_table_t                                *

            register_hooks              /* register hooks                            */
            };
            Take this c code name it ‘mod_helloworld2.c’ and save it. Now you can compile it using an apache tool
            called apxs. apxs is located in the bin Directory of the Apache 2.0.x build. The command that I used
            to compile this mod is ‘apxs -c -i -a mod_helloworld2.c’. This will build our mod and install it.
            What good is the code if you don’t see it doing anything? ‘cd’ to the ‘conf’ directory. In this
            directory is the file ‘httpd.conf’. Add these lines where it seems appropriate:

                    <Location /ourmap>
                  SetHandler helloworld2-handler

                 </Location>




                      Give a mod to run, the code for a Hello World.
            3.1.4 Module Definition

            Every standard Apache mod needs an initial ‘module’ to describe it. By convention this is the
            last thing in the module. To define it use:
                   module AP_MODULE_DECLARE_DATA foobar_module =

            Replace ‘foobar’ with the name of the module (the file name minus any extensions).
            3.1.5 Standard Module Stuff

            There  are  14  slots  in  a  standard  Apache  2.0  module.  We’re  fortunate  though.  The  macro
            ‘STANDARD20 MODULE STUFF’ predefines the first eight of these for us. The macro is defined
            in http_config.h if you desire to take a closer look at it. It mostly contains bookkeeping items
            such as the major and minor magic numbers for the Apache release.
            3.1.6 Config Slots

            The  next  four  slots  we  do  not  use,  so  let’s  skip  them.  They  have  to  do  with  host  wide  and
            directory wide configurations and access.






                                             LOVELY PROFESSIONAL UNIVERSITY                                    31
   31   32   33   34   35   36   37   38   39   40   41