CGI Setup For RealAug Web Application. The Challenge
I want to be able to test the server side application that I build locally. One option is to compile and run the app straight off the same operating system that I happen to be running, which would allow me quite a bit of control when it comes to debugging and testing. A better way, in my opinion, and the method that I ultimately chose, is to set up a server on a Virtual machine running locally. This post details the steps I took to get FastCGI running on an Apache2 server which sits on Xubuntu which is hosted on a VR machine which lives in my main OS; Windows XP. Windows XP! I hear you gasp. Well, yes, I simply haven’t had the need nor the hardware to upgrade. It runs so sweetly on my 3.5GHz dual core Pentium 4 with 3Gig of RAM, why would I spend chunks of cash to get transparent windows? Code that works well on this old machine will rock the socks off anything even slightly higher spec, so I’m happy to keep working on it.The Steps
First things first, get a virtual machine. I grabbed the latest and free version of Virtualbox from here and ran the install script. On Windows, that’s pretty straightforward and I don’t need to break that down. Next, install Xubuntu on an instance of the virtual machine. Again, a walk-through process. Why Xubuntu? It’s lightweight, feature full and performs well on my spec. The virtual Xubuntu OS easily equals and probably exceeds the performance of its host, which is already pretty good.Now it gets a little more fun/complex/interesting depending on your outlook. If you only want the server on the VM, you can just do apt-get install apache2 from the terminal.
You can now start running CGI scripts right away. But we are interested in FastCGI for its performance purposes. Fortunately, Apache2 comes bundled with mod_fcgi, which needs to be enabled in the config process so that it can spawn your application. FastCGI reduces overhead on the server running your application by keeping persistent processes running rather than firing up new ones for each request. This means your app will need to run in a persistent manner such as within a loop.Configuring
The configuration of FastCGI on Apache2 seems somewhat fragmented and googling for how-to’s turns up instructions for Apache, which is only of marginal help.
Here’s what I did to make it work:
In /etc/apache2/ports.conf make sure the server is listening on the correct port by adding these lines if they are not already there:
NameVirtualHost *:80
Listen 80
In /etc/apache2/mods-available/FastCGI.conf, make sure your CGI scripts and applications are picked up with the desired file extension (.fcgi in this case).
AddHandler FastCGI-script .fcgi
#FastCgiWrapper /user/lib/apache2/suexec
FastCgiIpcDir /var/lib/apache2/fastcgi
This is the only instruction I have in this file, and after going all around the houses figuring out which files to alter the configuration and where they are located, the above ended up working for me.
Of course, you will need the CGI development kit which you can get from the FastCGI website. Once unpacked you’ll have to edit/ lib F CGI/fcgi.cpp to #include then you can do ./configure followed by making. If you are using ubuntu I found it easier to just get the software manager to install the CGI headers into /user/include by installing lib F CGI-dev.Make sure mod_fastcgi.so is installed in /usr/lib/apache2/modules. If it’s not there sudo apt-get install libapache2-mod-fastcgi will get it done.
First things last, we need to get Apache2 to load the FastCGI module. In /etc/apache2/mods-available there need to be two additional files: fcgi.conf and fcgi.load.
Here’s a screenshot showing what my FastCGI.conf file contains:
This will cause any file with a “.fcgi” extension to be treated as a FastCGI application. Bear in mind that the file must be in an ExecCGI enabled directory in order to execute.
The written application then needs to be tailored to FastCGI input and output, I’ll show how this is accomplished in another post.Free Trial, good offerTranslate this PageMetaBlogroll