ubuntu下lua如何安装

ubuntu下lua如何安装,第1张

1网站下载LUA包http://www.lua.org/download.html,ctrl+F2输入gnome-terminal打开终端

2、下载ubuntu的编译支持

sudo apt-get install build-essential

注意,这里不仅仅是安装gcc而已,还包括很多其他工具。

3、下载libreadline相关支持,这个东西在编译时需要用到,无奈。

sudo apt-get install libreadline5

sudo apt-get install libreadline5-dev

4、编译以及安装

tar xzvf lua-5.1.2.tar.gz

cd lua-5.1.2

make linux

sudo make install

这里make的参数linux也可以是其他 *** 作系统,视具体情况而定。

5、测试

$ lua

Lua 5.1.2 Copyright (C) 1994-2007 Lua.org, PUC-Rio

>

按下Ctrl+D退出。

有两种方式,一种是apache2.3以上会内置的lua module,大家可以下载apache httpd 2.3.8的代码,在modules目录下有lua这个目录。

另外一种是今天要介绍的,使用wsapi方式。

我们使用ubuntu服务器,先确保lua5.14以及apache2都安装成功。

然后

sudo apt-get install apache2-mpm-worker liblua5.1-0-dev luarocks

sudo apt-get install libfcgi-dev libapache2-mod-fcgid

sudo luarocks install wsapi-fcgi

然后修改.htaccess或者httpd.conf或者你的vhost配置,添加下面部分。

Options ExecCGI

AddHandler fcgid-script .lua

FCGIWrapper /usr/local/lib/luarocks/bin/wsapi.fcgi .lua

要注意的是wsapi.fcgi也许是在不同目录下,用find自己找吧。

在var/www下你的站点中新建一个luacgi目录,然后建立两个文件。

launcher.fcgi:

#!/usr/bin/env lua

require "wsapi.fastcgi"

require "hello"

wsapi.fastcgi.run(hello.run)

index.lua:

module(…, package.seeall)

function run(wsapi_env)

local headers = { ["Content-type"] = "text/html" }

local function hello_text()

coroutine.yield("<html><body>")

coroutine.yield("<p>Hello Wsapi!</p>")

coroutine.yield("<p>PATH_INFO: " .. wsapi_env.PATH_INFO .. "</p>")

coroutine.yield("<p>SCRIPT_NAME: " .. wsapi_env.SCRIPT_NAME .. "</p>")

coroutine.yield("</body></html>")

end

return 200, headers, coroutine.wrap(hello_text)

end

然后用chown –R www-data:www-data luacgi修改目录owner。

这时候应该就能用xxx.com/luacgi/index.lua访问了。

如果你用nginx,也有现成的lua mod可以使用(作者是淘宝的程序员),这里就不多说了。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/11799414.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-18
下一篇2023-05-18

发表评论

登录后才能评论

评论列表(0条)

    保存