5

I want to make a Web application in Haskell (for example, it could be a blog, forum, or some dynamic web pages), what do I need?

(I know that I need an http server (such as apache or lighttpd). I also know that I should know some Haskell programming.)

How do I get it all to work together? I don't understand the whole package/setup.

Do I need mod_haskell or other modules?

Please can somebody explain to me how apache modules work and how to install them?

Agi Hammerthief
  • 2,114
  • 1
  • 22
  • 38
mono
  • 53
  • 1
  • 3
  • I don't mean to be offensive but this has been written about over and over on the Internet. Do you want to know about Haskell or how to build a server? – Chuck Vose Dec 29 '09 at 16:08
  • no, i want an explantion how all the mod_somthing http-server and programming language, work together? how they are all connect together :-) – mono Dec 29 '09 at 16:10
  • moshe: Your question is quite broad and can be answered in many ways. For example, the mod_php and mod_python modules are *Apache* extension modules, so they work with the Apache stack. There is no mod_haskell that I know of. And all web servers (Apache included) support the Common Gateway Interface (CGI), which is yet another way to do the same thing, although the performance characteristics of CGIs can be very different depending on the language you're working with. In short: to get a useful answer, you need to confine your question either to one language or to one web server. – Daniel Pryden Dec 29 '09 at 16:27
  • i dont want it just in haskell. haskell is just an example of esoteric(sort of) language. anyway, the guy underneath(glenatron) help me :-) – mono Dec 29 '09 at 17:05
  • 2
    I hope this isn't a new trend where people come here and ask for pizza recipes and relationship advice just because they heard that the #haskell folks are helpful. "My wife goes to sleep too early. What shall I do?" -- "Did you try Hoogle?" – yairchu Jan 05 '10 at 16:05
  • @DanielPryden There is a mod_haskell project, although it doesn't seem to be part of the Apache group's projects: http://nixos.org/~eelco/mod_haskell/ – Agi Hammerthief Mar 10 '14 at 20:35

3 Answers3

6

Short anwer to the question on the title: Yes.

See http://hackage.haskell.org/package/cgi

Network.cgi

Simple Library for writing CGI programs. See http://hoohoo.ncsa.uiuc.edu/cgi/interface.html for the CGI specification.

Here is a simple example, including error handling (not that there is much that can go wrong with Hello World)

 import Network.CGI

 cgiMain :: CGI CGIResult
 cgiMain = output "Hello World!"

 main :: IO ()
 main = runCGI (handleErrors cgiMain)

Regarding the integration of the parts.

CGI is a programming protocol and interface between a web server and some external program, communicating thru standard input and output and sharing environment variables.

You need a web server that supports CGI (most do), and you have to configure the server so that for some special requests (for example, URLs with some special file extension) it invokes the CGI program. For Apache web server, see http://httpd.apache.org/docs/2.0/howto/cgi.html

PA.
  • 28,486
  • 9
  • 71
  • 95
  • thanks for the comment, but i dont want it to be with a specific language. i mentiond haskell because it's a bit ezoteric :-). i want to know what are all the mod_somthing, http server and the language, combine together. all the process of make a web app(blog, forum, or just dynamic web pages) is not clear to me :-) – mono Dec 29 '09 at 16:22
  • A slightly bigger example is given here: http://lukeplant.me.uk/blog/posts/ella/ – Long Dec 29 '09 at 16:36
  • @PA. at lighttpd I need to do following for cgi: `[...] ".pl" => "/usr/bin/perl"," [...]` but what executable must I set for the .hs files? – Martin Fischer Apr 28 '16 at 08:20
6

Let us imagine you are creating a dynamic web site in your programming language of choice.

When a user comes to visit your site, they make a request to http://name-of-your-site.com and this is passed to your server.

When the request arrives at port 80, it is collected by your HTTP server, which is probably Apache, but might be LightHttpd or any other HTTP server. That will recieve the request and decide what to do with it.

Now imagining that your site is written in python, it will be stored as a bunch of .py files somewhere and so the request needs to be passed on to the python runtime with instructions for what file to run and where to return the output from that file. This is the role of mod_python - taking requests from the server and handing them to the runtime. Most mods also handle thread pooling - suppose you have twenty requests over a minute, if each gets handed to the python runtime in a simple fashion then you will have twenty python threads all starting up, running together and then dying off as the process is complete. Typically Apache mods will keep a few threads up and running, to save on startup time and just pass new requests to one of the existing threads so that when it has finished one request it gets passed another one by the interface. CGI containers do the same job in a slighly different way, the reason you might choose one over the other is likely to be related to what HTTP server you are using ( mod_python is designed for Apache, for example, something like FastCGI is used more with LightHttpd ) and to performance considerations. If you are using something like FastCGI you would then potentially need a second layer of interface between the CGI Container and the programming language runtime.

So the layers you are working with look a bit like this:

HTTP Server->  CGI Layer          ->  Programming Language Runtime -> your code
Apache     ->  mod_python         ->  Python Runtime               -> index.py
LightHttpd ->  FastCGI+python_cgi ->  Python Runtime               -> index.py 

Obviously, I have used Python as an example here, but you can find equivalent mods and cgi containers for most mainstream languages ( and a lot of esoteric ones ) and the Http stack you are working with will be broadly similar in most cases.

glenatron
  • 11,018
  • 13
  • 64
  • 112
1

Perhaps you may find HAppS useful.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358