Friday, April 01, 2011

Install GHC7 and Yesod on Amazon Linux

I've been working lately on a multi-player web game, to actually get to know HTML Canvas (on the client) and Yesod (on the server) properly. I have a first fully functional version of the game, so now is the time to think about hosting. Michael initiated a discussion about it, and in the meantime I decided to investigate Amazon since they offer free instances now on EC2.
The free AMIs (images) come with a version of Linux specific to Amazon, but apparently binary compatible with CentOS, on which GHC and the Haskell Platform have been reported to successfully build.
These are the steps I followed to get everything working, hopefully they can be useful to somebody else. So as per the Amazon Getting Started guide, you connect to your instance with the ec2-user.
First we install through the package manager some useful packages:

sudo yum install make
sudo yum install gcc
sudo yum install zlib-devel
sudo yum install glut
sudo yum install glut-devel

I didn't find gmp, so I downloaded and installed in the default location:

curl -O
tar -xjvf gmp-4.3.2.tar.bz2
cd gmp-4.3.2
sudo make install

But afterwards I had issues building some Haskell packages because it didn't like the default install folder of /usr/local/lib, it preferred /usr/lib, so I did:
sudo cp /usr/local/lib/libgmp.* /usr/lib/
But I suppose ./configure --prefix=/usr/lib/ would be the preferred way to do that.

Libbsd is also required otherwise unix-compat fails:

curl -O
tar -xzvf libbsd-0.2.0.tar.gz
cd libbsd-0.2.0
sudo make install

Then for GHC, I just downloaded the generic binary and installed that. I decided to install Haskell under my home folder.

curl -O
tar -xjvf ghc-7.0.2-i386-unknown-linux.tar.bz2
cd ghc-7.0.2
./configure --prefix=/home/ec2-user/haskell
make install

Make sure we know how to find it:
export PATH=$PATH:/home/ec2-user/haskell/bin

Then get the Haskell Platform source and build that, since there is no binary (yet) for our platform:

curl -O
tar -xzvf haskell-platform-2011.2.0.0.tar.gz
cd haskell-platform-2011.2.0.0
./configure --prefix=/home/ec2-user/haskell
make install

Once you're there, it's back to familiar ground:

cabal update
cabal install yesod

And there we are!! My deployment platform is ready!


thomaschrstnsn said...

Hi. Thanks for the nice guide, worked like a charm for me.

I was able to skip the gmp build from source (gmp and gmp-devel were installable from yum). I also had to install make using yum.

Zoe A Clifford said...

Sadly I ran out of memory while trying to compile (well... link) Haskell Platform (on a 64 bit instance). Setting LDFLAGS to "-no-keep-memory" and it seems to be working. Albeit very very very slowly.
I'll get back to you in a year or two if it fails.

JP Moresmau said...

Thomas, thanks, I've added make to the list of yum, must have done it and forgot about it. I didn't manage to get gmp from yum, though. Funny.
Zoe, I used a 32 bit instance I think, and while it was slow, I didn't run into memory issues.

Andriy Drozdyuk said...

Great post - have you had any developments in this? I.e. any easier way of doing it...

JP Moresmau said...

Er, no, Andriy. I haven't pursued that web project so I'm not using my instance any more. So no better advice, sorry! said...

The ghc distribution has moved to