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
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
Code:
/opt/cpanel/ea-php70/root/usr/bin/pecl install imagick
- Login to WHM as the root user
- Navigate to: Home »Software »Module Installers
- Click on the Manage link to the right of "PHP Pecl"
- Select the version of PHP from the drop-down and click Apply
- Under "Install a PHP Pecl" enter "imagick" (without the quotes)
- Click "Install Now"
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
Code:
yum groupinstall alt-php
yum update cagefs lvemanager
Code:
/usr/bin/selectorctl --summary
/usr/bin/selectorctl --set-user-current=5.1 --user=cpanelusername
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"
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";
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