How to install ImageMagick in ea-php and alt-php

If you found this post helpful, kindly share it and show your support :)

To install ImageMagick, you can run below command via Terminal as a root user for both ea-php and alt-php

yum install ImageMagick ImageMagick-devel -y

FYI :- These packages will be installed by default on cPanel 92 and later.

For ea-php, you can follow below steps to install the ImageMagick PHP Extension from command line :-

  • To find the binaries for PECL for all versions of PHP that you have installed:
find /opt/cpanel/ -iname pecl | grep bin
  • Run below command for each version of ea-php that needs to make use of the extension (For eg: PHP 7.3)
  • You can replace ea-php73 based on the PHP version. ea-php71 for PHP 7.1, ea-php72 for PHP 7.2 etc)
/opt/cpanel/ea-php73/root/usr/bin/pecl install imagick
  • CageFS needs to be updated after installing ImageMagick for ea-php on CloudLinux servers. You can run this inside of a screen session:
screen -S updateCageFS
cagefsctl -u

From WHM, you can do the same by following below steps.

  • Log in to your WHM as the root user.
  • Go to Home »Software »Module Installers.
  • On the right of “PHP Pecl”, click on the Manage link.
  • Select the PHP version from the drop-down menu, and click Apply.
  • Enter “imagick” (without the quotes) on the box under “Install a PHP Pecl”
  • Click “Install Now”.
  • For CloudLinux servers, you will need to update the cage by following below step

Home >> Plugins >> CageFS User Manager >> click on the “Update CageFS Skeleton” button on the bottom right.

For alt-php, the ImageMagick installed and working by default in alt-php. The below steps required to install and enable alt-php for a cPanel user.

  • If CageFS is not installed on the server, you can run below commands from commandline as a root user to set it up.
yum install cagefs
/usr/sbin/cagefsctl --init
/usr/sbin/cagefsctl --enable-all
  • If CageFS is already installed and working, you can run below command, where “username” is the name of your cPanel user:
/usr/sbin/cagefsctl --enable username
  • To install alt-php, you run below commands :-
yum groupinstall alt-php
yum update cagefs lvemanager
  • Set the version of alt-php that the cPanel user should have:
/usr/bin/selectorctl --summary
/usr/bin/selectorctl --set-user-current=7.3 --user=username
  1. ImageMagick is available for alt-php versions 5.1 and up.
  2. In some cases, you may need to update the CageFS skeleton using cagefsctl -u
  • You can run below commands as a root user to create a PHP-info file, then check it for the ImageMagick extension. You can use same commands for both ea-php and alt-php
echo "<?php phpinfo();" > /home/username/public_html/phpinfo.php
chown username:username /home/username/public_html/phpinfo.php
chmod 0644 /home/username/public_html/phpinfo.php
lynx --dump http://domain.tld/phpinfo.php | grep -i "imagick module" 

Replace “username” with the cPanel user and domain.tld with corresponding domain name

  • You can also test the actual functionality of the ImageMagick plugin by creating this PHP file.
<?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";

Warning :- We recommend that only experienced system administrators perform the steps in this article.

Loading

Mohammed Noufal

I'm Mohammed Noufal, working as Server Admin for the last 10 years.  In my day-to-day life, l had to face different problems related to Web-hosting. On my website Errorlogz.com, you can find solutions for different Web-hosting-related problems. Sometimes, I spent hours searching/googling to find a solution. This inspired me to start a website that gives solutions to different Webhosting problems. This website includes basic Linux and windows commands, and different control panels like cPanel, Plesk, DirectAdmin, Webmin & so on. You can find solutions and or suggestions for different Web-hosting related problems from here. Hence I would like to say Errorlogz is your server protector.  I will be glad if Logdetect can help any one of the Server admins to find a solution to his problem.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *