
Imagick (ImageMagick extension) is a PHP extension used to modify the content images using the ImageMagick API. Many popular PHP applications such as WordPress use it for image optimization.
In this tutorial, we learn how to install the PHP ImageMagick extension on Ubuntu 20.04. Imagick supports PHP 5.4, 5.5, 5.6, 7.0, 7.1, 7.2, 7.3, and 7.4.
Prerequisites
- Ubuntu 20.04 machine with PHP installed
- A non-root user with sudo priviledge
Install Imagick on Ubuntu
First, update your Ubuntu system to resynchronize the package index files from their sources on Ubuntu.
$ sudo apt update
To install Imagick for PHP, type:
$ sudo apt install php-imagick
You can verify the installation, type:
$ php -m | grep imagick
Output:
imagick
Let's check the directory where PHP extensions are stored. First, find the directory where PHP extensions kept using the following command
$ php-config --extension-dir
Note: php-config command is part of php7.4-dev package.
Now list all PHP extensions using:
$ ll /usr/lib/php/20190902

Enable Imagick.so in php.ini file
If you using Apache, php.ini file location is /etc/php/7.4/apache2/php.ini and for Nginx is it /etc/php/7.4/fpm/php.ini. You should replace the path according to your PHP version.
Add the following lines to the respective php.ini file
extension=imagick
You can confirm by creating a PHP info page. For example, let's create an index.php file on the Apache webserver in the following default document root.
$ sudo nano /var/www/html/index.php
Next, copy and paste the sample PHP code below.
<?php
phpinfo();
?>
Save your changes and close the index.php file.
Now, open a web browser and enter serverIP/index.php.

Conclusion
In this tutorial, we learned how to install PHP ImageMagick Extension (Imagick) on Ubuntu 20.04.
Thanks for reading, please lets us know your suggestions in the below comment section.