Erlang tips: starting embeded Yaws server

OS: Ubuntu 9.04

sudo apt-get install yaws

Create some document folder:

mkdir /home/alin/public_html

Add data to an test.html file, in order to be rendered:

echo '<html><body><div>Hello from Yaws!</div></body></html>' > /home/alin/public_html/test.html

erlang module for embedded yaws:

-module(test_yaws).
-export([start/1, stop/0]).

-define(YAWS_LIB,"/usr/lib/erlang/lib/yaws-1.80/ebin"). 

start(Port) ->
    code:add_path(?YAWS_LIB),
    SL=[{listen,{0,0,0,0}},
        {port,Port},
        {servername,"localhost"},
        {flags,[{dir_listings,true},{access_log,false}]}],
    GL=[{trace,false},{tmpdir,"/tmp"},{flags,[{auth_log,false},{copy_errlog,false}]}],
    yaws:start_embedded("/home/alin/public_html", SL, GL).

stop() ->
    code:add_path(?YAWS_LIB),
    yaws:stop().

Start embedded yaws:

$ erl
Erlang R13B (erts-5.7.1) [source] [smp:2:2] [rq:2] [async-threads:0] [kernel-poll:false]

Eshell V5.7.1  (abort with ^G)
1> c(test_yaws).
2> test_yaws:start(5559).
=INFO REPORT==== 24-May-2009::18:28:35 ===
Yaws: Listening to 0.0.0.0:5559 for servers
 - http://localhost:5559 under /home/alin/public_html
ok
3> 

To check if everything is ok, go to: http://localhost:5559/ (listing of public_html folder will be done if no other resource is specified).
If accessing http://localhost:5559/test.html, “Hello from Yaws!” message will be displayed.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.