How to Install Imagick Extension in PHP 7.0 on Debian Buster

debianimagemagickPHP

I've upgraded our company's webserver to Debian 10 Buster recently. Our website is using a legacy CMS that cannot run on PHP versions newer than 7.0. It requires the imagick extension to be present. Unfortunately, the official debian package php-imagick is only available for PHP 7.3.
What's good and sustainable way to install the Image Magick extension for PHP 7.0 on my Buster install?

Best Answer

You already got PHP 7.0 on your Debian Buster somewhere, despite it comes with PHP 7.3. That's most likely from the DEB.SURY.ORG repository, which also has a suitable version of php-imagick:

$ apt-cache show php-imagick
Package: php-imagick
Version: 3.4.4-4+0~20200302.14+debian10~1.gbp2925ae
. . .
Provides: php5.6-imagick, php7.0-imagick, php7.1-imagick ...

But it also shows you this official Debian 10 Buster version:

Package: php-imagick
Version: 3.4.3-4.1
. . .
Provides: php7.3-imagick

I tested on a Debian 10 Buster with the Sury repository, and the one from Sury was installed by default just by using apt-get install php-imagick. However, if it didn't, you could choose to install this version through the php7.0-imagick it provides:

$ sudo apt-get install php7.0-imagick
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'php-imagick' instead of 'php7.0-imagick'

This php-imagick will be the one from DEB.SURY.ORG.

But next time, please think through all your dependencies before rushing to upgrade the OS.