Installing Haskell Snap web framework in Homestead, Vagrant

Whole process of installing is not difficult compare to others language and framework. Every information needed is almost written in reference in clearly way. Even though I came across with the problem, it is not really a big deal and can be easily solved by apt-get. In this article, I am going to share my experience on how I installed snap into my Homestead.


  • Installing Haskell 7.8.3 in Homestead
  • Installing Snap by Cabal
  • Make http://localhost:8080 work in Mac browser
  • Run Snap Server

Installing Haskell 7.8.3 in Homestead

Document is clear enough, there are three installing methods, community-supported version, Generic Linux binary and build from source. I choose Generic Linux binary. Here’s how I installed it.

sudo apt-get install libgmp3c2 freeglut3 freeglut3-dev -y
sudo mv haskell-platform-2014.2.0.0-unknown-linux-x86_64.tar.gz /temp_haskell.tar.gz
cd /
sudo tar xvf temp_haskell.tar.gz
sudo /usr/local/haskell/ghc-7.8.3-x86-64/bin/activate-hs

As libgmp3 is not installed in my Homestead, I tried to install it by apt-get install.

If you are using Ubuntu 14.04, it is even more simple to installed by.

sudo apt-get install haskell-platform

You can checked if it is worked by ghci command. Simple right!

Installing Snap by Cabal

Snap is even more easier if you are using Cabal to install. Before install snap, cabal ask me to update cabal-install. Then only I install snap by Cabal.

cabal update
cabal install cabal-install
cabal install snap --force-reinstalls

Install is done. I checked if it is worked by create a new snap project.

mkdir pizzahouse
cd pizzahouse
~/.cabal/bin/snap init

If there is file are generated, it means Snap is installed. Yeah!

スクリーンショット 2014-10-27 午前1.56.14

Make http://localhost:8080 work in Mac browser

This is the most troublesome part of the whole work.First, I have to create a new virtual host in nginx and proxy port 8080 used by Snap to port 80.

Inside folder /etc/nginx/sites-available, I created a new virtual host file named “localhost” and wrote following code.

server {
    listen 80;
    server_name localhost;
    root /home/vagrant/Code/haskell;

    charset utf-8;
    access_log off;
    error_log  /var/log/nginx/localhost-error.log error;

    try_files $uri/index.html $uri @app;

    location @app {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;

    location ~ /\.ht {
        deny all;

Then, symlink sites-available/localhost file and sites-enabled/localhost file.

ln -s /etc/nginx/sites-availble/localhost /etc/nginx/sites-enabled/localhost

After configuration and symlink is finished, I restarted nginx.

Run Snap Server

Compile the file and start the server at port 8080. Then, every things worked like magic, http://localhost:8080 is working in local browser.

cabal install
~/.cabal/bin/pizzahouse -p 8080

Thank you for reading.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s