Installing the Imagick PHP extension in Ubuntu

If you’re running a WordPress website, you’ll see in the WordPress Site Health page that imagick is an optional but recommended module to be installed.

Oh no, imagick is not installed on our server.

We can also check if imagick is installed via the command line, as usual, no output means it’s not installed:

[email protected]:/var/www$ php -m | grep imagick
[email protected]:/var/www$

By the way, the command php --modules and its shorthand version php -m will display the list of compiled modules.

We now install imagick. Before installing we check what version of PHP is running on the server, run the apt-get install using the correct PHP version and finally restart the Apache server:

[email protected]:/var/www$ php -v
PHP 7.4.3 (cli) (built: Oct  6 2020 15:47:56) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies
[email protected]:/var/www$ sudo apt-get install php7.4-imagick
[email protected]:/var/www$ systemctl reload apache2

We should be done with the installation by now. We check if the extension is loaded again:

[email protected]:/var/www$ php -m | grep imagick
[email protected]:/var/www$

This time the extension is shown in the list of PHP modules, so we’re good!