Installing Perl CGI in Apache (Windows platform)

How to install perl cgi in Apache webserver:
Download the latest version of ActivePerl from (if it asks you to register, you can just leave the form blank and hit “Continue”).

Get the Windows (x86) MSI version.
My file was named: ActivePerl-
Install Active Perl
On the “Setup” screen (where you choose what features to install — should be about the 2nd or 3rd screen in. 
It is highly recommend that you install perl to a directory like:

In someone else’s words (very good advice) 
If you will be using Perl CGI programs and want to maintain some level of portability between both Linux machines and Windows machines, you will want to install Perl to the same location on your Windows machine that it is on most Linux machines.

For example, on a standard Linux machine, Perl is located at /usr/bin/perl and so every Perl program that I write begins with #!/usr/bin/perl. So, when I install Perl on a Windows machine, instead of installing it in the default location (which is E:\perl for ActivePerl) I install it in C:\usr so that the Perl executable is located at /usr/bin/perl. This allows me to write code on my Windows machine, then move it (without making any changes) to a Linux machine and have it run there. And vice versa. 

[Check] Add Perl to the PATH environment variable
[Check] Create Perl file extension association
The rest should be grayed out and read-only, but if not, leave them unchecked

Activating CGI:

Using Notepad (or other text editor) open
C:\Program Files\Apache2_2\conf\httpd.conf
(also should be start-menu shortcut called “Edit Apache HTTP httpd.conf File“) and search for
Options Indexes FollowSymLinks
(about line 267) when you find it add ExecCGI to the end so it looks like
Options Indexes FollowSymLinks ExecCGI

[OPTIONAL] Enabling CGI in any directory:

If you want to use CGI outside the C:/Program Files/Apache2_2/cgi-bin/ ScriptAliased directory, you will need to uncomment the following line:
#AddHandler cgi-script .cgi
AddHandler cgi-script .cgi (remove the #)
I also added .pl behind .cgi so ‘perl’ extension is also treated as cgi files.

If you will be creating your own cgi-bin, you will want to comment out:
ScriptAlias /cgi-bin/C:/Program Files/Apache2_2/cgi-bin/
so it becomes
#ScriptAlias /cgi-bin/C:/Program Files/Apache2_2/cgi-bin/

Finding your location to perl:
If you do not know where your perl.exe installed to, go to Start -> Search and type in a search for perl.exe
This location is the path to perl you put on the top of all your cgi scripts. If you listened to my advice in the “Install” step, the path should be close to: C:/usr/bin/perl.exe

Some notes  :

For the perl path C:/usr/bin/perl.exe all of these are/were valid.
I prefer the last one because of the Linux <<>> Windows portability.

Testing CGI:
If you if you uncommented (removed the # symbol) the line
AddHandler cgi-script .cgi in step #4, then create a file in your document_root called hello.cgi and put these three lines in it.
(if you did not comment/disable it, put the CGI file in C:/Program Files/Apache2_2/cgi-bin/):

print “Content-type:text/html\n\n”;
print “hello world”;
Restart Apache if it is already running.

Now go to http://localhost/cgi-bin/hello.cgi (or wherever you put the file) and run the script.
If you get a hello world in your browser, CGI is running. If you get a 500 error, go to the last entry in C:/Program Files/Apache2_2/logs/error.log (or the Review Error Log in the start menu) to see exactly what caused this error.

I think this will will help you to run perl on windows platform using apache web server.
I found this useful script at

Connecting MySQL From PHP

Although many of you know how to connect MySQL Server which is Running on your machine (localhost) or to any other server from a PHP Code, but I think I can write a few lines for those who does not know how to do it.

If you are very much new to PHP and wondering about how to install php in your Local machine rather than using a server which costs very much and for the beginners it is not worthful, then you may visit which can guide you through the installation process. I hope it will help you to install Apache (The web server), MySQL (the Database Server) and PHP (Hypertext Preprocessor) the coding language.
Php is very easy to learn. You can buy a small book from WROX (Beginning PHP,MySQL, Apache Web Development or PHP5 or PHP4) and from there you can learn the basic syntax of PHP (which is very much similar to C).

Now I assume that you know a little bit of php and you have installed Apache, Php and Mysql successfully.
[You need to uncomment the line  ;extension=php_mysql.dll by removing the beginnign ; and restart Apache Web server. If it still throwing errors such as php_mysql.dll not found, then you may need to restart the computer also.]
You can find that you MySQL is running perfectly and accessible from PHP from a piece of code

//This a function which shows php information

Save this file as you wish in the Apache s htdocs directory (which is the directory from where you php scripts will run, you can change this also by configuring httpd.conf file in Apcahes conf directory). I prefer to use the name of the file phpinfo.php. Hit this file in the internet explorer like (http://localhost/phpinfo.php) and you will see the informations about installed php on your server. And you can find the MySQL support block from there. If this block is present then you are ready to connect MySQL from php.

So we can start:
1. create a file name conf.php (you can choose other names also)
  put below contents in the file,

   $host = “localhost”; //Host where this database is running.
   $user_name = “user”; //Your MySQL Server’s user name
   $password = “pass”; //Your MySQL Server’s  Password
   $db_name = “test”; //Your MySQL Server’s Database.

  //Now connect
  $link = mysql_connect($host,  $user_name, $password);
        echo “Connection to <b>$host</b> successful”;
       //Now you are connected to MySQL, so choose the databse you want to use
       $is_selected = mysql_select_db($db_name)  ;
       //Check the selection
          echo “Database: $db_name selected successfully”;
         echo “Error selecting database $db_name;
    echo “Error connecting MySQL Server at $host”;


Save this script to your servers document root folder (htdocs) and call this script from Internet Explorer or Mozilla.
If you php-mysql configuration is ok then this script will run without any error.

Also for mysql errors you can change this script to 

   $host = “localhost”; //Host where this database is running.
   $user_name = “user”; //Your MySQL Server’s user name
   $password = “pass”; //Your MySQL Server’s  Password
   $db_name = “test”; //Your MySQL Server’s Database.

  //Now connect
   mysql_connect($host,  $user_name, $password) or die(mysql_error());
  //Now you are connected to MySQL, so choose the databse you want to use
   mysql_select_db($db_name)  or die(mysql_error());
    echo “Database: $db_name selected successfully”;

 In this case if any errors occures in the runtime, it will automatically notify you with the error details thrown by mysql server.