02/23/2013 § Leave a comment
Got a really good idea for what I believe is a marketable IT Utility for the Resturaunt Industry, so I sat down earlier this week to set up my tools and libraries, and roll up some prototype code. Its been a while since I’ve done any Apache module development, so I set about re-familiarizing myself with the code and procedures.
One thing I have a real stick up my ass regarding is documentation; it needs to be complete and accurate, or you don’t publish it. Publishing documentation that is innacurate or incomplete is a sin. Too bad so many web sites do it.
I get it if its just out of date; but innacurate is unforgivable. Stuff like “…then edit the file…”, so many times I see this, without any reference to “what” file is supposed to be edited, or edited with what…? Another thing that bothers me is when I need to track down instructions that leave off with out any discernable next step, and then I have to track down that next step on some other website. I think a lot of this is due to the nature of OSS, things change at the drop of a hat, but if you’re going to publish information, its of no use if its incorrect.
I want to jot down the steps I took to get an Apache 2 module working from source before I forgot, so here goes; we are assuming an apache module called “mod_module.c”; first install Apache 2 dev files by installing (I’m not supporting Apache 1, sorry) the apache extension tool; “apt-get install apache2-prefork-dev”, prefix the command with sudo if you’re not root, of course. Then write your way cool extension, the important bit is this; in a remarked section of the code place a structure similar to this:
* Name: mod_module
MOD_LIB="-L/usr/local/lib/somelib -lsomelib -lm -lz"
if [ "X$MOD_LIB" != "X" ]; then
echo " + using $MOD_LIB for Mylib support"
You’ll of course be substituting the “mod_module” references for the actual names in your dependancy list. The important part, the part that took me a few tries to understand, is in Apache 2’s LoadModule directives. In your distribution’s apache2 “../mods_available” subdirectory you need to make sure there’s a “mod_module.load” file, make sure the name of the file corrosponds to the “Name” field in this struct, and the file should contain a LoadModule directive that looks like
"LoadModule mod_module /usr/lib/apache2/modules/mod_module.so". You’ll then want to build the module with
"sudo apxs2 -c -lsomelib -lm -lz mod_module.c", using the “somelib” reference if your module has a dependancy on some external library. You’ll end up with “mod_module.la”, this also threw me; you end up with a static library rather than a shared object. The next step creates the actual shared library MySQL will use; “sudo apxs2 -i mod_module.la” will build the shared library and place it where apache will find it. Then “sudo a2enmod mod_module” activates it. You also need to make sure that in your <sites-available>/<website>/”Directory” directives or your “.htaccess” file has whatever properties your module requires are in your site’s config file.
Believe me, it took over three days for me to figure out how to make this all work given the disparity, dry prose, and plain incorrectness of the textual instruction available on the net. I’m sure its correct, however I’m also sure I’ve missed something so if anyone out there tries these steps and can’t get it to work I’d appreciate feedback.