First CGI program

1. Copy the following program in your UNIX account, save it as hello.cgi. The program look a lot like a perl program.

#!/usr/local/bin/perl -wT
print "Content-type: text/html\n\n";
print qq(<?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE html PUBLIC "-//w3c//DTD XHTML 1.0 Strict//EN"
             "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n);
print qq(<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n);
print qq(<head>\n<title>Hello World</title></head>\n<body>);

print "<h2>Hello World!</h2>";

print "</body>\n</html>\n";

2. chmod 711 hello.cig (so that is it executable by group and others, but not readable by them)

3. open a browser and type it http://www.pic.ucla.edu/~yourPicAccount/hello.cgi (http://www.pic.ucla.edu/~yourPicAccount/some_directory/hello.cgi, depends on where the file is.

4. View source, you can see the source code

<?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE html PUBLIC "-//w3c//DTD XHTML 1.0 Strict//EN"
             "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Hello World</title></head>
<body><h2>Hello World!</h2></body>
</html>