Setting up LAML (Linux, Apache, MySQL, Lua) with MAMP
As a weekend project I decided to set up a LAML, (Linux, Apache, MySQL, Lua) stack on my computer. I never worked with Lua before, but I figured it wouldn’t be too hard to get it working with my MAMP setup. Getting started, I spent some time reading any articles I could find on the web that talked about setting up or using using Lua for web development. I quickly ran into the Kepler Project which as their website points out:
is an open source platform that brings the power of Lua to web development
While this was my goal, I wanted to start from scratch since I haven’t had any experience with the language and didn’t want to learn it on a specific platform just yet. So, I went on to figure out how to install and configure Lua with MAMP. To accomplish this yourself, you will need: Xcode, MAMP, Lua, LuaRocks, MAMP source, and mod_fcgid.
This one is pretty straight forward. You can easily install Xcode if you have an OS X install DVD. Otherwise you can download it from the Apple Developer Center.
Installing Lua is also straight forward. Download the source from Lua’s FTP site. I chose the current version (5.1.4). After extracting the source run the following commands:
This should install the Lua interpreter into your /usr/local/bin/
To install LuaRocks, you first need to download the source. The current release is 2.0.1. After downloading the source run the following commands:
This should install luarocks in /usr/local/bin/ . You can test your installation with:
You should be presented with a list of commands to use luarocks.
This part is a little tricky as you need to make sure you have the source for your MAMP installation. You can download the MAMP source from the MAMP website. Running the .dmg should extract the source. After extracting the source run the following:
Once you have moved your source over, extract the MySQL package then run the following commands:
Once you have finished building MySQL, you will want to move the mysqlclient into the current MySQL location:
You will now be able to install the luasql-mysql package from luarocks with the following command:
This is an easy one:
This part was a bit tricky for me since I don’t have much experience compiling Apache modules. First, you will need to extract the httpd source, for me this was httpd-2.0.63.tar.gz. Next, you will want to build Apache into a separate directory. Use the following to build Apache:
While running the make command, you may get the following error:
Fixing this is simple, all you need to do is edit /Applications/MAMP/Library/include/httpd-2.0.63/srclib/apr/include/apr.h and make the following modifications:
I know its taken quite some time now, but you are almost done! All that’s left is to build mod_fcgid and configure Apache. To build mod_fcgid run the following commands:
Now that you have everything built and in place, you just need to configure Apache and then you will be ready to start building Lua web apps!
Open /Applications/MAMP/conf/apache2/httpd.conf with your favorite text editor and add the following to the load modules section:
While you are at it, you can comment out the following lines if you like (I am not sure if it is possonlble to run mod_cgid with mod_fcgid, so I just took them out).
Next, find the IfModule mod_fcgid directive, and add the following under it:
Finally, restart Apache through the MAMP application and test it out! Here is a sample lua script to test out your Lua environment: