Now that your .www directory has
been created and you have set the permissions correctly,
it’s time to create your first Python CGI script. To
do this, enter the following commands at a UNIX prompt:
% cd ~/.www
% pico test-python.cgi
This will call up the pico text editor and allow you to
enter your CGI script. Please note, you can use any text
editor to create the test file, e.g. xemacs, emacs, vi, etc.
Copy and paste the following into pico:
#!/soft/python-2.5-bin/python
import cgi
import cgitb
cgitb.enable() # for troubleshooting
#print header
print "Content-type: text/html"
print
print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
print "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
print "<html>"
print "<head>"
print "<title>Python CGI test</title>"
print "</head>"
print "<body>"
print "<p>Hello, world!</p>"
print "</body>"
print "</html>"
Save this file and exit pico. Then, execute the following
commands to ensure that the file permissions are correct.
% chmod a+x test-python.cgi
% chmod go-w test-python.cgi
Now that your .www directory has
been created and you have set the permissions correctly,
it’s time to create your first Perl CGI script. To do
this, enter the following commands at the UNIX prompt:
% cd ~/.www
% pico test-perl.cgi
This will call up the pico text editor and allow you to
enter your CGI script. Please note, you can use any text
editor to create the test file, e.g. xemacs, emacs, vi, etc.
Copy and paste the following into pico:
#!/soft/perl5.8.7-bin/perl -w
use CGI;
$cgi = new CGI();
print $cgi->header();
print '<?xml version="1.0" encoding="UTF-8"?>';
print '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Perl CGI test</title>
</head>
<body>';
print '
<p>
Hello world!
</p>';
print '
print '
</body>
</html>
';
Save this file and exit pico. Then, execute the following
commands to ensure that the file permissions are correct.
% chmod a+x test-perl.cgi
% chmod go-w test-perl.cgi