Configuring Erlyweb with postgres
I had a hard time getting postgres to work with Erlyweb but finally got it working with help from people on the erlyweb mailing list and IRC. So for all the Erlyweb noobs out there, here’s a step by step configuration guide for configuring Erlyweb with postgres as the database.
1. pg_hba.conf:
Configure your database to use MD5 for authentication. The Erlyweb postgres driver connects to the database using a MD5 connection. So your pg_hba.conf should contain the following line:
# TYPE DATABASE USER CIDR-ADDRESS METHOD
host <db name> <user> 127.0.0.1/32 md5
My pg_hba.conf looks like this:
# TYPE DATABASE USER CIDR-ADDRESS METHOD
host erlytest abhi 127.0.0.1/32 md5
The above line instructs postgres to allow local connections to the database named ‘erlytest’ for the postgres user ‘abhi’ using a md5 encrypted connection.
Note that the order that the rule appears is important. Refer postgres documentation for more information.
Restart the postgres service for the new changes to take effect.
2. psql.app
Create a file named psql.app in the ‘ebin’ directory of your Erlyweb application. The file should look something like this:
{application, psql, [{description, "application description"},
{vsn, "0.0.2"},
{modules, []},
{registered, [psql_sup]},
{applications, [kernel, stdlib]},
{mod, {psql, []}},
{env, [{erlydb_psql, {"localhost", 5432, "<postgres username>", "<password>", "<dbname>"}},
{pools, [{erlydb_psql, 1}]}]}]}.
3. Code Path
Add ‘ebin’ to your erlang code path in erl using:
code:add_path("/path/to/erlywebapp/ebin/").
4. Start yaws in interactive mode:
sudo yaws -i
5. Connect to postgres database:
application:start(psql).
6. Compile your application in yaws REPL:
erlyweb:compile("/path/to/erlyweb/app/", [{erlydb_driver, psql}]).
… and thats about it. Happy hacking!
Loading...