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
For both EA-PHP and ALT-PHP, run this command via SSH or Terminal as the root user to install the software:
yum install ImageMagick ImageMagick-devel -y
NOTE: In cPanel 92 and later these packages will be installed by default.
Step 2: Install the ImageMagick PHP Extension
The installation varies 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.
- All commands provided below need to be executed via SSH or Terminal as the root user.
- 1. Find the binaries for PECL for all versions of PHP that you have installed:
find /opt/cpanel/ -iname pecl | grep bin
- 2. 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
- 3. 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
3. Or do the installation via WHM:
1. Log in 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 menu, and click Apply.
5. Under "Install a PHP Pecl", enter "imagick" (without the quotes).
6. Click "Install Now".
7. If the server is CloudLinux update the cage by navigating to: Home »Plugins »CageFS User Manager
8. Then click on the "Update CageFS Skeleton" button on the bottom right
ALT-PHP comes with ImageMagick installed and working by default. These are the steps required to install and enable ALT-PHP for a cPanel user.
- 1. If CageFS is not already installed and working, run these commands via SSH as the root user to set it up:
yum install cagefs
- 2. Or if it is already installed and working, run this command instead, where "cpanelusername" is the name of your cPanel user:
/usr/sbin/cagefsctl --enable cpanelusername
- 3. if it is not already installed, install ALT-PHP with these commands:
yum groupinstall alt-php
yum update cagefs lvemanager
- 4. Set the version of ALT-PHP that the user should have:
/usr/bin/selectorctl --set-user-current=5.1 --user=cpanelusername
- ImageMagick is available for versions 5.1 and up.
- You may need to update the CageFS skeleton in some cases with: cagefsctl -u
Step 3: Testing ImageMagick
Run these commands as the root user to create a PHP-info file, then check it for the ImageMagick extension. Use these commands for both EA- and ALT-PHP.
- You must replace "cpanelusername" with the username of the cPanel user with which you are testing.
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"
Create this 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';
Warnings: We recommend that only experienced system administrators perform the steps in this article. 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.