Continuing with my project work on Crossbow, the Libraries were almost completed and its the time to be thinking about a GUI, web based one to be more specific.
After a lot of R&D work(which was basically asking my mentors) I decided to use CGI.
1.I was writing it in Perl, studied it quite well.
2.We intend to use Webrick, a server written in Ruby and it as a built in class for CGI!!!
Although the preludes were cleared, like they say when you get to work is when you get to work,Really!!
As obvious I was using Apache(ok…. ok for the time being thats all)
Since I faced issues setting up Apache2 to run my CGI programs ,I thought it will be a good idea to invest some time blogging about it…
Baby steps include…
First of all start Apache…Quite easy ,
#/usr/ apache2/2.2/bin/apachectl start (This starts the server,Thats it.)
This is the tricky part(well actually very trivial unless you dont know what your doing and just go by some config book which is very very subjective to the author).
http://locahost (Ran this in the browser to see that I had a Internal server error,I will cut out the remaining description and get to the point)
First check your /etc/hosts file,you will see an entry like this(mine)
192.168.1.5 Harivayu Harivayu-nge0 # Added by inetmenu
will give you a complete description about how to interpret this file…
The first entry is the IP addr your using, the next is the Hostname ,finally comes the nick-name,
Comments are denoted by #
Here you can see that localhost is not listed…So either you add an entry for the localhost(If you insist to use localhost) or use the Hostname already defined, in my case its Harivayu
Then “It works”!!!!!!!
Now to tweak apache settings to accept CGI programs..
open up /etc/apache2/2.2/httpd.conf (The apache config file)
You will find an entry that reads
ScriptAlias /cgi-bin/ “/var/apache2/2.2/cgi-bin/”
Meaning, “cgi-bin” is Aliased to the actual path “var/apache2/2.2/cgi-bin/”
So according you will have to place all your .cgi programs in the above mentioned dir for it to work…
Or else you can specify your own dir just change the ScriptAlias to desired dir!(Why bother dude?, Sys admins are not allowed to comment here!!
THE MOST IMPORTANT ONE,
Check the permissions, its very easy to over look this aspect of any CGI program and think about all the other issues,while the answer is very trivial….
ENSURE you have set the permissions for your .cgi file precisely…..
Its always advisable to use “-w” option while specifying your interpreter,
As a check to see if your program is correct, when you run it in command line, “-w” will throw up any syntax warnings or errors ,so it can be resolved easily.
Thats it! your good to go!!!
So place the script in /var/apache2/2.2/cgi-bin
- launch the browser, execute [http://yourhostname/cgi-bin/file.cgi
- Rejoice the Results….(of course the program should be correct)