You can create programs that the HTTP server uses when a HTTP client connects to the Web site. These programs are referred to as common gateway interface (CGI) scripts. A Web page is static, meaning that once you download a Web page it does not change. This means that the HTTP server cannot interact with the HTTP client in real time. If you have to set up a Web site that has to process data, such as a password, you need to use CGI script. You can write CGI script in Perl, C, and Java. Perl is a popular tool used to create CGI script because it is an interpretive language and therefore does not need to be compiled.
Corel LINUX comes with Perl installed. Perl does not have an integrated environment like other languages, such as C++ or Visual Basic. You can create Perl code in a text editor. You must type the same starting line of code in every Perl program. The purpose of this line is to inform the HTTP server where to locate Perl on the host computer. The first line of all Perl programs must be:
#!/usr/bin/perl
You can use the which command in the Console to find the location of Perl on your computer. You can type the following command in the Console:
which perl
You can save a Perl program by saving the file with a .pl file extension. If you want to save a Perl program as CGI script, you must save it with the .cgi file extension. If you want the HTTP server to execute the .cgi file, you must do three tasks. First, you must save the .cgi file in the directory specified by the ScriptAlias directive. The ScriptAlias directive is defined in the srm.conf file. For information about the ScriptAlias directive, see "Using the srm configuration file." The directory specified in the sample srm.conf file, which was created earlier in this chapter, is /usr/lib/cgi-bin/. The second task you must complete is to change the file permission of the .cgi file. You can change the file permission of a .pl file or a .cgi file the same way because they are both Perl programs. The third task is to call the .cgi file. You can create an event in a Web page and call the .cgi file when the event is called. For example, you can insert a push button into your Web page and call the .cgi file when the user clicks the push button.