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)
- Find PECL binaries for installed EA-PHP versions:
find /opt/cpanel/ -iname pecl | grep bin
- 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
- Update CageFS if on CloudLinux:
screen -S updateCageFS
cagefsctl --force-update
cagefsctl -u
- Restart detached PHP processes (for LiteSpeed users):
/usr/local/lsws/admin/misc/lswsctrl restart
π₯οΈ Method 2: Install via WHM
- Log into WHM as root
- Navigate to:
Home Β» Software Β» Module Installers - Click Manage beside PHP Pecl
- Choose EA-PHP version (e.g., ea-php81), click Apply
- Under Install a PHP Pecl, enter:
imagick
- Click Install Now
- 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
Type | Installation Required | CageFS Update | Restart PHP Processes |
---|---|---|---|
EA-PHP | Yes (via PECL or WHM) | Yes (CloudLinux) | Yes (LiteSpeed) |
ALT-PHP | Preinstalled (CloudLinux) | Yes | Yes (LiteSpeed) |