Recently I setup a server on my local machine for Perl CGI. At first, I thought it would be complicated installing Apache server on Windows but later I found it pretty simple. There are steps to follow and a few tweaks required to spin the CGI server using Bitnami.
Setup Apache server
You can download Bitnami from there website for free. They also have some pre-configured apps, which are good to create a testing environment. some famous apps they have are WordPress blog, PHPBB forum, Tomcat, Moodle, Django, Ruby on Rails etc. To see them all visit their app store.
- After you have downloaded the bitnami Wamp software. Install the software on your windows machine with default settings.
- Now step two is installing the Perl. You can download and install Active Perl with default settings in C:\perl
- If you have all CGI code written in a different environment than windows, you probably will see #!/usr/local/bin/perl on the top of the page in the first line. This line is called shebang. This line tells the machine, what to do with the file when it is executed (ie it tells it to run the file through Perl if you give Perl interpreter path). For windows it will be c:\perl\bin if you have installed the Perl in c:\perl directory. You can also customize the path if you want to.
Setting up Perl interpreter path
Find out the path to the Perl interpreter. If you have installed Active Perl, the default path is usually c:\perl\bin. In case you have installed strawberry Perl, the path to the executable is C:\strawberry\perl\bin\perl.exe.
Run the following commands to setup your interpreter path for Perl.
- Open command promot as administrator and go to the root directory.
- Create the symbolic link using mklink /D command. Example mklink /D usr C:\perl. Now every time you execute your per file, Shebang will search for your Perl interpreter in usr/bin folder which is pointing to c:\perl/bi
- Another way to configure Perl path is byconfiguring your http.conf. Add ScriptInterpreterSource Registry-Strict and setup registry key in windows registry: Windows Registry Editor Version 5.00
To check you have successfully installed configured the Perl. Open the command prompt and run Perl -v and it should show the version of Perl you have installed.
Configuring CGI server
Now you have to configure your server to honor cgi and Perl files.
Open httpd.conf, look for the line that says “Options Indexes FollowSymLinks”
Options Indexes FollowSymLinks (search for this) Options Indexes FollowSymLinks Includes ExecCGI (change to this)
Now look for the line “AddHandler cgi-script .cgi“, this line is commented out. You need to enable this by un-comment this line, to do that remove the # character at the beginning of this line. This will add a handler for files with .cgi extension. If you want to use .pl file extension in your server, add “AddHandler cgi-script .pl” just below the above line. Now you will be able to execute CGI and Perl script with .cgi and .pl, extension.
Lines to add
AddHandler cgi-script .cgi AddHandler cgi-script .pl
You are done here and ready to run perl files on your local.
Debugging WAMP apache
Sometimes it is impossible to restart the Apache server. When you go to services to restart Apache server it shows “Error 1053: The service did not respond ot the start or control request in a timely fashion”. Most of the time its because port 80 is not free. If you are running Skype or any similar software which runs on port 80. To check what program is using port 80 you can run
netstat -a -b in command prompt.
Windows could not start the wampapache service on Local Computer. Error 1053: The service did not respond ot the start or control request in a timely fashion.
Step 1. Open command prompt in administrator mode
Step 2. Go to your apache / bin folder
Step 3. Type
httpd.exe -e debug in command prompt and you can see all the errors.
Installing Active Perl
Alternatively, you can install Active Perl on your machine. You can follow the tutorial below: