Install, Setup and Configure CGI and Perl in Windows XP

Prerequisite

Obvioulsy, a web server needs to be running on the Windows machine. Refer to this post for instructions on how to install Apache2 in Windows.

Download ActivePerl

Download ActivePerl from http://www.activestate.com/Products/ActivePerl/?mp=1. Click on Free Download to start the download process. There is no need to input any contact info. Just leave it blank and press ‘Next’ to start the download.

Then download the lastest version of Windows MSI package.

Install ActivePerl

Start the installation by double clicking the setup file. Follows the on-screen instruction. If you will be using Perl CGI programs and want to maintain some level of portability between both Linux machines and Windows machines, you may want to install Perl at the same location on your Windows machine as it is on most Linux machines.

For example, on Linux machine, Perl is located at /usr/bin/perl and so every Perl program that I write begins with #!/usr/bin/perl. So, it’s best when install Perl on an Windows machine, instead of installing it in the default location (i.e. C:\perl), install it in C:\usr instead, so that the Perl executable is located at /usr/bin/perl. This allows codes written on Windows machine been moved to, without changes, to Linux machine, and have it run there, and vice versa.

To change the installation path, click on browse button when you’re on the installation screen that prompts you to select which features you want to install. Set it to C:\usr\ if needed.

Make sure that the following options is checked (selected):
Add Perl to the PATH environment variable
Create Perl file extension association

Activating CGI

Open the httpd.conf file for editing by selecting Start > Programs > Apache HTTP Server > Configure Apache Server > Edit the Apache httpd.conf Configuration File. Alternatively, open the httpd.conf with any text editor.

In the main directory section, search for Options Indexes FollowSymLinks (at about line 267), and add ExecCGI to the end so it looks like:

Options Indexes FollowSymLinks ExecCGI

Search for the following line and remove the hash mark character (#) to uncomment this line. (You can also change .cgi to .pl, or add .pl behind .cgi if you prefer that perl extention is also treated as cgi files) For example:

#AddHandler cgi-script .cgi

Should look like:

AddHandler cgi-script .cgi .pl
or
AddHandler cgi-script .pl
or
AddHandler cgi-script .cgi

Save the httpd.conf configuration file, restart the Apache server. Test the configuration as described in Testing Your Web Server CGI Configuration at the end of this article.

Optional: Enabling CGI in Any Directory

If you want to use CGI outside ScriptAliased directory (ScriptAlias is usually the Apache2/cgi-bin/), comment out the following line:

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

Should look like:

#ScriptAlias /cgi-bin/ “C:/Program Files/Apache Group/Apache2/cgi-bin/”

Alternatively, if you want to specify just one directory to put all your cgi programs, change the path instead, but makes ure that directory exists.

Should look like (for default settings):

ScriptAlias /cgi-bin/ “your_prefer_cgi-bin_direcotry”

Save the httpd.conf file. Restart the Apache server.

Finding Perl Executable Location

If you don’t know where is perl.exe installed to, go to Start -> Search and search for perl.exe. This location is the path to the perl executable that has to be put on the top of all cgi scripts. If you follow default installation procedure, the path should be C:/perl/bin/perl.exe

For the path to perl.exe path, all of these format are valid:
#!c:/perl/bin/perl.exe
#!c:/perl/bin/perl
#!/perl/bin/perl.exe
#!/perl/bin/perl

Testing Your Web Server CGI Configuration

Save the following test script in your DocumentRoot directory (if you have uncomment ScriptAlias, you can put it anywhere inside your DocumentRoot directory, or if you have set ScriptAlias to some particular directory, put the cgi in that directory only, i.e Apache2/cgi-bin) as test.pl or test.cgi (depending on your configuration of the AddHandler line) and modify the first line as required to point to your ActivePerl interpreter:

#!c:\perl\bin\perl.exe
# ^^^ this must be the first line of the script! ^^^
# start code

use strict;
use CGI;
my $q = new CGI;

# print header and start the markup output

print $q->header( “text/html” ),$q->start_html( “hello from perl cgi!” );
print $q->h2(”hello dave…”);
print $q->end_html;
# end code

Now go to http://localhost/cgi-bin/test.cgi (scripts in Apache2/cgi-bin/ are read as http://localhost/cgi-bin/ by default). You should see a page that displays a level two heading with the following text:

hello dave

If you see the above message, CGI is running. If you get a 500 error, go to the last entry in your Apache2/logs/error.log (or the Review Error Log in the Start menu) to see exactly what caused this error.


10 Responses to “Install, Setup and Configure CGI and Perl in Windows XP”

  1. sundeep
    August 30th, 2009 19:47
    10

    I followed your steps but the browser does not give the page in HTML format, it displays a plain text file with HTML tags..Can U help?
    Thank you in advance.

  2. XXC
    May 21st, 2009 18:21
    9

    Yep, Error 500 here also, I looked at the error logs and indeed there is an error, well so how do we resolve the 500 error??

    You left us high and dry with this article…

  3. Lincolemberg Canuto Lima
    October 15th, 2008 05:14
    8

    Salve galera,

    vim trazer a cura de tantas pessoas que quando vão instalar o PERL com APACHE se deparam com uma mensagem de erro do APACHE (500 Internal Server Error)…

    É simples, quando nós copiamos o conteúdo do arquivo test.cgi não notamos as “aspas” que contem cada linhas… basta apenas redigir todas as aspas do arquivo TEST.CGI (sem copiar).. vocês perceberam que o tipo de aspa irá mudar quando for redigida.. Fora isso não há secredo. Façam todos os passos deste belo artigo com este detalha..

    :)

    vlz!!!

  4. gael
    September 30th, 2008 23:42
    7

    Thanks a lot !

    BTW, the error 5OO is thrown by the server if the quotes are not replaced by standard one line 11…

    Otherwise everythings works fine.

  5. Munir
    November 28th, 2007 22:14
    6

    I did everything you said. But cgi is still not running. Please help.
    my apache is 2.2

  6. Johanna
    October 8th, 2007 23:05
    5

    Hi all,

    I really need some help on this subject =)

    I have followed the steps above, and changed the quotation marks, and what I get is 9 error messages:

    Backslash found where operator expected at Z.\test.cgi line 1, near “rtf1\”
    or …. , near “ansi\”
    or …. , near “deff0″
    or …. , near “f1\”
    etc..

    I am a total rookie with these things, any help appreciated =)

    Thanks,

    Johanna

  7. Mitchell
    June 20th, 2007 08:09
    4

    Just for the record, the above test script throws a 500 error when used as is. Maybe it is just a problem with firefox displaying text or something, but the quotation marks are mixed up, so that could lead to problems :)

  8. jack
    May 10th, 2007 19:25
    3

    Cool4you,guys.

  9. Besart
    July 25th, 2006 20:53
    2

    I have installed cgi and configured apache as you said, but i got this erro:

    Internal Server Error
    The server encountered an internal error or misconfiguration and was unable to complete your request.

    Please contact the server administrator, webmaster@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

    More information about this error may be available in the server error log.

    ——————————————————————————–

    Apache/2.0.58 (Win32) PHP/5.1.4 Server at localhost Port 80

  10. Install AWStats- Free Logfile Analyzer for Site Statistics » My Digital Life
    January 2nd, 2006 02:19
    1

    [...] As AWStats is Perl based, a Perl Interpreter need to be installed first to take anvantage of AWStats. For instruction on how to install Perl in Windows machine, check out this article. [...]

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe to comments feature has been disabled. To receive notification of latest comments posted, subscribe to My Digital Life Comments RSS feed or register to receive new comments in daily email digest.
Custom Search

New Articles

Incoming Search Terms for the Article

perl.exe download - install perl on windows xp - download perl.exe - perl setup - perl setup for windows - perl interpreter for windows xp - perl download for windows xp - xampp perl cgi - setup perl - xampp perl path - apache perl setup - download perl exe - xampp path to perl - xampp cgi perl - Cgi/perl setup installation - how to configure cgi in windows - download perl setup - perl windows xp - how to install perl on windows XP - installin perl in xp - perl for windows xp - xampp cgi enable - perl on windows xp - perl cgi apache2 - xampp enable cgi - perl exe download - xampp install perl - test perl on xp - perl for XP download - configure cgi - download perl for windows xp - perl configuration file - cgi perl setup - perl for windows XP download - perl interpreter free download - enable cgi in xampp - how to install perl on xp - how to configure cgi - perl path xampp - how to configure perl in windows - configure perl on windows - installing perl on windows xp - perl for xp download - perl for xp - configure apche to work with strawberry perl - how to run cgi program in windows xp - installed perl. how to configure perl in windows - perl windows download free interpreter - configuring perl on windows xp - config cgi windows -