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 realtime. 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 7.4 would be located at /opt/cpanel/ea-php74 whilst PHP 7.2 would be located at /opt/cpanel/ea-php72. We are going to install ImageMagick to PHP 7.4
Install ImageMagic 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-php74/root/usr/bin/pecl install imagick
For PHP 7.2 the command would be
/opt/cpanel/ea-php72/root/usr/bin/pecl install imagick
If you are using CloudLinux and CageFS you have to tell CageFS you have installed ImageMagic 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";
Customers who have a free cPanel license can request the support team install this and any other extensions for PHP. This is included in your Server Management package.
How was this article?
You might also like
More from cPanel
A smarthost relay is an external SMTP server that you can connect to your cPanel server. The smarthost will deal …