What is PERL / CGI?

Perl is a programming language that is often used for systems programming. Its tools are also used for a wide number of tasks and for solving a lot of complicated problems. One of its typical uses is to extract information from a text file and have a report printed out. It is also often used to convert text files into another form. Perl scripts are programs written in Perl while the program for executing these scripts is called Perl program.

CGI or Common Gateway Interface is a program that could be written in C, Perl, Java or Visual Basic, which is used to generate dynamic content on web pages and applications. Such program is designed to accept and return any data that conforms to CGI specifications. Web servers usually use CGI programs to dynamically interact with their users.

How does CGI work and what is its connection to Perl?

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.

Summarily, a CGI script is a special functionality program, often a Perl script, which executes the data dynamically and outputs the final result into your browser to display.

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

Yes, you can have PERL/CGI Script support on your Apache web server on Windows. First, you need to install PERL if you want to run PERL scripts. 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 thefreecountry.com 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. Being uncommented out means that your Apache is already configured to run CGI scripts in that directory.

Can I run CGI scripts anywhere in my domain?

You may run CGI scripts anywhere in your domain by simply doing the following:

  • Look for the “httpd.conf” file and add the following line to it:
    AddHandler cgi-script .cgi
  • Examine if the line is commented out and remove the hash mark (#) to enable CGI scripts in your domain.
  • Should you want to make the .pl extension recognized as a CGI script too, simply add the .pl to the line, which should now become
    AddHandler cge-script .cgi .pl
  • Next, look for the “Directory”, which typically should look something like thisOptions FollowSymLinks
    AllowOverride None

    then add “+ExecCGI” to the options list, which should now look like
    Options FollowSymLink +ExecCGI

  • You should now be able to run CGI scripts anywhere on your domain.