How to begin writing an Application Server over Apache? - apache

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.

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.

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

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.

Related

Solution to execute CGI scripts

I have some CGI scripts which are used internal to the organization. Due to some standard changes, the server/system team has commented the below line from httpd.conf (apache config file) that support the CGI scripts. Because of this change, the existing CGI scripts are affected and unable to execute them on browser.
### LoadModule cgid_module modules/mod_cgid.so
Is there a way to overcome this situation and make the scripts work as is.
NOTE : The above commented line cannot be uncommented/enabled.
Ways of circumventing your company's policy, from best to worse:
Load mod_cgi anyway.
Load mod_fcgi, and convert your CGI script into a Fast CGI daemon. It's a lot of work, but you'll can get faster code out of it!
Load your own module that does exactly the same thing as mod_cgi. mod_cgi is open source, so it should be easy to just rename it.
Load mod_fcgi, and write a Fast CGI daemon that executes your script.
Install a second apache web server with mod_cgi enabled. Link to it directly or use mod_proxy on the original server.
Write your own web server. Link to it directly or use mod_proxy on the original server.
Last time you asked this question, you talked about using mod_perl instead. The standard way to run CGI program unchanged (for some value of "unchanged") under mod_perl is by using ModPerl::Registry. Did you try that? How did it go?
Another alternative would be to convert your programs to use PSGI. You could try using Plack::App::Wrap::CGI or CGI::Emulate::PSGI. Using Plack would free you from any deployment restrictions. You could run the code under mod-perl or even as a separate service behind a proxy server.
But I can't help marvelling at how ridiculous this whole situation is. Your company has CGI programs that it (presumably) relies on to run part of its business. And they've just decided to turn off support for them. You need to find out why this decision has been made and try to buy some time in order to convert to an alternative technology.

List of served files in apache

I am doing some reverse engineering on a website.
We are using LAMP stack under CENTOS 5, without any commercial/open source framework (symfony, laravel, etc). Just plain PHP with an in-house framework.
I wonder if there is any way to know which files in the server have been used to produce a request.
For example, let's say I am requesting http://myserver.com/index.php.
Let's assume that 'index.php' calls other PHP scripts (e.g. to connect to the database and retrieve some info), it also includes a couple of other html files, etc
How can I get the list of those accessed files?
I already tried to enable the server-status directive in apache, and although it is working I can't get what I want (I also passed the 'refresh' parameter)
I also used lsof -c httpd, as suggested in other forums, but it is producing a very big output and I can't find what I'm looking for.
I also read the apache logs, but I am only getting the requests that the server handled.
Some other users suggested to add the PHP directives like 'self', but that means I need to know which files I need to modify to include that directive beforehand (which I don't) and which is precisely what I am trying to find out.
Is that actually possible to trace the internal activity of the server and get those file names and locations?
Regards.
Not that I tried this, but it looks like mod_log_config is the answer to my own question

How to execute a script Perl with mozilla with Bitnami LAMP Stack?

I downloaded LAMP Stack from Bitnami web site as Ubuntu VM. I'm not expert, and I've some difficultes. I created a perl script as CGI called prova.cgi : it is a simple hello world. Now I have to execute it using mozilla (in windows), keeping alive the bitnami VM: I write: http://192.168.88.129/opt/bitnami/apache2/cgi-bin/prova.cgi but the result is:
Not Found
The requested URL /opt/bitnami/apache2/cgi-bin/prova.cgi was not found on this server.
Maybe I'm making an error about the location in which my script is supposed to stay: I put it in /opt/bitnami/apache2/cgi-bin/.
Any Suggestion?
Regards, Matteo
"Not Found" means exactly what it says on the tin.
What's going on, is apache is configured with a scripting location - the precise details will be in your httpd.conf. When you access a url of an appropriate type, apache will redirect the request and run the script.
I will guess in this case - you need to fetch http://192.168.88.129/cgi-bin/prova.cgi
But to be sure, you'd need to check your httpd.conf.

Python BaseHTTPServer vs Apache and mod_wsgi

I am setting up a very simple HTTP server for the first time, am considering my options, and would appreciate any feedback on the best way to proceed. My goal is pretty simple: I'm not serving any files, I only need to respond to a very specific HTTP POST request that will contain geolocation data, run some Python code, and return the results as JSON. I do need to be able to respond to multiple simultaneous requests. I would like to use HTTPS.
In looking on stackoverflow it seems I can potentially go with BaseHTTPServer and ThreadingMixIn, or Apache and mod_wsgi. I already have Apache installed, but have never configured it. Are there compelling reasons to go the more complicated Apache route (more complicated to me, because I will need to do research on configuring Apache and getting mod_wsgi going but already have a test instance of BaseHTTPServer up and running), or is it equally safe, secure (very important), and performance-oriented to use BaseHTTPServer for something so simple?
BaseHTTPServer is not a production grade server.
If you don't understand how to set up Apache, but want to get something with mod_wsgi running quickly and easily, then you probably want to look at mod_wsgi express.
This gives you a way of installing mod_wsgi using Python 'pip' and also provides you a way of starting up Apache/mod_wsgi with a auto generated Apache and mod_wsgiconfiguration such that you don't even need to know how to configure Apache.
The next version of mod_wsgi express to be released (version 4.3.0, likely released this week), can even set up a HTTPS site for you, with you just needing to have obtained a valid certificate or generated a self signed certificate.
I would suggest if interested you use the mod_wsgi mailing list to ask for more details about using mod_wsgi express for running a HTTPS site.
http://code.google.com/p/modwsgi/wiki/WhereToGetHelp?tm=6#Asking_Your_Questions
You can start playing around though with it for a normal HTTP site by following instructions at:
https://pypi.python.org/pypi/mod_wsgi

can I write a shell script that can be called from apache as a web service

I have an apache web server running on an AIX box that has Informix SE databases that I'd like to retrieve information from. I'd like to implement a web service that I can use internally and I can write a shell script that can interpret xml and return it with message data but can find no information on how to implement it in apache.
Should this be possible - without php or anything else like, just with ksh?
Thanks,
Brian.
Yes, you can implement a CGI with a very basic Apache configuration (see ScriptAlias in the default confiugration.
A minimal CGI shell script just needs to print a content-type header and followed by a blank line
The request body is available as stdin
Little executables and libraries exist to make CGI shell scripts easier to work with, but often they will not be needed. Plenty of examples for "CGI shell script" on any search engine.