Installing lighttpd with mod_magnet on centos x86_64

Installing lighttpd was pretty simple, however while setting up this wordpress site I wanted to enable WP Super Cache. In order to run Super Cache in full mode on lighttpd we need lighttpd with mod_magnet.

mod_magnet requires that lua be install. For some reason lighttpd doesn’t appear to like lua when it is installed via yum. So I had to compile it by source.

mkdir /root/installers
cd /root/installers
mkdir lua
cd lua

wget http://www.lua.org/ftp/lua-5.1.4.tar.gz
tar xvfz lua-5.1.4.tar.gz
cd lua-5.1.4

Note: if you are using x86_64 you will need to make this modification

vim src/Makefile

change

CFLAGS= -O2 -Wall $(MYCFLAGS)

to

CFLAGS= -O2 -Wall -fPIC $(MYCFLAGS)

If that change isn’t made you will likely get this error when compiling lighttpd:
libtool: link: gcc -shared .libs/mod_magnet_la-mod_magnet.o .libs/mod_magnet_la-mod_magnet_cache.o -L/usr/local/lib -llua -lm -Wl,-soname -Wl,mod_magnet.so -o .libs/mod_magnet.so
/usr/bin/ld: /usr/local/lib/liblua.a(lapi.o): relocation R_X86_64_32 against `luaO_nilobject_’ can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/liblua.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[3]: *** [mod_magnet.la] Error 1
make[3]: Leaving directory `/root/installers/lighttpd/lighttpd-1.4.25/src’
make[2]: *** [all] Error 2
make[2]: Leaving directory `/root/installers/lighttpd/lighttpd-1.4.25/src’
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/root/installers/lighttpd/lighttpd-1.4.25′
make: *** [all] Error 2

make linux test

My instance didn’t come with readline-devel or ncurses-devel preinstalled so it threw a few errors:
In file included from lua.h:16,
from lua.c:15:
luaconf.h:275:31: error: readline/readline.h: No such file or directory
luaconf.h:276:30: error: readline/history.h: No such file or directory
lua.c: In function âpushlineâ:
lua.c:182: warning: implicit declaration of function âreadlineâ
lua.c:182: warning: assignment makes pointer from integer without a cast
lua.c: In function âloadlineâ:
lua.c:210: warning: implicit declaration of function âadd_historyâ
make[2]: *** [lua.o] Error 1
make[2]: Leaving directory `/root/installers/lua/lua-5.1.4/src’
make[1]: *** [linux] Error 2
make[1]: Leaving directory `/root/installers/lua/lua-5.1.4/src’
make: *** [linux] Error 2

and

gcc -o lua lua.o liblua.a -lm -Wl,-E -ldl -lreadline -lhistory -lncurses
/usr/bin/ld: cannot find -lncurses
collect2: ld returned 1 exit status
make[2]: *** [lua] Error 1
make[2]: Leaving directory `/root/installers/lua/lua-5.1.4/src’
make[1]: *** [linux] Error 2
make[1]: Leaving directory `/root/installers/lua/lua-5.1.4/src’
make: *** [linux] Error 2

In gettings those errors just install the packages

yum install readline-devel
yum install ncurses-devel
make linux test

Hello world, from Lua 5.1!

make linux
make install
cp etc/lua.pc /usr/lib/pkgconfig/

Lua should now be installed
Time to install Lighttpd

cd /root/installers

mkdir lighttpd
cd lighttpd/
wget http://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-1.4.25.tar.gz
tar xvfz lighttpd-1.4.25.tar.gz
cd lighttpd-1.4.25
./configure --with-openssl --with-lua

checking if lua-support is requested… yes
checking for LUA… no
checking for LUA… no
checking for LUA… configure: error: Package requirements (lua-5.1 >= 5.1) were not met:

No package ‘lua-5.1’ found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables LUA_CFLAGS
and LUA_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

It says to adjust the PKG_CONFIG_PATH, ok so:

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/lib/pkgconfig
export PKG_CONFIG_PATH
./configure --with-openssl --with-lua

Plugins:

enabled:

mod_magnet

mod_magnet is enabled! yay

make
make install

and done! Lighttpd is now installed with mod_magnet.

resources:
http://dragkh.wordpress.com/2009/10/12/centos-5-lighttpd-1-5-0-cache-no-package-lua-found/
http://www.verlihub-project.org/doku.php?id=howto_install_lua_library_on_64_bit