7.3. A First CGI Program
CGI using Perl is straightforward. If you can write a Perl program to print “hello, world!” you’re halfway there. So, to be consistent with previous first examples (and because we haven’t chanted the mantra in a while), let’s start with “hello, world!”. Change to the proper directory that contains the server’s CGI programs:
$ cd /var/www/cgi-bin
Create the file hello.cgi, which contains the following text: [2]
[2] The file extension is a matter of style (or lack thereof); we use .cgi for the CGI programs in this book. Another logical option might be the .pl extension, because the program is Perl, but we’ll maintain a somewhat artificial distinction between plain-Jane Perl scripts and CGI web scripts.
#!/usr/bin/perl ...
Get Open Source Web Development with LAMP: Using Linux, Apache, MySQL, Perl, and PHP now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.