Image Magick (imagick) for PHP in cPanel
My VPS is AlmaLinux v8.10.0 running cPanel 122.0.13 and uses the regular Multi-PHP setup, not the awesome-but-no-thank-you CloudLinux.
Warning!
I’m an asshole. Follow me at your own risk. Be ready if shit hits the fan. Always ensure you have backups before making system changes, and if you’re on a production server, it’s advisable to test these steps in a staging environment first.
What brings us here?
My WordPress OCD-inducing annoying Site Health kept complaining about Image Magick (imagick) and intl extensions for PHP not being installed.
Ok. This should be easy – said the moronic voice that lives inside my head. (I call him Moroni to just to mess with you Mormons).
It should be just a checkmark in EasyApache > PHP Modules – said the moron. And what do you know? For the intl extension that was the case:
So I provisioned EasyApache4 and while it worked I had a moral obligation to go get me a cigar, and then let’s check:
[root@vps1 imagick]# /opt/cpanel/ea-php74/root/usr/bin/php -m | grep intl
intl
[root@vps1 imagick]# /opt/cpanel/ea-php81/root/usr/bin/php -m | grep intl
intl
[root@vps1 imagick]# /opt/cpanel/ea-php82/root/usr/bin/php -m | grep intl
intl
[root@vps1 imagick]# /opt/cpanel/ea-php83/root/usr/bin/php -m | grep intl
intl
Great, but … (Slow sad violin music starts playing in the background)
I tried looking for imagik in WHM > EasyApache4 > PHP Modules
No such luck.
So I tried WHM > Module Installers > PHP Extensions and Applications Package and PHP PECL, but it just wasn’t fucking there. WTF cPanel! Alas! My happiness was premature and short lived.
This is the kind of thing that triggers my unholy suicidal anger of having to add more tasks to my already never ending SysAdmin 2Do List first thing in the morning. Fortunately, my shrink has me medicated against demonic possession.
I asked Anthropic’s Claude 3.5 Sonnet and it suggested:
dnf update -y
dnf install epel-release -y
dnf install ImageMagick ImageMagick-devel -y
dnf install php-devel -y
dnf install gcc make -y
dnf install php-pear -y
pecl install imagick
Because I’m an asshole, I only ran:
dnf install epel-release -y
dnf install ImageMagick ImageMagick-devel -y
It seems I installed imagick on the system.
Anyway, on to Perplexity to find a better answer. Google? are you serious? “We’re not cavemen. We have technology!”
So Perplexity gave me these commands to try using SSH Terminal:
/scripts/checkimagemagick
[root@vps1 ~]# /scripts/checkimagemagick
bash: /scripts/checkimagemagick: No such file or directory
Fucking AI bullshit! Hope is overrated.
/scripts/installimagemagick
[root@vps1 ~]# /scripts/installimagemagick
bash: /scripts/installimagemagick: No such file or directory
Why am I not surprised?
/usr/bin/convert --version
[root@vps1 ~]# convert
Version: ImageMagick 6.9.13-14 Q16 x86_64 18442 https://legacy.imagemagick.org
Copyright: (C) 1999 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP(4.5)
Delegates (built-in): bzlib cairo djvu fontconfig freetype gslib gvc jbig jng jp2 jpeg lcms ltdl lzma openexr pangocairo png ps raqm raw rsvg tiff webp wmf x xml zlib
Usage: convert [options ...] file [ [options ...] file ...] [options ...] file
[... lots more irrelevant output]
WTF! ImageMagick 6.9.13-14 exists. Seems I really did installed Image Magick after all.
On to next command:
for php in $(whmapi1 php_get_installed_versions|grep -oE '\bea-php.*') ; do /opt/cpanel/$php/root/usr/bin/pecl install imagick; done
This looks like it will run PECL for each ea-version of PHP on my system. My expectations are low because I already checked PECL PHP
It worked like a charm for PHP 7.4, 8.1, 8.2 but fails for PHP 8.3
[root@vps1 imagick]# /opt/cpanel/ea-php74/root/usr/bin/php -m | grep imagick
imagick
[root@vps1 imagick]# /opt/cpanel/ea-php81/root/usr/bin/php -m | grep imagick
imagick
[root@vps1 imagick]# /opt/cpanel/ea-php82/root/usr/bin/php -m | grep imagick
imagick
[root@vps1 imagick]# /opt/cpanel/ea-php83/root/usr/bin/php -m | grep imagick
[nothing]
It’s a known issue that Installing PHP PECL “imagick” fails on PHP 8.3
So I did a manual install as suggested by WJNLLC in the comments:
cd /usr/src
wget https://codeload.github.com/Imagick/imagick/zip/refs/heads/master
unzip master
rm -fr master
mv imagick-master imagick
cd imagick
/opt/cpanel/ea-php83/root/usr/bin/phpize
./configure --with-php-config=/opt/cpanel/ea-php83/root/usr/bin/php-config
make
make test
make install
echo "extension=imagick.so" >> /opt/cpanel/ea-php83/root/etc/php.d/imagick.ini
service httpd restart
service php-fpm restart
Some people might get error when running make test
if they didn’t run dnf install ImageMagick ImageMagick-devel -y
previously, like I did, out of pure dumb fucking luck! 🙂
[root@vps1 imagick]# /opt/cpanel/ea-php83/root/usr/bin/php -m | grep imagick
imagick
Success! At least for me.
Side effects: probably. This may not play well with cPanel, specially on CloudLinux and their PHP Selector, but It gets the job done for me while they fix the PECL issue.
Shit went wrong?
If you fucked up and anything goes wrong, be ready to uninstall manually. This may help:
Remove extension=imagick
.so from /opt/cpanel/ea-php83/root/etc/php.d/imagick.ini
sed -i '/extension=imagick.so/d' /opt/cpanel/ea-php83/root/etc/php.d/imagick.ini
Delete the file (if you followed the above steps, if not wherever you put it IDK, how the fuck should I know what you did?)
rm -f /opt/cpanel/ea-php83/root/etc/php.d/imagick.ini
Remove the compiled extension:
rm -f /opt/cpanel/ea-php83/root/usr/lib64/php/modules/imagick.so
Clean up the source files:
cd /usr/src
rm -rf imagick
Run phpize cleanup:
/opt/cpanel/ea-php83/root/usr/bin/phpize --clean
Restart Apache:
service httpd restart
or for PHP-FPM
service php-fpm restart
Verify that Imagick is no longer loaded:
/opt/cpanel/ea-php83/root/usr/bin/php -m | grep imagick
This should not return any result if Imagick is successfully uninstalled.
Remember to replace ea-php83 with the appropriate version if you’re using a different PHP version.
After following these steps, Imagick module should be uninstalled from your system.
Cheers!
Leave a Reply