Posted on March 11, 2024
by Myoungjin Jeon
Tags: haskell
Install yesod
Install ghcup
Install yesod via stack
> stack new yesod-test yesodweb/postgres
> # change lts version to my needs
> # add more packages
> stack install yesod-bin
Basic Setup 1
✎ package.yaml FIXME
- about main-is
- entry point module for each app
- if the module name is SomeApp.hs main-is becomes SomeApp
- add to ghc-options too
- -main-is SomeApp
- entry point module for each app
- add dependencies
- FIXME HERE
- version 0.0.1 for initial setting
stack.yaml
- change stack resolver something you are using actively. if unsure use lastest lts what ghcup suggest first.
duplicate executable and change the name
- copy sources recursively and change the name on package.yaml copy src to bootstrap-src
Install & setup postgresql
- please have a look at
settings.yml
database:
user: "_env:YESOD_PGUSER:whatsyourfavcoffee"
password: "_env:YESOD_PGPASS:whatsyourfavcoffee"
host: "_env:YESOD_PGHOST:localhost"
port: "_env:YESOD_PGPORT:5432"
# See config/test-settings.yml for an override during tests
database: "_env:YESOD_PGDATABASE:whatsyourfavcoffee"
poolsize: "_env:YESOD_PGPOOLSIZE:10"
please note or change that user, password and database
- add user with password
- create a database
sudo -u postgres psql # execute psql with postgres user
# this is demostrated on Arch Linux <2024-03-11 Mon>
[sudo] password for myoungjin:
psql (16.1)
Type "help" for help.
postgres=#
CREATE USER whatsyourfavcoffee WITH PASSWORD 'whatsyourfavcoffee';
CREATE DATABASE whatsyourfavcoffee;
postgres=# CREATE USER whatsyourfavcoffee WITH PASSWORD 'whatsyourfavcoffee';
CREATE DATABASE whatsyourfavcoffee;
# if you see the two lines below, it is done successfully.
CREATE ROLE
CREATE DATABASE
- give privilege to user there is a important change since version 15.
GRANT ALL PRIVILEGES ON DATABASE whatsyourfavcoffee TO whatsyourfavcoffee;
-- Below is required for 'DB OWNDER' to make any change INSIDE of DB
ALTER DATABASE whatsyourfavcoffee OWNER TO whatsyourfavcoffee;
postgres=# GRANT ALL PRIVILEGES ON DATABASE whatsyourfavcoffee TO whatsyourfavcoffee;
-- Below is required for 'DB OWNDER' to make any change INSIDE of DB
ALTER DATABASE whatsyourfavcoffee OWNER TO whatsyourfavcoffee;
# if you see the two lines below, it's sucessful.
GRANT
ALTER DATABASE
start yesod for the first time with yesod-scaffold-default
stack exec yesod devel
Yesod devel server. Enter 'quit' or hit Ctrl-C to quit.
Application can be accessed at:
http://localhost:3000
https://localhost:3443
If you wish to test https capabilities, you should set the following variable:
export APPROOT=https://localhost:3443
.. snip ..
- if you cannot access first page, touch
Application.hs
(I guess this is sort of bug, but I haven’t found the proper way to improve it)
touch src/Application.hs