Search code examples
haskellyesodcloud9-idehaskell-stack

Running Yesod in Cloud9


These are the steps I used to run a Yesod scaffold in Cloud9. The whole process took a few hours and I had to upgrade memory and disk (do this before proceeding):

Installing Stack

  1. sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 575159689BEFB442
  2. (Ubuntu 14.04 (amd64)):
    echo 'deb http://download.fpcomplete.com/ubuntu trusty main'|sudo tee /etc/apt/sources.list.d/fpco.list
  3. sudo apt-get update && sudo apt-get install stack -y

Status: running $ stack from the command line works as expected

Yesod Template Quickstart

  1. Create a new scaffolded site: stack new yesodOnC9 yesod-postgres && cd yesodOnC9
  2. Install the yesod command line tool: stack build yesod-bin cabal-install --install-ghc
  3. Build libraries: stack build

Create PostgreSQL Database in C9

  1. Start the PostgreSQL service $ sudo service postgresql start
  2. Connect to the service $ sudo sudo -u postgres psql
  3. Create a PostgreSQL database (from inside psql, at last step) postgres=# CREATE DATABASE "yesodDB";
  4. Create a test PostgreSQL database postgres=# CREATE DATABASE "yesodDB_test"
  5. Set Password for Postgres User postgres-# \password postgres Enter new password: MYPASSWORD

Result:
user: postgres
password: MYPASSWORD

Configure Yesod to Database

  1. Open config/settings.yml
  2. Change database user to: user: "_env:PGUSER:postgres"
  3. Change database password to: password: "_env:PGPASS:MYPASSWORD"
  4. Change database database to: database: "_env:PGDATABASE:yesodDB"
  5. Close settings.yml and open test-settings.yml
  6. Change database database to: database: yesodDB_test

Launch devel server:

  1. stack exec -- yesod devel -b $IP -p $PORT

Result: Successful, Running Scaffold

If you leave your workspace, you will have to restart the PostgreSQL service with: $ sudo service postgresql start when you return.


Solution

  • Did you configure Postgres to accept TCP connections as indicated by the error message? Your installation of Yesod seems ok, but Yesod reads the DB to make a migration at start time so it needs a connection to your DB.