How to Install the Imagick PHP Extension on Windows

Recently while I was setting up Nuno Maduro's Pinkary project in my local PC I had a hardtime. I had many reasons but especially with installing Imagick PHP extension.

I was using XAMPP as my local server but when I tried to install this app there was multiple problems like PHP version etc. So I chose to use Docker but for that also PHP8.3 was needed and these PHP extensions are also needed. So you can use these steps for prettymuch all PHP extension installations.

Step 1: Check PHP Compatibility

Before you begin, ensure you know your PHP version, thread safety (TS or NTS), and architecture (x86 or x64). You can find this information by running the following command in your command prompt:

php -i | findstr "Thread Safety" && php -i | findstr "Architecture" && php -v

Step 2: Download the Imagick Extension

  1. Go to the PECL Imagick page.
  2. Download the DLL that matches your PHP version, architecture, and thread safety.
  3. Extract the downloaded zip file.

Step 3: Copy the DLL to the PHP Extensions Directory

  1. Copy the php_imagick.dll file from the extracted folder and paste it into your PHP extensions directory (e.g., C:\xampp\php\ext).
  2. Copy the extracted folder (ie, php_imagick-3.7.0.) to the PHP root directory (e.g., C:\xampp\php).

Step 4: Update the php.ini File

Open your php.ini file (usually located in your PHP installation directory) and add the following line to enable the Imagick extension:

extension=php_imagick.dll

Step 5: Add ImageMagick to the System PATH

  1. Open the System Properties (you can search for "Environment Variables" in the Start menu).
  2. Click on Environment Variables.
  3. Under User variables, find the Path variable and click Edit.
  4. Add the imagick extracted directory (e.g., C:\xampp\php\php_imagick-3-7-0).

Step 6: Restart Your Web Server

Open the XAMPP control panel (or your web server control panel) and restart Apache to apply the changes.

Step 7: Verify the Installation

Create a PHP file (e.g., info.php) with the following content:

<?php phpinfo(); ?>

Open this file in your browser (e.g., http://localhost/info.php) and search for "imagick" to verify that the extension is loaded.

Conclusion

Hope it is done. And I believe we can follow these steps to install any new PHP extensions.
Happy coding! 🚀