How To Install And Enable The Imagick Extension In PHP

Avatar photoPosted by

Imagick is a PHP extension that provides a wrapper for the ImageMagick library, which is used for creating and modifying images.

Here’s how you can install and enable the Imagick extension:

For Linux (Ubuntu/Debian)

  1. Update your package lists:
   sudo apt-get update
  1. Install ImageMagick and PHP Imagick extension:
   sudo apt-get install imagemagick php-imagick
  1. Restart your web server:
   sudo systemctl restart apache2   # For Apache
   sudo systemctl restart nginx     # For Nginx

For macOS

If you are using macOS with Homebrew, you can install Imagick like this:

  1. Install ImageMagick using Homebrew:
   brew install imagemagick
  1. Install the PHP Imagick extension:
   pecl install imagick
  1. Add the extension to your php.ini file:
   echo "extension=imagick.so" >> /usr/local/etc/php/{php-version}/php.ini

Replace {php-version} with your actual PHP version number.

  1. Restart your web server:
   sudo apachectl restart   # For Apache
   sudo nginx -s reload     # For Nginx

For Windows

  1. Download ImageMagick:
  • Go to the ImageMagick download page and download the binary release that matches your PHP version and architecture (x86 or x64).
  1. Install ImageMagick:
  • Run the installer and make sure to check the option “Install development headers and libraries for C and C++”.
  1. Download and install the Imagick extension:
  • Go to the PECL website and download the DLL file that matches your PHP version and architecture.
  • Move the downloaded php_imagick.dll file to your PHP extensions directory (usually ext within your PHP installation folder).
  1. Edit your php.ini file:
  • Add the line: extension=php_imagick.dll
  1. Restart your web server:
   net stop apache2.4   # For Apache
   net start apache2.4  # For Apache

Verify Installation

After installation, you can verify that Imagick is enabled by creating a PHP file (e.g., info.php) with the following content:

<?php
phpinfo();
?>

Access this file through your web browser. Look for the Imagick section in the output to confirm that it is installed and enabled.

By following these steps, you should be able to install and enable the Imagick extension for your PHP environment.