PERL/CGI Script Support

What do I need to know about PERL/CGI?

A PERL is a general purpose programming language that can be used for a variety of tasks such as text file information extraction, conversion of a text file into another format as well as printing out reports. However, PERL has a lot of other significant uses including systems programming. Actually, the term PERL typically represents how useful it is as PERL stands for Practical Extraction and Reporting Language. Some PERL features are borrowed from other programming languages such as C, Shell Scripting and AWK. It is widely popular because of its ability to provide powerful text processing facilities but without the lengthy command-line tools that are employed by most Unix-based languages. This PERL feature allows clients to easily manipulate text files which would have been time-consuming with other languages. PERL’s parsing abilities also helps make it more popular especially as a CGI scripting language.
A CGI or a Common Gateway Interface is a program, more specifically, a set of standards that define how information is to be exchanged between the web server and a custom script. A CGI could be written in Perl, C, Java or Visual Basic, reason why PERL’s parsing abilities make it one of the popular CGI scripts. Often, CGI is used to generate dynamic content on web pages and applications and are so designed to accept and return any data that conforms to CGI specifications. Web servers usually use CGI programs to dynamically interact with their users.
PERL/CGI script then, using both descriptions, is a program that is written in PERL and that defines the how the exchange of information between the server and the custom script should behave.

How does PERL/CGI work?

This is what usually happens when you click the hyperlink or a URL of a particular webpage in your browser: first, the browser contacts the HTP web server and demands for the URL; then, the web server will parse the URL and looks for the filename you requested. If found, the server sends it back to your browser but if not, the server sends an error message indicating that the wrong file was requested. The browser then accepts the server response and displays the file, if found, or the error message, whichever is applicable.
However, it would be possible to setup the HTTP server to execute the request as a program instead of just sending the file back to the browser. This request execution setup is called the Common Gateway Interface or CGI. CGI’s written in PERL script is known as PERL/CGI script.
Basically, CGI works by allowing web servers to simply let a scripting program or an executable program create a dynamic page behind the scenes. A dynamic page is a page that serves dynamic content that is created according to a set of conditions that are usually user-inputs like inputs from forms that are filled out in the web. Take this as an example: the information that you filled-out on a form in a web site, once submitted by clicking the “sent” button, is processed behind the scenes by a program, usually Perl, that checks your information for errors and even connect to a data base for data storage. It can even generate an error page to allow the user to fix errors in his entry or a Thank You page if everything went well.

How can I have PERL/CGI Script support on my Apache Web Server on Windows?

It is quite easy to add PERL/CGI Script support for your Apache Web Servers on Windows; all you have to do is to follow the following procedure:

  •  First, you need to download PERL on your system. You can get a free Windows version of PERL from any of the sources that are listed on the Free Perl Executables page of the web site.
  •  After downloading the file, you need install the PERL program into your computer by simply following the on-screen instructions.
  •  After installing the PERL, you need to configure Apache running PERL Scripts in a CGI Directory, which makes Apache treat any file in a particular directory – usually called cgi-bin – as a CGI script. To enable PERL/CGI support, you need to do the following:
  •  Look for the “httpd.conf” file in the “conf” directory of your Apache folder. For those who use default directory, the file would be “c:\Program Files\Apache Group\Apache\conf\httpd.conf”;
  •  Open the file and look for the line

ScriptAlias /cgi-bin/”C:/Program Files/Apache Group/cgi-bin/”;

  •  See if the line has a hash mark (#) before it which means that it is commented out.
  •  Simply remove the hash (#) character to enable it. Un-commenting it out means that your Apache is already configured to run PERL/CGI scripts in that directory.

Can I make the PERL/CGI script my default page?

Yes, you can and may choose your PERL/CGI script to execute as the default page for your directory. To do this, you need to add a line to the Apache configuration file, the httpf.conf.:

  •  First lock of the line within the files that begins with “DirectIndex” and you need to manually add the file “index.cgi” to the list of files that are located on the line. As an example; the line “DirectoryIndex index.html” should be changed into this form after the line is added; “DirectoryIndex index.cgi index.html”;
  •  Having done this, you should have enabled PERL/CGI script to be your default page. So the next time you access http://localhost/ or http://localhost/directory/ without any specified filename, Apache should run the “index.cgi”.

      Web Hosting Plan Guide