linux下lua開發環境安裝
我前面我們介紹了nginx+lua環境的搭建,在此我們再來瞭解下lua開發環境的安裝。
目前lua版本已經更新到lua5.3,但是我們在此安裝lua5.1,因為5.1運行了好多年,有好多模組都是基於此版本的,例如lua_gd。
安裝:
1.先安裝lua的相關依賴
yum install readline-dev readline-devel
2.安裝lua5.1
wget http://www.lua.org/ftp/lua-5.1.0.tar.gztar -zxvf lua-5.1.0.tar.gzmake linux testmake install
lua有一個模組管理工具luarocks,類似於yum,我們可以使用luarocks來安裝相關模組。
1.安裝
wget http://luarocks.org/releases/luarocks-2.2.1.tar.gztar zxpf luarocks-2.2.1.tar.gzcd luarocks-2.2.1./configure
會出現以下提示:
Lua interpreter found: /usr/bin/lua...Lua version detected: 5.1lua found in $PATH: /usr/binChecking Lua includes... lua.h not found (looked in /usr/include, /usr/include/lua/5.1, /usr/include/lua5.1)You may want to use the flag --with-lua or --with-lua-include. See --help.configure failed.
提示找不到lua.h,預設情況下會從/usr下尋找,因為我們需要指定lua.h的目錄
find / -name lua.h/usr/local/luajit/include/luajit-2.0/lua.h/usr/local/src/lua/lua-5.1.5/src/lua.h/usr/local/src/lua/LuaJIT-2.0.4/src/lua.h/usr/local/include/luajit-2.0/lua.h/usr/local/include/lua.h
再重新編譯安裝:
./configure --with-lua=/usr/local --with-lua-include=/usr/local/includemake bootstrap
我們就將luarocks安裝到/usr/local下了,加入以下環境變數,就可以直接使用了:
export PATH=/usr/local/bin:$PATH
lua可用模組列別,可以在此查看http://luarocks.org/repositories/rocks/,我們通過以下即可直接安裝:
[root@usvr-126 local]# luarocks install luafilesystemInstalling https://rocks.moonscript.org/luafilesystem-1.6.3-1.src.rock...Using https://rocks.moonscript.org/luafilesystem-1.6.3-1.src.rock... switching to 'build' modegcc -O2 -fPIC -I/usr/local/include -c src/lfs.c -o src/lfs.ogcc -shared -o lfs.so -L/usr/local/lib src/lfs.oUpdating manifest for /usr/local/lib/luarocks/rocksluafilesystem 1.6.3-1 is now built and installed in /usr/local (license: MIT/X11)
安裝完成後,會在/usr/local/lib/lua/5.1/下產生一個lfs.so的檔案,我們只需要將此檔案拷貝到nginx中自訂的LUA_PATH中,就可以引用該庫,調用其中的函數。
例如在nginx的設定檔中引用:
lua_package_path ‘/usr/local/nginx/lua/?.lua;;’lua_package_cpath ‘/usr/local/nginx/lua/lib/?.?;;’;#其中”;;”代表原先尋找範圍。
註:路徑自己定義,也可定義成預設路徑。