Building and installing Lapis with OpenResty
Running OpenResty and making applications with Lapis
What
Lapis web framework running on top of OpenResty with LuaJit
Why
Trying out a new framework for me called Lapis. Built on top of OpenResty making for fast rendering of content with LuaJit compiling. I decided to record down my findings for how to accomplish using Lapis tonight.
I started with Ubuntu 15 and the rest is a summary of:
- build + install OpenResty
- testing OpenResty
- install Lapis
- testing Lapis with sample Lua application
For now, this is a good starting point. Next up, I would like to try sending queries to a database.
How
Install OpenResty 1.9.7.3
sudo apt-get install git libreadline-dev libncurses5-dev libpcre3-dev \
libssl-dev perl make build-essential perl make libssl-dev \
postgresql-9.4 postgresql-server-dev-9.4 postgresql-contrib-9.4
./configure --with-cc-opt="-I/usr/include/openssl -I/usr/include" \
--with-ld-opt="-L/usr/include/openssl -L/usr/include" -j8 \
--prefix=/opt/openresty-1.9.7.3 \
--with-pcre-jit \
--with-ipv6 \
--with-http_postgres_module
# make with 4 spare cpu power
make -j4
# install
make install
Make a plain app to test OpenResty
Create the application
mkdir ~/work
cd ~/work
mkdir logs/ conf/
Create nginx configuration file
Contents of ~/conf/nginx.conf
worker_processes 1;
error_log logs/error.log;
events {
worker_connections 1024;
}
http {
server {
listen 8080;
location / {
default_type text/html;
content_by_lua '
ngx.say("<p>hello, world</p>")
';
}
}
}
Start the applicatoin
To start the application you need to load your environment’s path with the custom nginx binary that is compiled with OpenResty
PATH=/opt/openresty-1.9.7.3/nginx/sbin:$PATH
export PATH
nginx -p `pwd`/ -c conf/nginx.conf
We are now ready to test the application with a curl call
curl http://localhost:8080/
The expected output should be:
<p>hello, world</p>
Lapis
Now that we have the OpenResty confirmed working, time to move on to the Lapis framework.
Install Lapis
apt-get install luarocks
luarocks install moonscript
luarocks install lapis
luarocks install --server=http://rocks.moonscript.org/manifests/leafo lapis
Make a test application
mkdir lapistest
cd lapistest
lapis new --lua
lapis server
Test the application with curl!
curl http://localhost:8080
You should see the following: