Well, installing Perl (x64) on my Windows 2012 IIS8 server should have been easy peasy , but in classic fashion after bleeding out the eyeballs and working throughout the night and hours of frustration I can now at least say I’ve got it working – YAY!!!

I’m using Windows Server 2012 with IIS8 and ActiveState Perl (x64) it’s Perl version 5.16.3 which I downloaded from the ActiveState website here. Once the download is complete just double click and install it, It’s an .msi file which it fine.

The actual filename is ActivePerl-

A few more things.

So will that be Perl working now? No not yet. The next thing you need to do is to create a file association in IIS8 so it will know what to do with file extensions of the types .pl and .cgi.

Bring up the IIS8 interface and Select (highlight) your computers name. Among all the icons in the window on the right, there is one with the title ‘Handler Mappings‘. This is what we’ll use to make our file associations.

In the Actions window on the far right of the screen there are a few links you can select. We want the one that says “Add Script Map…” double click on that and we’ll get a new window.

On the window that comes up you can see just above the ‘Open’ button and the ‘Cancel’ there’s a dropdown selector that will say (*.dll) – We don’t want that, so click and select (*.exe) instead. You will now see a list of the .exe files that are in that folder. Double click on Perl.exe

The Add Script Map window will now have the ‘Executable’ text box with C:\Perl64\bin\perl.exe. We need to add to this the following “%s” %s and then also give this file association a ‘Name’ ie Perl-pl for the .pl extension so it should like this.


Next click on the button that says “Request Restrictions…” The first tab says ‘Mapping’ there is a checked tick box that says Invoke handler only if request is mapped to: and file is selected. This is fine and there is nothing we need to do here.

Select the Tab that says: Verbs. Here we need to select the radio button that says “One of the following verbs:” and in the box underneath type the following. GET,HEAD,POST all in capitals with no spaces between the comma’s.

Just for the sake of completeness the last Tab says Access and the ‘Script’ radio button is selected – This is fine and again there is nothing else for us to do here.

Click OK and again, and you will see a box pop up that has the following:



Ok, now go back to the top and do exactly the same thing, only this time for the extension .cgi instead of .pl.

When you’ve done this – Restart IIS.

Testing your Perl installation.

I created a folder off the root of my domain called ‘cgi-bin’ this is quite standard practise. It is also possible to have a .cgi or .pl file running from any directory on your website. Personally I like to have all my things in one place, but just so that you know you can do this if you wish.

Testing a Perl file.

use CGI::Carp qw( fatalsToBrowser );
print "Content-type: text/html\n\n";
print "<html><head><title>Test Page</title></head><body>";
print "Greetings Earthling!";
print "</body></html>";

You can cut and paste the lines above and save it to a file called ‘test.pl’ in your cgi-bin directory. Now we’re at the moment we’ve all been waiting for…

In the address bar of your browser go to http://mydomain.com/cgi-bin/test.pl and if all is well you should see Greetings Earthling!

That’s it, all done. Ready to rock and roll.

Best wishes

Simon Nicol.

What if it doesn’t work?

What can go wrong? Pretty much everything really. Before I was able to write this post I managed to get almost every error in the book – I even discovered some errors that I didn’t know existed!

Among them was  the wonderfully unhelpful 500 – server error that basically doesn’t tell you anything apart from “Something somewhere isn’t working”. A 502 error – quite how that happened I have no idea. And also everybody’s favourite a 404 error – Just super! Ok? here we go…

404 Error.

To get rid of the 404 error I just renamed the web.config to something else, it was somehow managing to mess things up. Also you can check your folders permissions. They need to be Read & Execute.

500 and 502 Errors

This was a little bit more involved but it will help deepen your understanding of what’s going on under the hood. There’s a text file that contains a list of instructions that are the Handler Mappings. It’s called applicationHost.config and it’s located here: C:\Windows\System32\inetsrv\config if you edit this file (I use a text editor called EmEditor which can display line numbers). It’s around line 400 or so where it has our Perl extension defined. It should look like this:

<add path=”c:\perl64\bin\perl.exe &quot;%s&quot; %s” allowed=”true” />

After all my mistakes in attempting to get Perl working before, I must have had over a half dozen lines like this in their various definitions. I deleted them all and tried again.

Then when I looked in the Handler Mappings I found that my extensions were ‘Disabled‘ I did some searching to see if I could re enable them. After a while I did what I should have done first – delete it and start again. Much easier.

Really, your Perl install should be working by now. It is also possible that you have some error in you Perl code. Fortunately, all my websites I host from home (I really think EVERYBODY) should be doing this. Your own dedicated server, and broadband is fast enough these days.

I went to a PowerShell and changed to the directory where my Perl script was located. From there you can type:

perl -wc cgi-test.pl (Obviously for the Perl command to work the Perl.exe path needs to be in your environment variables which the .msi install should have taken care of this). This command will do a syntax check.

If everything is tickertyboo there, then try it without the ‘c’ option. ie perl -w cgi-test.pl This will display the output of the Perl code you’re running to the PowerShell / Command line so you can see more clearly what’s going on.

Another handy command to know is iisreset which basically does what it says on the tin and shuts down and restarts the IIS service.

That’s it. I’m now pooped and going to switch the kettle on for a nice cup of tea. Please feel free to discuss all things Perl in the comments below.

I would like to give a passing nod to the following sites that although didn’t solve any errors when they happened were certainly instrumental in getting things running – Many thanks!