Compiling the Haskell Warp web server

In my process of benchmarking various web servers I have come across the Warp web server, which runs using Haskell. Warp is supposedly the fastest Haskell based web server and having learned Haskell a few years ago I was keen to see what it could do.

I will be going through the process I took to get Warp up and running as this is my first time using a Haskell web server and I had some problems getting it going.

Warp requirements

Before using Warp we need to compile GHC, Haskell Platform, and the Yesod web framework.

The version of Haskell Platform you will download and install is dependent on the version of GHC that you will be using.

Compiling and installing GHC

GHC – The Glasgow Haskell Compiler is first required as this is used to compile our Haskell programs. Straight on the page in the link you will see a list of the different versions of GHC, in my example I am working with version GHC 7.4.1.

On my x86_64 Debian 6 test server I’ve done the below to install GHC into /usr/local/. Note that you will need bzip2 installed in order to extract the file.

tar xfjv ghc-7.4.1-x86_64-unknown-linux.tar.bz2
cd ghc-7.4.1-x86_64-unknown-linux
./configure --prefix=/usr/local/
make install

After a while GHC should compile and be ready in the directory specified.

Compiling and installing the Haskell Platform

The Haskell Platform will give you what you need on the Haskell side of things, including the cabal tool which we will use later to install the Yesod web framework.

I am using the current version of the Haskell Platform, version 2012.2.0.0. You may note that on the page it is saying to use GHC 7.4.1 and I am using 7.4.2, in this instance you will probably get a warning to use the flag --enable-unsupported-ghc-version after ./configure.

tar xf haskell-platform-2012.2.0.0.tar.gz
cd haskell-platform-2012.2.0.0
checking zlib.h usability... no
checking zlib.h presence... no
checking for zlib.h... no
configure: error: The zlib C library is required

This one is easily fixed by installing zlib1g-dev

apt-get install zlib1g-dev
checking for zlib.h... yes
checking for zlibVersion in -lz... yes
checking GL/gl.h usability... no
checking GL/gl.h presence... no
checking for GL/gl.h... no
configure: error: The OpenGL C library is required

Great so zlib is working now but OpenGL is failing, luckily it’s another easy fix.

apt-get install freeglut3-dev
make install

That’s it, the Haskell Platform is all ready to go.

Compiling and installing the Yesod

The Yesod web framework for Haskell is installed through the cabal command line tool.

cabal install yesod

You should now have everything you need, you can test by running “cabal install warp” and it should say that the requested package is already installed.

cabal install warp
Resolving dependencies...
All the requested packages are already installed:
Use --reinstall if you want to reinstall anyway.

Creating a static test page

Now it’s time to create a simple test page which you will be able to view through your browser. Add the following code into test.hs

{-# LANGUAGE OverloadedStrings #-}
import Network.Wai
import Network.Wai.Handler.Warp
import Blaze.ByteString.Builder (fromByteString)
import Network.HTTP.Types (status200)

main = run 3000 $ const $ return $ ResponseBuilder
    [("Content-Type", "text/plain"), ("Content-Length", "4")]
    $ fromByteString "Test"

Now to compile the .hs file and then execute it.

ghc --make test.hs

That’s it, the test will remain running as long as this is executing. If you point your browser to the IP address you set this up on at port 3000 you should see “Test” returned. In my example as I am doing this locally if I browse to localhost at it successfully returns the content.


I had a lot more errors during the first round of trying this, mostly due to the fact that I was using “apt-get install ghc” which only downloads GHC 6.12 from the repository. There was a lot of trial and error to get to the simplified version of this working, I was getting various errors when using cabal to install yesod, namely to do with base-4.X and transformers-base. Starting again from scratch with the newer version of GHC solved this for me.

I intend on doing a brief benchmark on Warp to compare it to some other non Haskell web servers such as Apache and Nginx to get an idea of how Haskell’s best fits in.

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>