ErlangWeb是一个开源的基于Http协议的应用框架,主要是利用Erlang语言来快速、简洁的建立Web应用程序,不过目前这个框架只支持基于Linux平台上。它的官方站点是http://erlang-web.org/.
以下将介绍从它的网站上下载源代码并且编译,然后利用框架来搭建一个Web应用程序:
一 、下载
从http://wiki.erlang-web.org/Downloading上下载最新版的框架。初次之外,还可以找到以前版本框架,下载到本地后文件是erlangweb-1.4.tar.gz。利用tar解压缩到/otp/路径下。
二 、编译
进入解压缩后的/opt/erlangweb-1.4目录中,在终端输入bin/compile.erl命令进行编译:
root@ubuntu:/otp/erlangweb-1.4# bin/compile.erl
Recompile: lib/eptic-1.4/src/e_session
Recompile: lib/eptic-1.4/src/e_multipart_yaws
Recompile: lib/eptic-1.4/src/e_multipart_inets
lib/eptic-1.4/src/e_multipart_inets.erl:29: Warning: regexp:split/2: the regexp module is deprecated (will be removed in R15A); use the re module instead
lib/eptic-1.4/src/e_multipart_inets.erl:37: Warning: regexp:first_match/2: the regexp module is deprecated (will be removed in R15A); use the re module instead
lib/eptic-1.4/src/e_multipart_inets.erl:39: Warning: regexp:split/2: the regexp module is deprecated (will be removed in R15A); use the re module instead
lib/eptic-1.4/src/e_multipart_inets.erl:41: Warning: regexp:split/2: the regexp module is deprecated (will be removed in R15A); use the re module instead
lib/eptic-1.4/src/e_multipart_inets.erl:57: Warning: regexp:first_match/2: the regexp module is deprecated (will be removed in R15A); use the re module instead
Recompile: lib/eptic-1.4/src/e_mod_yaws
Recompile: lib/eptic-1.4/src/e_mod_inets
Recompile: lib/eptic-1.4/src/e_mod_gen
Recompile: lib/eptic-1.4/src/e_mod_ewgi
Recompile: lib/eptic-1.4/src/e_logger_viewer
Recompile: lib/eptic-1.4/src/e_logger
Recompile: lib/eptic-1.4/src/e_lang
Recompile: lib/eptic-1.4/src/e_json
Recompile: lib/eptic-1.4/src/e_hook
Recompile: lib/eptic-1.4/src/e_file
Recompile: lib/eptic-1.4/src/e_error
Recompile: lib/eptic-1.4/src/e_dispatcher
Recompile: lib/eptic-1.4/src/e_dict
Recompile: lib/eptic-1.4/src/e_db_mnesia
Recompile: lib/eptic-1.4/src/e_db_couchdb
Recompile: lib/eptic-1.4/src/e_db
Recompile: lib/eptic-1.4/src/e_conf
Recompile: lib/eptic-1.4/src/e_component
Recompile: lib/eptic-1.4/src/e_cluster
Recompile: lib/eptic-1.4/src/e_cache_ets
Recompile: lib/eptic-1.4/src/e_cache_disk
Recompile: lib/eptic-1.4/src/e_cache
Recompile: lib/eptic_fe-1.0/src/eptic_fe
Recompile: lib/eptic_fe-1.0/src/e_fe_proxy
Recompile: lib/eptic_fe-1.0/src/e_fe_mod_yaws
Recompile: lib/eptic_fe-1.0/src/e_fe_mod_inets
Recompile: lib/eptic_fe-1.0/src/e_fe_mod_gen
Recompile: lib/eptic_fe-1.0/src/e_fe_gc
Recompile: lib/eptic_fe-1.0/src/e_fe_cluster
Recompile: lib/eptic_fe-1.0/src/e_fe_cache
Recompile: lib/wpart-1.4/src/wtype
Recompile: lib/wpart-1.4/src/wtpl
Recompile: lib/wpart-1.4/src/wpartlib
Recompile: lib/wpart-1.4/src/wpart_xs
Recompile: lib/wpart-1.4/src/wpart_valid
Recompile: lib/wpart-1.4/src/wpart_utils
Recompile: lib/wpart-1.4/src/wpart_master
Recompile: lib/wpart-1.4/src/wpart_gen
Recompile: lib/wpart-1.4/src/wpart_db
Recompile: lib/wpart-1.4/src/wpart_cache
Recompile: lib/wpart-1.4/src/wpart_app
Recompile: lib/wpart-1.4/src/wpart
Recompile: lib/wpart-1.4/src/validate_tool
Recompile: lib/wpart-1.4/src/utf8_api
Recompile: lib/wpart-1.4/src/utf8
Recompile: lib/wpart-1.4/src/erlydtl_expander
Recompile: lib/wparts-1.4/src/wtype_upload
Recompile: lib/wparts-1.4/src/wtype_time
Recompile: lib/wparts-1.4/src/wtype_text
Recompile: lib/wparts-1.4/src/wtype_term
Recompile: lib/wparts-1.4/src/wtype_string
Recompile: lib/wparts-1.4/src/wtype_password
Recompile: lib/wparts-1.4/src/wtype_multilist
Recompile: lib/wparts-1.4/src/wtype_integer
Recompile: lib/wparts-1.4/src/wtype_html
Recompile: lib/wparts-1.4/src/wtype_float
Recompile: lib/wparts-1.4/src/wtype_enum
Recompile: lib/wparts-1.4/src/wtype_datetime
Recompile: lib/wparts-1.4/src/wtype_date
Recompile: lib/wparts-1.4/src/wtype_csv
Recompile: lib/wparts-1.4/src/wtype_collection
Recompile: lib/wparts-1.4/src/wtype_bool
Recompile: lib/wparts-1.4/src/wtype_autocomplete
Recompile: lib/wparts-1.4/src/wtype_atom
Recompile: lib/wparts-1.4/src/wpart_upload
Recompile: lib/wparts-1.4/src/wpart_time
Recompile: lib/wparts-1.4/src/wpart_text
Recompile: lib/wparts-1.4/src/wpart_string
Recompile: lib/wparts-1.4/src/wpart_password
Recompile: lib/wparts-1.4/src/wpart_paginate
Recompile: lib/wparts-1.4/src/wpart_multilist
Recompile: lib/wparts-1.4/src/wpart_lookup
Recompile: lib/wparts-1.4/src/wpart_list
Recompile: lib/wparts-1.4/src/wpart_lang
Recompile: lib/wparts-1.4/src/wpart_integer
Recompile: lib/wparts-1.4/src/wpart_input
Recompile: lib/wparts-1.4/src/wpart_include
Recompile: lib/wparts-1.4/src/wpart_form
Recompile: lib/wparts-1.4/src/wpart_float
Recompile: lib/wparts-1.4/src/wpart_enum
Recompile: lib/wparts-1.4/src/wpart_derived
Recompile: lib/wparts-1.4/src/wpart_datetime
Recompile: lib/wparts-1.4/src/wpart_date
Recompile: lib/wparts-1.4/src/wpart_csv
Recompile: lib/wparts-1.4/src/wpart_comment
Recompile: lib/wparts-1.4/src/wpart_collection
Recompile: lib/wparts-1.4/src/wpart_choose
Recompile: lib/wparts-1.4/src/wpart_bool
Recompile: lib/wparts-1.4/src/wpart_autocomplete
Recompile: lib/wparts-1.4/src/wpart_atom
Recompile: lib/ewgi-0.2/src/ewgi_yaws
Recompile: lib/ewgi-0.2/src/ewgi_test
Recompile: lib/ewgi-0.2/src/ewgi_mochiweb
Recompile: lib/ewgi-0.2/src/ewgi_inets
Recompile: lib/ewgi-0.2/src/ewgi_application
Recompile: lib/ewgi-0.2/src/ewgi_api
Recompile: lib/erlydtl-0.5.3/src/erlydtl/erlydtl_scanner
Recompile: lib/erlydtl-0.5.3/src/erlydtl/erlydtl_runtime
Recompile: lib/erlydtl-0.5.3/src/erlydtl/erlydtl_parser
Recompile: lib/erlydtl-0.5.3/src/erlydtl/erlydtl_filters
Recompile: lib/erlydtl-0.5.3/src/erlydtl/erlydtl_deps
Recompile: lib/erlydtl-0.5.3/src/erlydtl/erlydtl_dateformat
Recompile: lib/erlydtl-0.5.3/src/erlydtl/erlydtl_compiler
Recompile: lib/erlydtl-0.5.3/src/erlydtl/erlydtl
Recompile: lib/ewts-1.0/src/ewts_sup
Recompile: lib/ewts-1.0/src/ewts_dbg
Recompile: lib/ewts-1.0/src/ewts_client
Recompile: lib/ewts-1.0/src/ewts_app
Recompile: lib/ewts-1.0/src/ewts
Recompile: lib/ewts-1.0/src/e_mod_ewts
Compilation completed!
编译完成后,在lib目录下的ebin目录中将会看到编译后的文件。
三 、创建一个Web应用
现在ErlangWeb框架已经编译好了,然后可以利用bin/start这个命令来创建一个新的Web应用了。首先,在我们在需要创建Web应用的路径中新建一个Web应用文件夹,比如/root/www/new_project。然后利用下面的命令创建:
root@ubuntu:~/www/new_project# /otp/erlangweb-1.4/bin/start.erl yaws
Element created: config
Element created: docroot
Element created: log
Element created: pipes
Element created: templates
Element created: bin
Element created: lib
Element created: releases
Element created: releases/0.1
Element created: templates/cache
Element created: docroot/conf
Element created: bin/heart
Element created: bin/to_erl
Element created: bin/run_erl
Element created: bin/start
Element created: bin/stop
Element created: bin/connect
Element created: bin/start_interactive
Element created: bin/start_erl
Element created: releases/start_erl.data
Element created: config/dispatch.conf
Element created: config/errors.conf
Element created: templates/404.html
Element created: templates/501.html
Element created: config/project.conf
Element created: docroot/autocomplete.css
Element created: docroot/indicator.gif
Element created: docroot/jquery.autocomplete.js
Element created: docroot/jquery.js
Element created: templates/welcome.html
Element created: releases/0.1/start.rel
Element created: releases/0.1/start.script
Element created: releases/0.1/start.boot
Element created: config/yaws.conf
Element created: docroot/conf/mime.types
Element created: config/inets.conf
Element created: config/inets_https.conf
Element created: config/ewgi_inets.conf
Element created: config/ewgi_inets_https.conf
Element created: config/errors_description.conf
Element created: releases/0.1/sys.config
Element created: Emakefile
Element created: bin/compile.erl
Element created: bin/add.erl
Element created: bin/generate.erl
Element created: bin/test.erl
Element created: bin/e_component.erl
后面的yaws参数表示我们的这个应用运行在yaws容器中,创建成功后,它将在new_project目录中生成以下文件夹:
四 运行创建的web应用
利用start生成了Web应用之后,还需要编译新创建的Web应用,编译web应用是利用下面的命令行:
root@ubuntu:~/www/new_project# bin/compile.erl
Compilation completed!
编译成功,你我们就可以运行了,输入下面的命令
root@ubuntu:~/www/new_project# bin/start
Starting Erlang Web
Erlang Web已经运行起来了,我们可以在浏览器中输入http://localhost:8080/来检查是否运行成功。如果成功,将会在页面中显示: