Question

I've read this and:

  1. There's no working solution proposed
  2. I'm not running Windows but Linux
  3. It's a home-made compilation
  4. running httpd-2.4.9

So here's what I tried so far, but without success:

  • follow this suggestion "where do I put 3rd party lua modules"?
  • tried to add all possibilities of PATH for Lua in my vhost conf:

    LuaPackageCPath /web/htdocs/olivier/doonoo/2/
    LuaPackagePath /web/htdocs/olivier/doonoo/2/
    LuaPackageCPath /web/htdocs/olivier/doonoo/2
    LuaPackagePath /web/htdocs/olivier/doonoo/2
    LuaPackageCPath /web/htdocs/olivier/doonoo/2/?.so
    LuaPackagePath /web/htdocs/olivier/doonoo/2/?.so
    LuaPackageCPath /web/htdocs/olivier/doonoo/2/?
    LuaPackagePath /web/htdocs/olivier/doonoo/2/?
    LuaPackageCPath /web/htdocs/olivier/doonoo/2/
    LuaPackagePath /web/htdocs/olivier/doonoo/2/
    LuaPackageCPath ./?.so
    LuaPackagePath ./?.so
    LuaPackageCPath ./
    LuaPackagePath ./
    LuaPackageCPath ./?
    LuaPackagePath ./?
    
  • tried to put lfs.so in my http folder: /local/install/httpd-2.4.9/modules/lua

  • tried to put lfs.so in my lua shared /usr/local/share/lua/5.2
  • tried to put lfs.so in the more generic shared /usr/local/share
  • tried to put lfs.so in the shared http modules /opt/httpd-2.4.9/modules/

And now I still haven't found a working solution. Any idea? By the way I can use r:notice() to write some information, so is there a way to dump the path and/or cpath that lua is using?

In my files, when I have the directive require "bb" in the file aa.lua and bb.lua is in the same path as the aa.lua, it works. If I try to do export LUA_PATH= and restart my webserver, the directive require "bb" doesn't work anymore in aa.lua. This implies that the environment variable LUA_PATH and LUA_CPATH have some effect on the Apache mod_lua.

Now I tried something else: dynamic library. I do this:

# lua
Lua 5.2.1  Copyright (C) 1994-2012 Lua.org, PUC-Rio
> a,b = package.loadlib('/usr/local/lib/posix_c.so', 'fcntl')
> print (a,b)
function: 0x7fbda3f845b0        nil
>

This means it tried successfully to open + get the fcntl function coming from posix_c.so.

Now if I try to add this code into my lua file for mod_lua like this:

function handle(r)
    r.headers_out['Cache-Control'] = 'no-cache, must-revalidate'
    r.headers_out['Expires'] = 'Mon, 26 Jul 1997 05:00:00 GMT'
    r.content_type = 'application/json';

    local a,b = package.loadlib('/usr/local/lib/posix_c.so', 'fcntl');
    r:puts(tostring(a)..','..tostring(b))
    return apache2.OK
end

I got this output:

nil,/usr/local/lib/posix_c.so: undefined symbol: luaL_setfuncs

After reading this, I guessed what went wrong: I had installed 5.2.1 version and mod_lua was compiled with 5.1. So I removed the 5.2.1, all 5.2 links, and re-compiled the luaposix lib. Now the Webpage gives me this: function: 0x220bce0,nil which means it successfully opened the library.

Any idea what's going on?

Was it helpful?

Solution

I've made it!

Two things were blocking, and I hope to help other ones if they have the same problem:

  1. Wrong version number. mod_lua was 5.1 and lua installed was 5.2. Solution: remove 5.2 and install 5.1, then recompile all needed modules
  2. bad *.so location. This command helped me to solve the problem: r:puts(tostring(package.cpath) .. ',\n'). It shows the path where lua is looking for the dynamic libraries. And no one matched where my lfs.so, posix_c.so, and posix.lua were. Thus I've made the folder /usr/local/lib/lua/5.1/ (which is very "clean" name and location to me) and copied those files there.

Now everything works.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top