In a recent project, we use OpenResty (Scalable Web Platform by Extending NGINX with Lua) as API gateway. Nginx hosts the webserver, and Lua script stores the logic.

One of our Lua files needs LuaXml modue to parse xml files. But the module is not installed by default in OpenResty. So we get this error when testing the nginx config – nginx: [error] init_by_lua error: /opt/openresty/nginx//conf/errors.lua:1: module ‘LuaXml’ not found.

So I downloaded the module and copy LuaXML_lib.so and LuaXml.lua to /opt/openresty/lualib. They are the only two needed files. Try again, then I get a different error:  /opt/openresty/lualib/LuaXML_lib.so: wrong ELF class: ELFCLASS32

Google tells me this means the module is for 32 bits OS. Oh, OK. Then I either need to find a module for 64 bits  or compile the source code for 64 bits.

Let’s do the hard way first – compiling LuaXML source code for 64 bits OS. Here is the how to:

wget http://viremo.eludi.net/LuaXML/LuaXML_101012.zip
mkdir LuaXml
unzip LuaXML_101012.zip -d LuaXml/

yum install libtermcap-devel ncurses-devel libevent-devel readline-devel
wget https://www.lua.org/ftp/lua-5.1.4.tar.gz

cd LuaXml/
gcc -shared -fPIC -o LuaXML_lib.so LuaXML_lib.c -I ../lua-5.1.4/src

Then copy LuaXML_lib.so and LuaXml.lua to /opt/openresty/lualib.

The easy way is to use LuaRocks  (Lua package manager):

wget http://luarocks.org/releases/luarocks-2.3.0.tar.gz
tar zxpf luarocks-2.3.0.tar.gz
./configure --with-lua-include='/home/ec2-user/app/files/ngx_openresty-'
make bootstrap
luarocks install luaxml