lua + nginx + FastCGI in Debian

I’ve recently been doing some testing in lua, and have been comparing the results to the EdgeLink Consulting CMS that we’ve designed in PHP. So far this solution is able to serve substantially more requests per second than our current CMS. However, we haven’t really spent much time optimizing the CMS. The goal is to have a working copy first before any optimizations are done. We’ve also been working on some eCommerce modules for the platform.

With all that being said, I’d like to post a quick tutorial on how I got this setup. It was quite the task. Although there was a tutorial I found to do the same task, it was a little bit confusing. My tutorial will have a lot of the same steps, with some minor adjustments. This tutorial is written at an intermediate level. Some trivial steps have been omitted.

NOTE: This has been tested with Debian 5.0.4 (Stable)

  1. Install nginx

     apt-get install nginx

    We’ll have to do some modifications later on to add the FastCGI handler. For simplicity we will keep the web path to “/var/www/nginx-default” and listen on port 8081 in case you have another webserver running on port 80.

  2. Install lua 5.1 (and WSAPI libraries)

    apt-get install lua5.1 liblua5.1-wsapi-fcgi-0 liblua5.1-coxpcall0 liblua5.1-filesystem0

    apt-get install liblua5.1-wsapi-doc

    Can’t do much testing without this. Note: The second line is not necessary if you are running Debian testing, and get the liblua5.1-wsapi-fcgi-1instead.

    EDIT: You’ll notice that I added in liblua5.1-filesystem0. Steve pointed out that there is a bug in liblua5.1-wsapi-fcgi-0. It doesn’t include it as a dependency. He reported this as a bug here, and it was fixed in liblua5.1-wsapi-fcgi-1.

  3.  Install spawn-fcgi

    If you’re running Debian testing you may be able to get spawn-fcgi through the distribution, however, I just downloaded it and compiled from source.

    tar -xzvf spawn-fcgi-1.6.3.tar.gz
    cd spawn-fcgi-1.6.3.tar.gz
    make install

  4.  Create a FastCGI Socket

    spawn-fcgi -F 4 -u www-data -s /var/run/nginx-fcgi.sock -P /var/run/ — /usr/bin/wsapi.fcgi

    For the sake of simplicity, we will just spawn it manually for now. If you’re feeling crafty you can add the above line to the start condition in/etc/init.d/nginx, and the line below to the stop condition. You can add both of them to restart.

    cat /var/run/ | xargs -n 1 kill

  5.  Create a lua file in /var/www/nginx-default/

     In this tutorial, use hello.lua. You can change this to whatever, you want but just make sure you make the modification in the nginx configuration below as well.

  6.  Edit /etc/nginx/sites-available/default

    Now let’s add the code that will point nginx to the correct file. For simplicity, we will simply point it to hello.lua. You can change this to anything, or simply modify the code to accept any *.lua file, as seen in the tutorial listed above. Here is the top of my default file:

    listen   8081 default;
    server_name  localhost;
    access_log  /var/log/nginx/localhost.access.log;

    location / {
        fastcgi_pass    unix:/var/run/nginx-fcgi.sock;
        fastcgi_param   SCRIPT_FILENAME “/var/www/nginx-default/hello.lua”;
        fastcgi_param   PATH_INFO       $request_uri;
        fastcgi_param   QUERY_STRING    $query_string;
        fastcgi_param   REQUEST_METHOD  $request_method;
        fastcgi_param   CONTENT_TYPE    $content_type;
        fastcgi_param   CONTENT_LENGTH  $content_length

  7. Restart nginx

    /etc/init.d/nginx restart

  8. Visit http://localhost:8081/

    Congratulations! You should now see hello.lua.

If you have any problems, post in the comments. Stay tuned for more related posts.

New Site

Hi Everyone,

I just wanted to write a quick post to say that I’ve migrated this website over to the content management system that Jake and I have been working on. It took a little while to migrate over, but everything seems to be working now.

Stay tuned for more updates.

Time for a Yearly Update

It’s about that time of year again, where I dust off the keyboard and decide to write my yearly post. Every year I intend to make more frequent updates, so we’ll have to see how it turns out this year. At the very minimum, I’m going to post another “Shotglass Showcase.”

Once again, I’ve been keeping pretty busy this year.

  1. I was involved in Laurier Musical Theatre’s production of Grand Hotel: The Musical in January. This was a great experience as always, and I’m once again looking forward to next year’s production of Follies.
  2. Jake Billo and I have been working on a new blogging platform that is aimed at trying to increase page load speeds. We’re finding that WordPress is a bit too bloated. This will be released soon, and is going to be very lightweight.
  3. This year I’ll be going into the 4th year of Honours Computer Science. This will probably be my second last year in the program.

That is about all that is new for now. Once again, I’ll be posting the “Shotglass Showcase” again soon. Stay tuned.

Well This Time it Ought to be Dave 3.0

Wow. It’s been so long since I posted that there is a drastic change in WordPress versions. Let’s hope I can even figure out how to publish this. I’ve been keep busy over the last 6 months or so that I haven’t posted. However, I’m finally done school for the year with the exception of taking 1 course in the summer. Here is just a quick overview of the past 6 months, and what I’m currently working on.

  • As mentioned above, I’m taking one (1) course, CP317: Software Engineering. I think I’m making a fairly good move by taking it in the summer. There are only 12 people in my class, including me, and the main focus of the course is to use the knowledge taught to complete one large group project. We decided to develop a multi-player networked tank game in Java.
  • I’ve been working on a side project through my business EdgeLink Consulting dealing with VoIP and Asterisk. This is a very neat technology with a very wide range of capabilities that I’m very excited to be working with. Expect a post in the next couple of days about Asterisk.
  • I was very busy throughout the fall and early winter with the musical that I’m in every year with Laurier Musical Theatre. This year it was How to Succeed in Business Without Really Trying. It went very well and I’m looking forward to the musical next year.
  • I’m also working on some other side projects that you may or may not hear about in the future.

That’s about it for now. You should see something in the next few days on Asterisk and VoIP.

Mind Mapping For Students

A few months ago I started using a program called MindManager. It’s a very powerful program used to create very aesthetically pleasing mind maps. I’ve been using it as a primary method of note taking in most of my classes. It doesn’t work so well for math, but for anything else, it’s a great option. I like it particularly because it easily allows me to link ideas together by adding relationships within the map, which aids me in recalling the information later.

Anthropology Map

There is also a feature that lets you add attachments to topics within the map, so that you can add pictures, or anything else that is appropriate. The reason I started using this to take notes was because I watched this video, which is a very good example of how students can make use of this program.

However, it’s not only useful for students, it can be used for anything. I’ve also been using this program to plan out various projects at work, and the recipients of these maps have been very impressed.

I’ve tried out several free alternatives for mind mapping, including FreeMind, but none of them make the maps look as good as MindManager does. It is definitely worth the investment for the product.

MindManager is available for both Windows and Mac.

JungleDisk and Amazon S3

Yesterday I read a post on 43Folders about having a paperless office. It also mentioned a very affordable and hassle-free way to backup the data on your computer. Amazon Simple Storage Service (Amazon S3) and JungleDisk provide such a solution. JungleDisk is a utility for Mac OS X that interfaces with Amazon S3. You can configure it to automatically synchronize certain folders on your computer at a time of your choosing. To give you an idea of how cheap it is, here is their pricing:

$0.15 per GB-Month of storage used

Data Transfer
$0.10 per GB – all data transfer in$0.18 per GB – first 10 TB / month data transfer out
$0.16 per GB – next 40 TB / month data transfer out
$0.13 per GB – data transfer out / month over 50 TB

$0.01 per 1,000 PUT or LIST requests
$0.01 per 10,000 GET and all other requests*
* No charge for delete requests

To give you an idea, I backed up all of my personal files; iTunes library, photos, documents, and emails, which is about 8.07GB of data, and it cost me $1.15. I think that might even be in USD, so really, I’m paying probably $0.02CAD by the time I get the bill.

If you’re looking for a hassle-free, dirt cheap(I even told Jake I think dirt is more expensive) way to backup your data, I definitely recommend this solution.

UPDATE: Fixed some formatting on the price list. Thanks Phil for pointing it out.

Is “Open 8 until Late” the Wrong Approach?

Recently I’ve been noticing TD Canada Trust pushing a marketing campaign that they are the superior bank because they have the longest hours. They are open “8 until late”, which is apparently open 50% longer than any other bank. I’m sure this sort of campaign might be very useful for a company like Wendy’s (ughh), with their “Eat Great, Even Late” campaign, but I fail to see the relevance for a bank in 2007.


When is the last time you actually had to see a teller? The fact is, more and more people are doing all of their banking online, or through a bank machine, neither of which depend on a branch’s hours. One of the only reasons to see a person at a bank, is for opening an account. Oh wait, you can apply for that online now too. I think their marketing dollars would be best used elsewhere, such as continuing to promote clients to use online banking. Not to mention, TD Canada Trust has one of the worst fee structures of any Canadian bank. Even students are paying $3.45/mo. if they can’t keep a minimum balance of $1,000. How many students do you know with that kind of money?

Considering they are one of the most popular banks around, it’s hard to believe they aren’t adapting as well as they should be. We don’t want longer hours, we want cheaper banking! Everyone knows that bankers work from 12:00pm-1pm every day.

My Go Bag

A while ago on Lifehacker, they did a series called “Show Us Your Go Bag“, where the readers sent in tagged pictures of the contents of their go bag. I never got around to actually sending them a picture of mine, so I’m going to post it here. Clicking on the picture will take you to Flickr where you can see the notes attached to it.

My Go Bad.

Here is the contents:

  • Leather portfolio
  • Umbrella (this has come in handy lately)
  • Camera
  • Large notebook
  • Morning newspaper
  • Binoculars
  • 15-inch Macbook Pro
  • Graph paper sticky notes (I got these in highschool, they are fantastic)
  • Various pens and pencils
  • Calculator
  • Ethernet cable (Very thin and small, came with my Fonero)
  • Moleskine notebook (to track my to-dos and work)

What’s in your go bag?

Shot Glass Showcase – Week 1

A few years ago when I was in England, I decided to start collecting shot glasses from all around the world. These are shot glasses that I either have acquired myself, or ones that have been brought back from various countries by friends. Some of them are very unique, so for the next 35 weeks (or until I run out of shot glasses), I will be posting a picture and description of one shot glass in my collection, as well as I drink you might potentially find in one of these shot glasses.

I think I’ll start off this series with one of my personal favourites that was brought to me from Jamaica.

Shot Glass Showcase 1

Since Jamaica is famous for their dark rum, here is a shooter you might enjoy in this glass:

Neutron Bomb – equal parts of the following:
Swiss Chocolate Almond
Dark Rum

It’s Friday! Go out, have a good time, and try this shot. Let me know how it is in the comments.

Changing Microsoft Office Word 2007’s Default Save Options

Microsoft Office 2007 is by far one of the best products Microsoft has ever made, with the exception of one thing. Microsoft decided it was necessary to introduce a new document format. These include xlsx, pptx, and docx. For the longest time, their Office products have used the doc, ppt, and xls formats. In addition to this change, none of these new formats are backwards compatible with Microsoft’s older Office products, which has caused a lot of people undue stress.

I’ve had several clients and co-workers wondering why they can’t open their Office 2007 documents from anywhere else except their own computer. One of my professors upgraded to Office 2007 and posted a docx file to the course management software. The entire lecture the next day was in uproar saying that they couldn’t open the file.

Luckily there is a way around this so that you can still have the great functionality of the software, without losing the portability.

  1. Every time you do a “Save As” you can change the drop down menu to save as a .doc (Microsoft 97/2000/2003 Compatible) instead of a .docx
  2. You can change the default save options to automatically save as a format of your choosing.

Microsoft has an article in their knowledge base about making this change. For your convenience, here is the rundown for making the change in Microsoft Word 2007. The article also explains how to do it in Excel and Powerpoint.

1. Double-click Microsoft Office Word 2007, double-click Word Options, and click Save.
2. In the right pane, right-click Save files in this format, and select Properties.
3. In Save files in this format, select Enabled.
4. In the drop-down box, select a default file save format.
5. Click Apply to save the settings.

I’m sorry Microsoft, but the world needs a new document format, like the United States needs Bush in power for another 4 years. (Oops, probably shouldn’t have said that.)

I’d like to thank Phil and Warren for helping me test this process.