Tutorial How to Install ImageMagick for EA-PHP and ALT-PHP

• We recommend that only experienced system administrators perform these steps. SSH access and root-level privileges are required to execute the commands included in this tutorial.
• cPanel Technical Support does not provide assistance with the steps in this tutorial beyond confirming that ImageMagick is installed and working with a basic test PHP script such as the one included in this resource.
What is ImageMagick?
ImageMagick 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
This step is the same for both EA PHP and CloudLinux's ALT PHP. Run the following command via SSH or Terminal as the root user to ensure the required software is installed:
yum install ImageMagick ImageMagick-devel -y
Step 2 - Install the ImageMagick PHP Extension
For this step, you'll need to vary your installation steps based upon which kind of PHP you want to use the extension with. You can use the extension with just EA or ALT PHP, or you can use it with both simultaneously.

NOTE: All commands provided below need to be executed via SSH or Terminal as the root user.

Find the binaries for PECL for all versions of PHP that you have installed with the following command:
find /opt/cpanel/ -iname pecl | grep bin
Issue the following 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
Alternatively, you can use WHM to do the installation with the following steps:
  1. Login to WHM as the root user
  2. Navigate to: Home »Software »Module Installers
  3. Click on the Manage link to the right of "PHP Pecl"
  4. Select the version of PHP from the drop-down and click Apply
  5. Under "Install a PHP Pecl" enter "imagick" (without the quotes)
  6. Click "Install Now"
See the bottom of this tutorial for instructions to test that ImageMagick and the PHP extension are installed and working.

ALT PHP comes with ImageMagick installed and working by default. Here we'll go over the steps required to install and enable ALT PHP for your cPanel user.

If CageFS is not already installed and working use the following commands via SSH as the root user to do so:
yum install cagefs
/usr/sbin/cagefsctl --init
/usr/sbin/cagefsctl --enable-all
/usr/sbin/cagefsctl --enable cpanelusername
Next, install ALT PHP if it is not already installed:
yum groupinstall alt-php
yum update cagefs lvemanager
Set the version of ALT PHP that the user should have. ImageMagick is available for versions 5.1 and up.
/usr/bin/selectorctl --summary
/usr/bin/selectorctl --set-user-current=5.1 --user=cpanelusername
That's it for ALT PHP. It comes with ImageMagick installed and enabled by default. You can move on to testing now.

Step 3 - Testing ImageMagick
The following commands can be executed as the root user to create a PHP info file and then check it for the ImageMagick extension.

These testing steps can be used for both EA and ALT PHP. You must replace cpanelusername with the username of the cPanel user that you are testing for.
echo "<?php phpinfo();" > /home/cpanelusername/public_html/phpinfo.php
chown cpanelusername:cpanelusername /home/cptest/public_html/phpinfo.php
chmod 0644 /home/cpanelusername/public_html/phpinfo.php
lynx --dump http://domain.tld/phpinfo.php | grep -i "imagick module"
You can also create the following PHP file to test the actual functionality of the ImageMagick plugin:
$image = new Imagick();
$image->newImage(1, 1, new ImagickPixel('#ffffff'));
$pngData = $image->getImagesBlob();
echo strpos($pngData, "\x89PNG\r\n\x1a\n") === 0 ? 'Ok' : 'Failed';
echo "\n";
Additional Questions / Feedback
Feel free to click on the Discussion tab to let us know if you have any questions or feedback about the information in this tutorial.

Admin Note:
This cPanel staff tutorial is no longer being maintained/updated here. For the most recent/up to date version please go here: How to Install ImageMagick for EA-PHP and ALT-PHP
First release
Last update
0.00 star(s) 0 ratings