Setting Up ImageMagick 6.7.4.6 Q16 in Windows Vista x64 SP2 with IIS7 and PHP 5.3 Imagick Extension

Wow, I’ve been trying to do this for almost a week and a half and finally I got it. I Google it!, StackOver it and nothing gave me to possibilities to have my localhost Windows Vista IIS7 with the latest ImageMagick Q16 and PHP extension working properly. But know I have my IIS7 PHP running smoothly with iMagick class working properly.

How do I get this working, well I follow a couple of tutorials that suggested to try with previous version of ImageMagick and the proper PHP extension and none of them work for me. So I decided to follow valokuva.org tutorial and also this tutorial from elxsy.com. Everything was perfect only that even though I follow all steps, after restarting the server no iMagick extension was enabled and most of the tutorial found was based in Unix/Apache not Windows Server.

Well, installing ImageMagick in Apache/XAMPP at work was a breath for me, but to got it right with IIS7 in my home was another story. So if you follow those tutorials and the Server Environment in phpinfo() show that ImageMagick is enabled and still no Imagick section in the PHP info file, then follow this simple steps:

  1. Uninstall ImageMagick and dowload the latest version here. Download the 32 bit version instead the 64 bit version, works better.
  2. Download the nts version of the php_imagick extension here. Windows does not require, or recommend, Safe-Thread version, and if you installed your PHP with the Microsoft Web Platform Installer you probably have the Non Thread Safe version of PHP installed. You can verify this in the phpinfo(), search for the Thread Safe row and ensure that is disabled. If not then download the ts version. If you don’t have a phpinfo go to item number 12. – Note, Windows does not need Thread Safe, if you haven’t installed PHP in your machine download the VC9 NTS version or install everything with the Microsoft Web Installer – “You will be looking at using FastCGI or something equal which works in a different model where PHP is totally outside┬áof the web server with multiple PHP processes used for answering requests through e.g. FastCGI. For such cases, thread-safety also doesn’t matter.” More Info
  3. If you want to use Ghostscript, download it here and install it first than ImageMagick. Obviously I suggest to install it in the C:/ directory example: “C:\gs” or whatever name you want it to call it. This is if you want ImageMagick create thumbnails of uploaded pdf files in the fly.
  4. Install ImageMagick and make sure you install in the C:/ root example (C:\imagemagick) do not install it in Program Files or Program Files(x86) folder and also that you check to include the environment path with the installation. If you forgot to do it, press the right click in ‘Computer’ icon and click ‘Properties’, look in the left column of the opened window and click ‘Advance System Settings’. After confirming authorization, if UAC is active, in the prompted GUI, click the button ‘Environment Variables’. Another GUI will be prompted and in ‘System Variables’, if you don’t see anything pointing to your ImageMagick location, click on the new button and add variable name IMAGEMAGICK, with a value of C:\imagemagick or the name of the path you decided to installed ImageMagick. And just in case, also add a variable for Ghostscript – if installed – variable name GHOSTSCRIPT value “C:\gs” as example. When creating the variable remember to use slash and not forward slash, will not find the locations.
  5. After installing Ghostscript (Optional) and ImageMagick, restart your computer. The server environment is not loaded instantly, server need to be restarted.
  6. Once this is done, go to your PHP location, that I hoped you had installed in the root to ‘C:\php’, and look for php.ini file. If you only have Notepad in your computer to edit php files download a better version called Notepad2, look for the extension area or just add at the end of the file “extension=php_imagick_nts.dll” if you download the nts version, or “extension=php_imagick_ts.dll” for the thread safe version.
  7. Copy the dll file into your PHP extension folder, example “C:/php/ext/”.
  8. Once you have that, click on the Start button and in the search bar type “inetmgr”. And click the software icon that appear in the results column. If you do not have a link in your desktop to this tool I suggest you to do it so you can find it quickly next time.
  9. When the INET manager load, in the middle pane you will see three main areas, “ASP.NET” – “IIS” – “Management”. In the IIS area find PHP Manager and click on it.
  10. If you have never click on that button before you probably will find an yellow warning saying that your configurations are not optimal, click on the link to fix your configuration and save every recommended configuration, probably one of them is the Thread Safe and cgi_config. This will make your extensions specified to load. Don’t ask me why, I’m not an expert in this area.
  11. After this, check your extensions, the last section is “PHP Extensions” and it will display how many extensions are installed and how many are enabled, under this there’s a link that says “Enable or Disable an extension” click on it an ensure that the imagick extension is enabled. If not enable it.
  12. In the left column, click on your computer to go back to the main menu, in the right column on the very top you will see a green icon labeled ‘Restart’, click on it.
  13. If you don’t have a phpinfo page create it and save it in “C:\inetpub\wwwroot”, inside that page type “<?php phpinfo(); ?>” and save it as “index.php”.
  14. Open your browser and in the address bar type: “localhost”, if it’s the first time probably your search engine will try to locate that in the web, if that is so type in “http://localhost”. Then the php info page should display. Scroll down until you found the Imagick section, if you find it your good to go, if not I’m sorry to say, you’re in your own… ­čÖü
  15. If your good, scroll down a little bit more and in the system variable you should have a row with IMAGEMAGICK and another with GHOSTSCRIPT if it is installed.
  16. To try the Imagick extension create another php page called “imagick_test” and type in <?php header(“Content-Type: text/plain”); system(“convert -version”); ?>. This should output the following
Version: ImageMagick 6.7.4-5 2012-01-11 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP
  1. If you see this, everything is working fine for the exec() PHP function, now try this:
  2. Add to the page: “$im = new Imagick;” and save it. Refresh the page, if no error is displayed your dll extension is working fine.

I hope this will help, takes me almost a week to figure this out so I hope you found this blog before.

Happy Coding!