cPanelResources

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

Warnings
• 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:
Code:
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.

EA PHP
Find the binaries for PECL for all versions of PHP that you have installed with the following command:
Code:
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:
Code:
/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
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:
Code:
yum install cagefs
/usr/sbin/cagefsctl --init
/usr/sbin/cagefsctl --enable-all
or
/usr/sbin/cagefsctl --enable cpanelusername
Next, install ALT PHP if it is not already installed:
Code:
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.
Code:
/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.
Code:
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:
Code:
<?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";
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.
Author
cPanelResources
Views
103
First release
Last update