将luarocks整合进openresty,并安装lfs

现在需要用openresty实现一个文件夹遍历的功能,需要LuaFileSystem(简称lfs)。
第一步:将luarocks整合进openresty
下载地址:https://luarocks.github.io/luarocks/releases/
在这里插入图片描述
下载最新版的源码包即可。

将下载的源码包解压,进行以下配置:

1
2
3
4
5
6
7
8
$ wget https://luarocks.org/releases/luarocks-3.3.1.tar.gz
$ tar zxpf luarocks-3.3.1.tar.gz
$ cd luarocks-3.3.1
./configure --prefix=/usr/local/openresty/luajit \
    --with-lua=/usr/local/openresty/luajit/ \
    --lua-suffix=jit \
    --with-lua-include=/usr/local/openresty/luajit/include/luajit-2.1
make && make install

下面是配置正确情况下的输出:(我是先运行./configure,然后手动输入make,再手动输入make install的)
在这里插入图片描述
注意:这些参数中的路径要与你的openresty安装路径一致,包括最后的luajit-2.1的版本。
make install会将编译好的luarocks安装到/usr/local/openresty相关目录。
/usr/local/openresty/luajit/share/lua/5.1/luarocks
在这里插入图片描述
在/usr/local/openresty/luajit/bin 目录中,会看到luarocks的可执行程序,接下来的一步我们需要运行这个luarocks来安装LuaFileSystem(简称lfs)
在这里插入图片描述
第二步:给openresty安装lfs
进入到/usr/local/openresty/luajit/bin目录中

1
./luarocks install luafilesystem

运行结果:
在这里插入图片描述
在/usr/local/openresty/luajit/lib/lua/5.1目录中,会看到编译好的lfs.so,不用再拷贝什么的,openresty就直接可以用了。
在这里插入图片描述
只需要在lua文件中

1
local lfs = require("lfs")

就可以用了。

参考:
将luarocks整合进openresty
lua模块之lfs-获取当前目录
Lua中路径操作–lfs库(LuaFileSystem)说明
交叉编译openresty,修复支持大文件 (LFS)
Large File Support in Linux
openresty的安装与luarocks等插件的安装配置