What is ImageMagick?
ImageMagick (imagick) is software designed to display, convert, and edit raster and vector images. It can be leveraged with PHP by installing the ImageMagick PHP extension on cPanel servers.
Step 1: Install ImageMagick
For both EA-PHP and ALT-PHP, ensure that the ImageMagick software is installed.
CentOS 7 / CloudLinux 7
yum install ImageMagick ImageMagick-devel -y
AlmaLinux / CloudLinux 8
dnf config-manager --set-enabled epel
dnf install ImageMagick ImageMagick-devel -y
Step 2: Install the ImageMagick PHP Extension
The installation varies based on which kind of PHP you want to use the extension with. You can use the extension with just EA-PHP or ALT-PHP, or you can use it with both simultaneously.
EA-PHP Extension via SSH or Terminal
Please note all commands provided below need to be executed via SSH or Terminal as the root user. If you are using LiteSpeed or the LSAPI handler with mod_lsapi, you may also need to restart detached PHP processes after the extension is installed. The following article outlines how this is done:
Restart LiteSpeed Detached PHP Processes
- Find the binaries for PECL for all versions of PHP that you have installed:
find /opt/cpanel/ -iname pecl | grep bin
- Run this command for each version of EA-PHP that needs to make use of the extension:
/opt/cpanel/ea-php70/root/usr/bin/pecl install imagick
- On CloudLinux servers, CageFS needs to be updated after installing ImageMagick for EA-PHP. This is best done inside of a screen session:
screen -S updateCageFS
cagefsctl -u
EA-PHP Extension via WHM
- Log in to WHM as the root user.
- Navigate to "Home » Software » Module Installers"
- Click on the Manage link to the right of "PHP Pecl."
- Select your desired version of PHP from the drop-down menu, and click "Apply."
- Under "Install a PHP Pecl," enter "imagick" (without the quotes).
- Click "Install Now."
- If the server's operating system is CloudLinux, update CageFS by navigating to: "Home » Plugins » CageFS User Manager"
- Then click on the "Update CageFS Skeleton" button on the bottom right
- If PHP-FPM is used this service must also be restarted
/scripts/restartsrv_apache_php_fpm
If you're using PHP 8.0, disable_functions has exec disabled by default, review the following article if you haven't enabled exec in your php.ini:
PHP 8.0 - Can not install PECL module with exec in disable_functions - can in previous versions
ALT-PHP Extension
ALT-PHP comes with ImageMagick installed and working by default. These are the steps required to install and enable ALT-PHP for all users on the server.
- If CageFS is not already installed and working, run these commands via SSH as the root user to set it up for all users on the server. If you are not sure if you have already installed and enabled CageFS for the entire server, running these commands will not hurt the server.
yum groupinstall alt-php
yum update cagefs lvemanager
/usr/sbin/cagefsctl --init
/usr/sbin/cagefsctl --enable-all - Next list the versions of ALT-PHP that are available for use:
/usr/bin/selectorctl --summary
- Set the version of ALT-PHP that you desire for the user to use. In this example ALT-PHP 5.1 is being selected:
/usr/bin/selectorctl --set-user-current=5.1 --user=cpanelusername
- Update the CageFS skeleton in a screen session with the following commands:
screen -S updateCageFS
cagefsctl -u - If PHP-FPM is used this service must also be restarted
/scripts/restartsrv_apache_php_fpm
Please note, ImageMagick is available for ALT-PHP 5.1 and up