πŸ–ΌοΈ How to Install ImageMagick for EA-PHP and ALT-PHP

ImageMagick (imagick) is a powerful image manipulation library that can be used with PHP. This guide covers installation for both EA-PHP and ALT-PHP on cPanel servers running AlmaLinux 9 or CloudLinux 9.


βœ… Step 1: Install ImageMagick (System Level)

Log in to your server as root via SSH.

πŸ“¦ For AlmaLinux 9 or CloudLinux 9:

dnf install epel-release -y
dnf install ImageMagick ImageMagick-devel -y

βœ… Step 2: Install ImageMagick PHP Extension

You can install it for:

  • EA-PHP (EasyApache PHP)
  • ALT-PHP (CloudLinux PHP Selector)
  • Or both

πŸ”Ή A. EA-PHP (EasyApache PHP)

πŸ”§ Method 1: Install via Terminal (SSH)

  1. Find PECL binaries for installed EA-PHP versions:
find /opt/cpanel/ -iname pecl | grep bin
  1. Install imagick for each EA-PHP version (e.g., ea-php81):
/opt/cpanel/ea-php81/root/usr/bin/pecl install imagick
echo "extension=imagick.so" > /opt/cpanel/ea-php81/root/etc/php.d/20-imagick.ini
  1. Update CageFS if on CloudLinux:
screen -S updateCageFS
cagefsctl --force-update
cagefsctl -u
  1. Restart detached PHP processes (for LiteSpeed users):
/usr/local/lsws/admin/misc/lswsctrl restart

πŸ–₯️ Method 2: Install via WHM

  1. Log into WHM as root
  2. Navigate to:
    Home Β» Software Β» Module Installers
  3. Click Manage beside PHP Pecl
  4. Choose EA-PHP version (e.g., ea-php81), click Apply
  5. Under Install a PHP Pecl, enter:
imagick
  1. Click Install Now
  2. If using CloudLinux, go to:
    • Home Β» Plugins Β» CageFS User Manager
    • Click Update CageFS Skeleton

πŸ”Ή B. ALT-PHP (CloudLinux PHP Selector)

CloudLinux ALT-PHP already includes ImageMagick, but you must ensure it’s properly set up and enabled:

🧰 Setup ALT-PHP with CageFS

yum groupinstall alt-php -y
yum update cagefs lvemanager -y
/usr/sbin/cagefsctl --init
/usr/sbin/cagefsctl --enable-all

πŸ” List Available ALT-PHP Versions:

/usr/bin/selectorctl --summary

πŸ§‘β€πŸ’» Set ALT-PHP Version for a User (Example: 8.2):

/usr/bin/selectorctl --set-user-current=8.2 --user=cpanelusername

πŸ”„ Update CageFS:

screen -S updateCageFS
cagefsctl -u

πŸ” Restart Detached PHP Processes (for LiteSpeed users):

/usr/local/lsws/admin/misc/lswsctrl restart

πŸ“ Note: ImageMagick is supported for ALT-PHP 5.1+


βœ… Step 3: Test the Installation

πŸ”Ž Create a PHP Info File:

Replace cpanelusername with the actual username and domain.tld with your domain.

echo "<?php phpinfo(); ?>" > /home/cpanelusername/public_html/phpinfo.php
chown cpanelusername:cpanelusername /home/cpanelusername/public_html/phpinfo.php
chmod 0644 /home/cpanelusername/public_html/phpinfo.php

Then test with:

lynx --dump http://domain.tld/phpinfo.php | grep -i "imagick module"

βœ… Step 4: Functional Test (Optional)

Create a file named test_imagick.php:

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

Save it to /home/cpanelusername/public_html/test_imagick.php, then visit it in the browser to verify it outputs:

Ok

πŸ“˜ Bonus: Show Supported Image Types via PHP

You can list the supported image types with this script:

<?php
$imagick = new Imagick();
$formats = $imagick->queryFormats();
echo "Supported Image Formats:<br>";
echo implode(', ', $formats);
?>

βœ… Summary

TypeInstallation RequiredCageFS UpdateRestart PHP Processes
EA-PHPYes (via PECL or WHM)Yes (CloudLinux)Yes (LiteSpeed)
ALT-PHPPreinstalled (CloudLinux)YesYes (LiteSpeed)
Scroll to Top