Monday, December 14, 2015

Setting up ImageMagick for PHP on Azure

Recently I was trying to get PHP+MySQL web application setup on Azure. I was excited to see how Azure would play with non Microsoft platforms. It was quite promising to see that Azure gave me a web applicaiton with PHP out of the box.

Now I wanted to stretch it further by trying to setup ImageMagick extension. Now installing ImageMagick has historically not been the cleanest process. With numerous libraries floating around it has been a less than ideal experience. I did finally get it working though, thanks to the pointer by Brij Raj Singh at StackoverFlow and the article by Mangesh. I am outlining here the steps I followed, tweaking Mangesh's steps a bit to get ImageMagick working on default PHP installation of Azure.

I am assuming in Azure you already have a web application with PHP enabled, and you are using the latest PHP 5.6 from Azure App Settings.

  1. Download the file and extract it in a temporary folder
  2. From, scroll to the 'Windows Binary Release' section and download the latest file ending with Q16-x86-dll.exe. (as of writing it was )
  3. Install the above downloaded exe file on your windows personal machine/laptop
  4. Now from within the FTP of your Azure site, create a folder named 'ext' in your root folder. So the path to this folder would be something like /site/ext
  5. Create a folder named 'ini' in your root folder. So the path to this folder would be something like /site/ini
  6. Create a folder named 'imagickwin' in your root folder. So the path to this folder would be something like /site/imagickwin
  7. In the ini folder created above, create a new file named extensions.ini
  8.  The ini file created above should have the following text extension=d:\home\site\ext\php_imagick.dll 
  9. In Azure portalgo to Application Settings for your app resource, and change PHP to the latest version 5.6
  10. In the Application Settings itself, create a key named 'PHP_INI_SCAN_DIR', and provide its value as d:\home\site\ini . This is as described at site.

  11. Copy all the Core*.dll files from 'C:\Program Files (x86)\ImageMagick-6.9.2-Q16' to the /site/imagickwin folder.
  12. Copy all DLL files from 'C:\Program Files (x86)\ImageMagick-6.9.2-Q16\modules\coders' to the /site/imagickwin folder.
  13. Now go to the folder where you extracted '' archive contents. From this, copy all the dll files to /site/ext folder
  14. Next is the most important step - Create a new file namedapplicationHost.xdt directly under the at the site folder level. This file should have the below:

<configuration xmlns:xdt=""> 
    <runtime xdt:Transform="InsertIfMissing"> 
      <environmentVariables xdt:Transform="InsertIfMissing"> 
        <add name="PATH" value="%PATH%d:\home\site\ext\;" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" /> 
        <add name="MAGICK_HOME" value="d:\home\site\ext\" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" /> 
        <add name="MAGICK_CODER_MODULE_PATH" value="d:\home\site\imagickwin\" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" /> 

Now, restart your web application, and load phpinfo() to verify that you are seeing something like below:

And you are done!