tags:

views:

348

answers:

3

if i want to make a web application, 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(apache, lighttpd). i know that i should know some programming language to develop this web app.

but how it all combine? can i develop in any (exotic) programming language? for example, can i develop a blog using haskell?

what is mod_python or mod_php? is it for the http server?

i don't understand the whole packege. how the http server is connected to the mod(php,python, etc') or cgi or fastcfi or scgi? how my application will know it will be a web app, and it need a connection with http server? and because i talked on haskell, do i need mod_haskell or other mod? please arrange my mind with all this parts :-).

+1  A: 

Perhaps you may find HAppS useful.

Ignacio Vazquez-Abrams
HAppS is orphaned you should use http://happstack.com instead
hiena
+2  A: 

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
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 :-)
moshe
A slightly bigger example is given here: http://lukeplant.me.uk/blog/posts/ella/
Long
+3  A: 

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
thanks a lot manit absolutely help to clear some things up :-)
moshe