views:

79

answers:

3

For my college project, I want to create a simple application server in C that runs over Apache. Like .php, .asp, .jsp, the extension of my files would be .sas.

I have already written a parser which reads the .sas files and generates the output. For example, consider a file index.sas with the below code:

<%   
echo "Hello";  
%>  

Now, if I execute:

sas index.sas

The result would be:

Hello

Now I want to use this program as an application server over Apache just as PHP, Tomcat, etc. work over Apache. I have heard of cgi-bin but I think PHP uses a different approach. I want to learn the approach which PHP uses.

Please advice.

+1  A: 

You need to write a module utilizing the Apache API.

Some basic documentation with examples can be found here.

http://www.auburn.edu/docs/apache/mod/mod_example.html

Michelle Six
A: 

Little correction: Apache HTTP Server is not required to be able to run Apache Tomcat as webserver. Apache Tomcat is at its own already a full fledged webserver. Your confusion is probably caused by the Tomcat Connector which could be used to connect Apache HTTP Server and Apache Tomcat together to be able to serve PHP/JSP behind one same HTTP port.

As to your actual question, PHP can be installed as CGI module or ASAPI (Apache Server API) module. If you want to program a CGI module for Apache HTTP Server, then you may find this document useful. If you want to write an ASAPI module, then you may find those documentations useful.

BalusC
Hmm... the 1st para sounds interesting, I did not know that! But why did they create a new web server for Tomcat when they already had HTTP server?
Cracker
Why are you creating a new scripting language when there are already so many? ;-)Humor aside, If I remember correctly, the original Tomcat came from Sun and was taken ovrer by Apache Foundation. Wasn't it called JServer or something like that... I could be mistaken, it's been a while.
cjstehno
@Cracker: because it serves an entirely different purpose: a 100% pure Java webserver/servletcontainer so that it can run everywhere without the need to create/distribute/download separate platform-specific (windows, linux, unix, solaris, etc) software. Java is namely platform independent.
BalusC
@cjstehno: http://en.wikipedia.org/wiki/Apache_Tomcat#History
BalusC
@cjstehno: Just for learning purpose...
Cracker
@cjstehno: Oh..ok.. I got your humor now! :D
Cracker
A: 

No, no, no!!! Did I say "no" enough? :)

You don't need to create a new module or look at PHP source code. Talking about re-inventing the wheel using a square boulder.

The easiest thing to do is to use mod_cgi. That is, you use CGI to have Apache forward the request to your SAS interpreter.

[Apache 1.3x] - http://httpd.apache.org/docs/1.3/mod/mod_cgi.html

[Apache 2.0x] - http://httpd.apache.org/docs/2.0/mod/mod_cgi.html

[CGI] - http://en.wikipedia.org/wiki/Common_Gateway_Interface

Now, if you do not want to use CGI (don't know why unless it is expressively forbidden by your homework instructions), then yeah, you will have to create a module. For that take a look at this as an starting point (courtesy of google):

http://threebit.net/tutorials/apache2_modules/tut1/tutorial1.html

Good luck with that, though. It could become labor-intensive.

Hope it helps.

luis.espinal