cPanel & WHM

How to Install ImageMagick in cPanel/WHM Servers

ImageMagick is a great PHP extension that is used to edit images. Usually found in CMS programs like WordPress, ImageMagick allows users to edit images in real-time. Here we are going to install ImageMagick on a cPanel server running CloudLinux.

The install process for ImageMagick is much the same when using cPanel or CloudLinux. The difference is when using CloudLinux you have to tell CageFS that you have installed ImageMagick. By default ImageMagick is already compiled into ALT PHP, this is the PHP version that CloudLinux uses.

On cPanel servers, PHP is always deployed to the same relative path. PHP 8.1 would be located at /opt/cpanel/ea-php81 whilst PHP 7.4 would be located at /opt/cpanel/ea-php74. We are going to install ImageMagick to PHP 7.4

Install ImageMagick cPanel

As the root user log in and issue the below commands.

yum install ImageMagick ImageMagick-devel -y

ImageMagick is now installed but not yet ready to use. Next, we have to install the ImageMagick PHP extension.

This next step depends on what version of PHP you are installing ImageMagick too. We are installing to PHP 7.4 so the command for this would be;

/opt/cpanel/ea-php81/root/usr/bin/pecl install imagick

For PHP 7.4 the command would be

/opt/cpanel/ea-php74/root/usr/bin/pecl install imagick

If you are using CloudLinux and CageFS you have to tell CageFS you have installed ImageMagick to EA PHP

screen -S updateCageFS
cagefsctl -u

At this point, you should have ImageMagick working. You can run a quick test to confirm this.

Test ImageMagick Is Installed

We do this with a PHP info page. Create a new PHP file in the users public_html directory called phpinfo.php and place the below code in the file and save.

<?php
phpinfo();
?>

Then navigate to the file using your browser. In the returned PHP info you should see the following.

imagick module version  3.4.4
imagick classes Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator, ImagickKernel
Imagick compiled with ImageMagick version   ImageMagick 6.9.10-68 Q16 x86_64 2020-04-13 https://imagemagick.org
Imagick using ImageMagick library version   ImageMagick 6.9.10-68 Q16 x86_64 2020-04-01 https://imagemagick.org
ImageMagick copyright   © 1999-2019 ImageMagick Studio LLC
ImageMagick release date    2020-04-01
ImageMagick number of supported formats:    230

You can also test the functionality of ImageMagick by creating a new PHP file and placing the below code in the file. Navigate to it via your browser like the PHP info page above.

<?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 ? 'Working' : 'Errors';
echo "\n";

ImageMagick is a fantastic application to use on Linux Servers and cPanel VPS Servers. It speeds up the delivery of images on websites which. in turn, assists with Search Engine Optimization.

Related Articles

Leave a Reply

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

Back to top button