Imagick is a PHP extension to create and modify images using the ImageMagick library. Those unfamiliar with the ImageMagick software are open-source, free software that can convert, read, write, and process raster images. Currently, the PHP extension only supports PHP 5.4, 5.5, 5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0 and 8.1.
In the following tutorial, you will learn how to install PHP EXTENSION ImageMagick (IMAGICK) on Ubuntu 22.04 LTS Jammy Jellyfish using the command line terminal.
Table of Contents
Update Ubuntu
First, update your system to ensure all existing packages are up to date.
sudo apt update && sudo apt upgrade -y
Install PHP-IMAGICK – APT Ubuntu Method
You have two choices for installation, and one is the default Ubuntu repository or installed from the PPA by Ondřej Surý. The tutorial will cover both options, and you can best decide which one to choose.
Install PHP-IMAGICK from Ubuntu Repository
The first option is to use the official 22.04 Ubuntu repository; for users who are not using the custom PPA for your PHP, this would be the most preferred version.
Install php-imagick with the following command.
sudo apt install php-imagick
Next, verify the installation using the following command, which will check for the module.
php -m | grep imagick
Example output:
Install PHP-IMAGICK – APT PPA Method
The second installation choice is recommended over the default repository by installing the PPA by Ondřej Surý. For those unfamiliar, Ondřej Surý is the maintainer for PHP at Debian and always updates this PPA with the latest stable versions of PHP released.
First, install the required packages for the PPA installation.
sudo apt install software-properties-common -y
Next, import the PPA.
sudo add-apt-repository ppa:ondrej/php -y
Run and APT update to sync the newly added PPA.
sudo apt update
The repository will most likely contain upgrades to dependencies, so run the upgrade on those packages before proceeding.
sudo apt upgrade
Now install the php-imagick package as follows.
sudo apt install php-imagick
Alternatively, specific versions.
Install 7.4 PHP-IMAGICK:
sudo apt install php7.4-imagick
Install 8.0 PHP-IMAGICK:
sudo apt install php8.0-imagick
Install 8.1 PHP-IMAGICK:
sudo apt install php8.0-imagick
Next, verify the installation:
php -m | grep imagick
Example output:
Comments and Conclusion
You have learned how to install PHP-imagick either using the Ubuntu default repository or the one by Ondřej Surý. Overall, out of the many options for image conversion that PHP can use, this is the most highly used and recommended choice compared to other options such as GD, especially for WordPress web servers, as it produces sharper, higher-quality compressed images.