How to Install ImageMagick or Imagick PHP Extension in Linux

ImageMagick or Imagick, is a popular image editing tool to create, edit, compose, or convert digital images into another format. It supports over 200 formats, including PNG, JPEG, GIF, WebP, HEIC, SVG, PDF, DPX, EXR, and TIFF.

It provides various editing tools such as resizing, flipping, mirroring, rotating, distorting, shearing, and transforming images, adjusting image colors, applying multiple special effects, drawing text, lines, polygons, ellipses, and Bézier curves.

Today, you will learn how to install ImageMagick as an extension for PHP scripts in a few simple steps.

Requirements

First, follow the below articles to install the ImageMagick tool on your system, depending upon your Linux distribution.

Install ImageMagick PHP Extension on Debian/Ubuntu

First, open your terminal app using the Ctrl+Alt+t or Ctl+Shift+t keyboard shortcut and run the below command to install PHP and common PHP packages.

$ sudo apt install php php-common gcc

Now install the ImageMagick and ImageMagick PHP extension by using the following command.

$ sudo apt install imagemagick
$ sudo apt install php-imagick

After the installation process is complete, execute the below command to restart the Apache server.

$ sudo systemctl restart apache2

Finally, you can verify the ImageMagick extension is successfully installed on your system by running the below command on your terminal app.

$ php -m | grep imagick
imagick

Below is the output of the above command.

Install ImageMagick PHP Extension in Debian-Ubuntu
Install ImageMagick PHP Extension in Debian/Ubuntu

Removing the ImageMagick PHP Extension in Debian/Ubuntu

Execute the below command if you decide to remove the ImageMagick PHP extension from your Ubuntu or Debian-based distributions.

$ sudo apt remove php-imagick
$ sudo systemctl restart apache2

Install ImageMagick PHP Extension on RHEL/Fedora/Alma Linux

First, open your terminal app using the Ctrl+Alt+t or Ctl+Shift+t keyboard shortcut and run the below command to install PHP and common PHP packages.

$ sudo dnf install php php-common

Install the three required packages, php-pear, php-devel, and gcc, on your system for compiling the ImageMagick PHP extension.

$ sudo dnf install php-pear php-devel gcc 

Time to install the ImageMagick PHP extension using the dnf command. It will automatically install the extension and add the module to the php.ini file.

$ sudo dnf install php-imagick

Next, execute the below command to restart the apache server.

$ sudo systemctl restart httpd

Finally, you can verify the ImageMagick extension is successfully installed on your system by running the below command on your terminal app.

$ php -m | grep imagick
imagick

Below is the output of the above command.

Install ImageMagick PHP Extension in RHEL
Install ImageMagick PHP Extension in RHEL

Removing the ImageMagick PHP Extension in RHEL/CentOS/Fedora/Alma Linux

Execute the below command if you decide to remove the ImageMagick PHP extension and all other packages installed during the installation from your RHEL-based distributions.

$ sudo dnf remove php-pear php-devel gcc php-imagick
$ sudo systemctl restart apache2

If you have any queries regarding the installation, let us know in the comment section.

Leave a Reply