Windows Server + IIS + PHP 5.3 + ImageMagick + PDFs

After 3 days and hours of frustration, here is the steps to follow for getting php_imagick working on Windows server running IIS:

  • make sure everything you install is 32-bit – this is because PHP is 32-bit, and introducing any 64-bit component will break the whole thing
  • download php_imagick here: http://windows.php.net/downloads/pecl/releases/imagick/3.1.2/php_imagick-3.1.2-5.3-nts-vc9-x86.zip
  • place only the php_imagick.dll file in the “ext” subdirectory of PHP
  • install a legacy version of ImageMagick – this is because as the forum thread http://stackoverflow.com/questions/8457744/installing-imagemagick-onto-xampp-windows-7 points out, PHP 5.3 is compiled with a different version of MSVC than the latest version of ImageMagick, and the two don’t talk to each other. Unfortunately, ImageMagick doesn’t keep archives of old versions, but thankfully other sites do: http://ftp.sunet.se/pub/multimedia/graphics/ImageMagick/binaries/ImageMagick-6.6.5-10-Q16-windows-dll.exe
    For simplicity sake, install the file in “C:\ImageMagick”
  • install a legacy version of GhostScript – again, this is to make sure the versions are compatible with each other. Again, Ghostscript themselves don’t seem to keep legacy files, but you can get them SourcrForge: http://sourceforge.net/projects/ghostscript/files/GPL%20Ghostscript/8.62/gs862w32.exe/download
    For simplicity sake, install the file in “C:\Ghostscript”
  • After all this, ImageMagick still won’t see Ghostscript as a delegate for handling PDF’s – you must edit the “config\delegates.xml” file and replace all instances of “@PSDelegate@” with the full path to the Ghostscript binary (note the forward slashes) as described http://stackoverflow.com/questions/13304832/ghostscripts-file-path-in-imagemagick: C:/Ghostscript/8.62/bin/gswin32c.exe
  • At this stage, any command-line testing of the ImageMagick to Ghostscript communication will probably work – but it won’t work under IIS. This is because by default, Ghostscript uses “C:\Windows\Temp”, but IIS doesn’t have permission to that directory. You must grant read/write access to that directory to “IIS_IUSRS” (or php_imagick will keep reporting that there is no delegate) as explained here: http://www.wizards-toolkit.org/discourse-server/viewtopic.php?f=1&t=24757&p=110439&sid=35e443f4faf1b92d68632a72c4000d3e#p110439
  • Finally – REBOOT! None of this will work without rebooting at least once so the entire OS has references to the newly installed software and libraries.

With any luck, you should now have a working php_imagick installed – you can confirm (at least part) of this using phpinfo() – although this may report php_imagick installed, it’s not a guarantee that PDF support will be working. You won’t know that part until you actually try to read in a PDF.

REAL Subdomains under Linode

While trying to add a sub-domain to my Linode account, I did the typical Google search to see if someone else had done so already, and I could just copy their instructions. Alas, there were plenty of posts titled “Subdomain on Linode” (or something to that effect), but they all only showed how to register a host under the DNS, and set up the <VirtualHost> records under Apache.

A host is not the same as a sub-domain.

Let’s assume we have a domain “mydomain.com”. Adding in “lab.mydomain.com” as an “A” record will simply make a host. You cannot then do “work.lab.mydomain.com” using this method – something which should be perfectly acceptable under an actual sub-domain.

Herewith, I present the correct procedure for adding in a sub-domain under the Linode DNS (using the above example of “mydomain.com”).

  1. Under the Domain zone for “mydomain.com”, add in the following “NS” records:
    1. ns1.linode.com -> lab.mydomain.com
    2. ns2.linode.com -> lab.mydomain.com
    3. ns3.linode.com -> lab.mydomain.com
    4. ns4.linode.com -> lab.mydomain.com
    5. ns5.linode.com -> lab.mydomain.com
  2. Create a new domain zone for “lab.mydomain.com”

Presto. You can now add in host records such as “www.lab.mydomain.com” or whatever you want.