mod_lua (what was mod_wombat, and is part of Apache core since version 2.3) is something which I'd quite like to work with for Google Summer of Code 2009. In order to work on it, you first need to be able to compile and run it. Doing this on linux is trivial - checkout the svn head of httpd, ./configure (with appropriate command line arguments), make and then sudo make install. Doing so on Windows is less trivial, but it can be done.
For my Windows setup, I've got a standard binary distribution of win32 Apache 2.2.9 (complete with development include and library files) running on Vista. This makes things slightly more interesting, as mod_lua targets Apache 2.3 and above, but I can't find win32 binary distributions of 2.3, nor do I feel confident in compiling it under windows. From this baseline, I did the following:
- Checkout the mod_lua svn trunk (using TortoiseSVN)
- Create a new Visual Studio project and add all of the mod_lua source files
- Add additional include directories (
"E:\CPP\lua-5.1.4\src";"C:\Program Files\Apache Software Foundation\Apache2.2\include")
- Add
LUA_DECLARE_EXPORT to the preprocessor definitions
- Add additional library directories (
"C:\Program Files\Apache Software Foundation\Apache2.2\lib";"E:\CPP\lua-5.1.4\Debug")
- Add
lua5.1.lib, libapr-1.lib, libaprutil-1.lib and libhttpd.lib to the library list
- Add a post-build event to copy the resultant DLL to the modules folder (
cp "$(OutDir)\$(ProjectName).dll" "C:\Program Files\Apache Software Foundation\Apache2.2\modules\mod_lua.so")
- Fix the usage of
AP_DECLARE and AP_DECLARE_LUA throughout the codebase (patch available on the httpd-dev mailing list)
- Copy the
ap_args_to_table and ap_body_to_table functions over from Apache 2.3's util_script.c into a new file, util_script_ap23.c. This is compilcated due to ap_body_to_table's usage of the request_req::body_table field, which is not present in the 2.2 version - but can be worked around via usage of apr_pool_userdata_[sg]et with the request's pool.
- Compile the project and tweak
httpd.conf as required to load and configure the module

(for comparison, similar info screenshot on the linux build)
Comments
Apache configuration
Your file structure looks good, though your Apache configuration less so. The relevant lines from my httpd.conf are as follows:
LoadModule lua_module modules/mod_lua.so
LuaScope once
LuaCodeCache never
AddHandler lua-script .lua
Thanks !
Thank you for the compiled mod_lua.so, I really couldn't find it anywhere else.
However, I would like to ask you something - please pardon my bad English, I'm French.
My Apache server is included in the WAMP server 2.0 (http://www.wampserver.com/en). Here's what things look like in c:/wamp after I tried to make the mod_lua work using your hello_world file ->
.....bin /
.......... apache /
...............apache2.2.8 /
....................bin /
.........................[things]
.........................lua5.1.dll
....................modules /
.........................[...]
.........................mod_lua.so
.....www / { here I put my "sites". It's the equivalent of /htdocs }
..........hello_world.lua
In the httpd.conf file, I added the following lines >
LoadModule mod_lua modules/mod_lua.sothen, as seen at http://lua-users.org/wiki/ModWombat, I tought it was the same
AddHandler lua-handler .luaI hoped then that, when I visit http://localhost/hello_world.lua, the magic words "Hello world" would appear on screen. Alas, all I got was the lua source code, exactly as if I had done nothing.
You know there isn't much doc' on "lua-on-the-web" out there ; I learned LUA as a first programming language and I know I'm not a "pro" - I used it to write little Add-ons for world of warcraft 2 years ago. But I loved its simplicity and ... I would really enjoy creating dynamic html docs with lua.
I didn't know your blog before searching google for Lua+apache, but I've seen enough on it to realize that you have a lot of things to do, and that this blog entry is pretty old now ; I don't want to get you worried ...
But I try to ask - maybe you could know what's wrong between my all-in-one Apache/Php/MySQL and your sexy mod_lua ; and maybe you could have enough time to help me ;)
Thanks you again, and thanks for reading. Sorry about the English. I did my best to avoid writing something awful :'(
Bye !
compiled mod_lua
As you've been asking for it, here are the compiled binaries: http://corsix.org/misc/ap_mod_lua-090926.zip
Before you get all excited though, bear in mind the following:
Could you please provide compiled file ?
As you have managed to compile the mod_lua for win32 / vista, could you please provide a link to download it ?
Thanks you so much !
Please, compiled !
Please provide a compiled version mod_lua module for Apache2. Since you have managed to compile it successful it would make everyone so much more happy! :)
It is quite interesting
It is quite interesting post.After reading this post, I understood what is mod-lua win32. Hope it will be very useful for me.
mod_lua on win32
good work.
I am able to build with linux, but I failed in windows xp, due to apache.
can u pls share the mod_lua.so for apache /win32
Regards,
Tijo.
Could you please provide
Could you please provide mod_lua.so compiled for win32? The newest version of the kepler framework don't have mod_lua and the older versions use lua 5.0.
util_script_ap23.c
You can find the entire file at http://www.corsix.org/misc/util_script_ap23.c - you may want to check that the usage of pool userdata is correct, as I've got very little experience with the Apache/APR side of things.
apr_pool_userdata_[sg]et
Actually, I am interested in how you used apr_pool_userdata_[sg]et to get rid of r->body_table in 2.2. Could you post a diff please :)
parsebody
I simply got rid of parsebody because it doesn't work with multipart form data and it introduces a DoS vulnerability. I think mod_lua needs a proper way to deal with request bodies. I have not yet looked at mod_request, mod_form, mod_upload, etc but it seems they could be adapted for the task, although it would be nice to make this globally available for all other modules. Mod_wombat used to have libapreq2 but multipart was not supported neither.
BTW, your info.lua looks nice. I have one too, but it's not as complete :)
http://www.coliko.com/info.lua
Post new comment