Install Imagick for IIS and PHP 7.3

I am writing this because there are lots of guides out there, and none of them applied to my situation and never worked for me. Once I did figure it out, finally, I promised myself I’d write a guide.

#php #php73 #iis #windows #server #2012r2 #nts #image #imagick #imagemagick

My Specs:

Windows Server 2012 R2 on IIS 8.5 and using x64 Non-Thread Safe PHP Version 7.3.13 downloaded from here.

Nice to knows:

PHP 7.3 was built on Windows with Visual Studio 2015/2017/2019. Which means that you need Visual C++ Redistributable for Visual Studio 2015-2019 installed. I also break up my PHP versions into separate folders and manually change the PATH variable every time I update versions, so that if anything in the new one breaks any of my code, I can easily go back. For example, I have PHP “installed” to “C:\Program Files\PHP\v7.x” where v.7.x is whichever version of PHP I am using. And in each of these folders is the latest release version number. So, for this blog post, the full path to use is “C:\Program Files\PHP\v7.3\13”.

Step 1

Download ImageMagick 7.0.7.11 which also uses VC15 like PHP 7.3 above does. Extract the contents of the “bin” folder to somewhere obvious and that you won’t accidently delete those files. Two examples: first would be to put it in a root C: folder like extra and the version number so “C:\extra\imagick\7.0.7.11” or second you could do something similar to how I installed PHP above, so “C:\Program Files\ImageMagick\7.0.7.11” again having a version number contain all the files in the “bin” folder in the .zip file. Now whichever or whatever path you choose to use, you need to put that in a couple of environmental path variables.

If you do not already have two “System variables” called “MAGICK_HOME” or “MAGICK_PATH” go ahead and create them with a “Value” of the path to your folder. Should look like this:

You should also add the same directory path that you used above into another “System variable” called “Path”. Make sure you put this near the beginning of the giant path variable and… DO NOT DELETE ANYTHING FROM THIS STRING! You could seriously mess up your system if you do so be careful.

Step 2

Restart your computer. I know you want to get this installed and working perfectly, but I can guarantee you, that if you don’t restart, you’ll have hours of heartache that were unnecessary only because you were too lazy to restart your darn computer! TRUST ME when I say that I have done this several times and truly hate myself when I figure out I did not restart and my changes were never saved or recognized until I did so.

Step 3

Download the php_imagick extension for PHP. Extract two files: php_imagick.dll and php_imagick.pdb into the “ext” directory in PHP. For my example, this folder is located at “C:\Program Files\PHP\v7.3\13\ext”.

Step 4

You should now have everything in place to enable the extension in IIS PHP Manager. If when you go to enable it and nothing says “php_imagick.dll” you might have to manually add the extension in php.ini which I will not cover here.

Step 5

TESTING. There are two things that you need to do to ensure everything is working properly. First off, check the output of <?php phpinfo(); ?> to see if there is an “imagick” section. Now, this section may be populated, BUT if you have a bad path variable or haven’t restarted, the “ImageMagick number of supported formats:” will be set to “0” instead of >200 formats.

The second test is create a new php document, I called mine imagick.php and paste this code into it:

<?php $image = new Imagick(); $image->newImage(1, 1, new ImagickPixel('#ffffff'));
$image->setImageFormat('png');
$pngData = $image->getImagesBlob();
echo strpos($pngData, "\x89PNG\r\n\x1a\n") === 0 ? 'Ok' : 'Failed';
?>

Now navigate to this page and you should get an “Ok” on the page or if something isn’t quite right, a lovely Internal Server Error 500. Just the PHP logs. It also doesn’t help to restart your computer again.

GOOD LUCK!

And I hoped this helped somebody!

Taken in part from here.

Image was taken from Wikipedia page for ImageMagick and I added the PHP logo taken from phpinfo();.

Leave a Reply

Your email address will not be published. Required fields are marked *