HOWTO Apache 2 + Lua 5.1 + FastCGI in Ubuntu
Submitted by develCuy on Sat, 2010-01-30 16:46
Install basement
$ sudo apt-get install apache2-mpm-worker liblua5.1-0-dev $ sudo apt-get install libfcgi-dev libapache2-mod-fcgid
Install Luarocks
Download latest version from: http://luarocks.org/releases/, extract it, open a terminal and do a "cd" into its directory, then:
$ ./configure --with-lua-include=/usr/include/lua5.1/ $ make $ sudo make install
Install WSAPI
$ sudo luarocks install wsapi-fcgi
Configure Apache
Edit /etc/apache2/sites-enabled/000-default, in section "Directory var/www", set "AllowOverride" from "None" to "All"
$ sudo /etc/init.d/apache2 restart
Test
Create following files in /var/www/:
.htaccess:
Options ExecCGI AddHandler fcgid-script .lua FCGIWrapper /usr/local/bin/wsapi.fcgi .lua
launcher.fcgi:
#!/usr/bin/env lua require "wsapi.fastcgi" require "hello" wsapi.fastcgi.run(hello.run)
index.lua
module(..., package.seeall)
function run(wsapi_env)
local headers = { ["Content-type"] = "text/html" }
local function hello_text()
coroutine.yield("<html><body>")
coroutine.yield("<p>Hello Wsapi!</p>")
coroutine.yield("<p>PATH_INFO: " .. wsapi_env.PATH_INFO .. "</p>")
coroutine.yield("<p>SCRIPT_NAME: " .. wsapi_env.SCRIPT_NAME .. "</p>")
coroutine.yield("</body></html>")
end
return 200, headers, coroutine.wrap(hello_text)
endGo to http://localhost/hello.lua
Further reading
Blessings!

develCuy's blog by Fernando Paredes Garcia is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 Peru License.


An Alternative guide WSAPI
Great post, I also submitted a guide for getting this to work as well, it make help some Ubuntu users as well. It works for all recent versions:
http://lua-users.org/wiki/LuaWsapi
get parameters , GET and POST..
hello, thanks for your little tutorial.
but now, i'm faced a problem..
hot to retrieve GET or POST parameters.?
please help me..
Pretty interesting and very
Pretty interesting and very useful post thanks a lot for sharing it....
Submersible pumps