Friday 24 June 2011

HTTP/HTTPS -- Deploy a basic CGI application

This is actually a surprisingly easy objective to achieve. Create a script in the /var/www/cgi-bin directory, like this and call it uptime.cgi:
#!/bin/bash
echo "Content-type: text/html"
echo ""
echo "Uptime is:  $(uptime)"
If you move/copy the script from a different directory or you use a different directory, the SELinux context is likely to be wrong and will need to be changed, so bear that in mind.

Make the script executable:
chmod +x uptime.cgi
You can now test your new cgi script with:
elinks 127.0.0.1/cgi-bin/uptime.cgi
You might want to add the following directives to a different directory to enable script execution and allow other script extensions.
Directory Options +ExecCGI 
AddHandler cgi-script pl cgi
Note that the . before the file extension is not needed and that the extensions are case insensitive.

No comments:

Post a Comment