Preparing for Lapis: OpenResty, LuaRocks, PostgreSQL, Tup, Sass, Git

Author
Michael
Published
2015, Jan 28, 01:09 pm
Category
Tech
Tags
Lapis, Linux

The Lapis web framework is amazing. Setting up your development environment is a bit involved. This post is my attempt to gather links and useful tidbits regarding the process process of preparing for Lapis.


Introduction

If your only OS is Windows, you've ended up on the wrong side of the metaphorical tracks. First install Linux and gain a basic familiarity, then we'll talk. If you're on OSX you almost certainly want to be using Homebrew. If you're a Linux user, you're good to go.

These instructions are just meant to get your system prepared for Lapis development. At the end we'll have links to the next steps.

Required Software OpenResty, LuaRocks, PostgreSQL

Only OpenResty is actually required, but LuaRocks and PostgreSQL are pretty fundamental.

OpenResty Nginx

Running Lapis requires OpenResty, which is basically the Nginx web server and a custom bundle of specially configured modules. For our purposes, suffice to say it's fast and easy to use.

Follow the OpenResty installation instructions. It's simpler than it appears at first glance. If your Linux distribution provides a package (like this one for Arch), that make it even simpler.

LuaRocks also Lapis and MoonScript

In order to install Lapis, we must first install LuaRocks, "a deployment and management system for Lua modules." Essentially, LuaRocks allows us to install things like Lapis and MoonScript without worry or hassle. Follow the LuaRocks installation instructions. Of course LuaRocks requires Lua, but that should be installed automatically.

Once you've got LuaRocks, we want to be using version 5.1, you can very easily install MoonScript and Lapis with the intuitive commands:

luarocks install moonscript
luarocks install lapis

PostgreSQL database

A web framework, like Lapis, requires a database for most interesting purposes. Lapis uses PostgreSQL.

Installing PostgreSQL is simple, but setting it up is not entirely trivial. The official documentation is not very helpful, so here are some links that are:

The bottom line is that PostgreSQL is managed by the postgres user. As postgres we need to run these commands with appropriate arguments:

initdb
createuser
createdb

Following the Arch Wiki, this process is pain free.

Addendum

If you see errors like module 'lapis' not found you may be experiencing a path expectation disconnect between LuaRocks and OpenResty. I discuss this issue in this post on the Arch Linux forum.

Recommended Software Tup, Sass

While these are not required, they make the task of developing with Lapis and MoonScript much more convenient.

Tup build system

Because MoonScript compiles into Lua (and should we make use of them, Sass to CSS and CoffeeScript to JavaScript) we need to recompile each time we change a file. Tup allows this to happen automatically.

Follow the Tup installation instructions. Once we've got Tupfiles, we can use tup monitor -a to keep our files compiled as we work.

Sass better CSS

Sass allows you to craft complex CSS in a much more programmatic style, with variables, nested rules, inheritance, mathematical operators, and more.

We can either follow the Sass official installation guide, or we can eschew Ruby and use LibSass + SassC instead. If that is a troubling thought, you can follow these straightforward SassC installation instructions.

Git version control

Installing Git is very easy. Using it can be somewhat challenging, but there's this incredible Code School - Try Git tutorial make the learning process fun and painless. Version control is incredibly important, not just for collaboration, but also for your own sanity.

Conclusion next steps

Learn about MoonScript, a gentler, kinder Lua.

Read the Lapis documentation. It's excellent.

Check out this list of Lapis tips, tutorials, snippets, and examples.

Most importantly, watch this video (at 720p or 1080p), where you can see all the software mentioned above put to awesome good use.



Comments


derek 2015, Feb 11, 02:23 pm

Many thanks for this. I agree this is a nightmare on Windows, is there any way around it? I'm so enjoying using moonscript with sqlite, but I can't get any modules installed. Just loads of errors, looks like I'm stuck with coffeescript..

Add a comment