LUA+MOD_LWT environment construction under "Lua" Linux

Source: Internet
Author: User
Tags lua

Lua is a small scripting language. It has the advantages of being lightweight and extensible. It can be used as a powerful, lightweight scripting language for any program that needs it.

LWT (LUA Web Tools) enables you to use LUA to develop Web applications and to run directly on Apache. LWT's core functionality is provided through an Apache module (MOD_LWT). In addition, LWT provides optional LUA modules to access the database and cache.

Now use LUA + LWT to build a background web environment.

  To install LUA:

There are two ways to install LUA in Linux.

The first kind: The system for Ubunut, Debian and other support Apt-get command can use this method.

sudo apt-get install lua5.1

The second type:

1, first go to Lua's official website (http://www.lua.org/ftp/) Download the latest release package, I chose the lua-5.1.4.tar.gz

2, use the command TAR-XZVF lua-5.1.4.tar.gz

3, the CD lua-5.1.4, and then execute sudo make, after the end of sudo make install, if there is no error in the middle, then success.

  Install MOD_LWT:

Before installing MOD_LWT, you must ensure that Apache, LUA, and liblua.so are installed.

First download the MOD_LWT Project installation package lwt-0.9.1.tar.gz, unzip.

CD lwt-0.9.1

CD MOD_LWT

Make

Make install

The installation process will generate Httpd.lua and Httpd/wsapi.lua two files in the/USR/LOCAL/SHARE/LUA/5.1/directory

Then modify the Apache configuration file httpd.conf

Vim/etc/apache2/httpd.conf

Add it on the inside:

AddHandler LWT. Lua

AddHandler Lwt-wsapi. ws

LoadModule lwt_module/use/lib/apache2/mod_lwt.so

Save and then invoke command startup module in Apache configuration directory

A2enmod LWT

Restart Apache
Apache2ctl restart

There was a problem restarting Apache:

The reason is that port 80 is occupied with NETSTAT-APN | grep 80 command to view 80 port usage:

The port is lighttpd occupied, LIGHTTPD is a lightweight Web server, here does not need him, directly killall-9 lighttpd

Restart Apache again:

Restart success:

Now you can use the official website test script Test.lua to try it:

1Require "httpd"2Local request_fields = {"uri", "protocol", "hostname", "path", "Path_info", "args",3"Method", "filename", "Filedir", "User", "Auth_type",4"Local_ip", "Remote_ip" }5request, args = ...6Httpd.set_content_type ("Text/plain; Charset=utf8 ")7Httpd.write ("Hello Lua world\r\n")8  for_, KeyinchIpairs (Request_fields) Do9Httpd.write (Key...). (Request[key] or "(not set)"): "\ r \ n")TenEnd

Access Test.lua with browser, successful interface:

LUA+MOD_LWT environment construction under "Lua" Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.