Setting up ErlyWeb

Building on the steps in the previous parts of this series, I’ve added ErlyWeb into the equation. ErlyWeb is a web application framework built on Erlang/YAWS which I’ve been reading a bit about recently. As well as the main web site linked above, Yariv Sadan‘s blog is a good source of information.

All I’m documentating at this stage is the initial setup of a skeleton app, which starts with getting and building ErlyWeb:

svn co http://erlyweb.googlecode.com/svn/trunk/ erlyweb
cd erlyweb
mv Emakefile Emakefile.old
sed -e "s*/usr/local/src*/usr/local/lib*" Emakefile.old >Emakefile
make
cd ..

Note that I amended the Erlang makefile to point at the location of my installed YAWS includes from an earlier step. Now, back in the home directory, start Erlang with the following command line:

erl -pa erlyweb/ebin

In the Erlang shell, do this to create the skeleton application:

1> erlyweb:create_app("dj","/home/ciaran").
2> halt().

A ‘dj’ directory was created above with the skeleton ErlyWeb application structure in place. Add two extra files in that directory as follows. Firstly a small Erlang program which runs the app with YAWS in embedded mode – dj.erl. It’s just a slight extension of the embeded YAWS test code from last time:

-module(dj).
-export([start/0]).
 
-include("/usr/local/lib/yaws/include/yaws.hrl").
 
start() ->
    erlyweb:compile("/home/ciaran/dj",[{erlydb_driver, mnesia}]),
    application:start(yaws),
    GC = yaws_config:make_default_gconf(false,"dj"),
    SC = #sconf{port = 8001,
                servername = "ubuntu01",
                listen = {0,0,0,0},
                docroot = "www",
                appmods = [{"/", erlyweb}],
                opaque = [{"appname","dj"}] },
    yaws_api:setconf(GC, [[SC]]).

And secondly a script to compile and start it, called simply dj:

#! /bin/sh
erlc dj.erl
if [ $? -ne 0 ]; then exit; fi;
erl -pa /usr/local/lib/yaws/ebin /home/ciaran/erlyweb/ebin -yaws embedded true -s dj

Now to start things up:

chmod 770 dj
./dj

All being well, hitting port 8001 with a web browser should show the skeleton application, which doesn’t do very much at this stage. The choice of the name ‘dj’ for this first application indicates that I’m planning to replace the back-end of my inexplicable DJ software with this. It’s unlikely to be anything to get excited over, unless you’re me.

  1. Issarlk’s avatar

    Thank you for that article. That script looks handy compared to typing everything.
    I’m a erlang newbie and this’ll help.

    Reply

Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">