How to install ImageMagick and Imagick on Ubuntu or Debian.

ImageMagick is a popular tool used for creating and modifying images. Check below to know how ImageMagick and Imagick on Ubuntu is installed and configured.

Install ImageMagick

Use a simple apt-get to install this as it is already included in the base repository.

sudo apt-get install imagemagick

Install Imagick

Use apt-get to install imagick -

sudo apt-get install php-imagick

The complete output of the above command is -

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  php-common
The following packages will be upgraded:
  php-common php-imagick
2 upgraded, 0 newly installed, 0 to remove and 20 not upgraded.
Need to get 0 B/252 kB of archives.
After this operation, 1,758 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Reading changelogs... Done
(Reading database ... 52632 files and directories currently installed.)
Preparing to unpack .../php-common_2%3a70+0~20190814.17+debian9~1.gbp1e7da2_all.deb ...
Unpacking php-common (2:70+0~20190814.17+debian9~1.gbp1e7da2) over (1:49) ...
Setting up php-common (2:70+0~20190814.17+debian9~1.gbp1e7da2) ...
(Reading database ... 52632 files and directories currently installed.)
Preparing to unpack .../php-imagick_3.4.4-1+0~20190814.12+debian9~1.gbpc5da26_amd64.deb ...
find: '/etc/php/7.2': No such file or directory
find: '/etc/php/7.1': No such file or directory
find: '/etc/php/5.6': No such file or directory
WARNING: Module imagick ini file doesn't exist under /etc/php/7.3/mods-available
WARNING: Module imagick ini file doesn't exist under /etc/php/7.3/mods-available
Unpacking php-imagick (3.4.4-1+0~20190814.12+debian9~1.gbpc5da26) over (3.4.3~rc2-2) ...
Setting up php-imagick (3.4.4-1+0~20190814.12+debian9~1.gbpc5da26) ...
[master 8805abe] committing changes in /etc after apt run
 Author: jitendrapurohit <jitendrapurohit@ask.fuzion.co.nz>
 7 files changed, 20 insertions(+)
 create mode 100644 php/5.6/mods-available/imagick.ini
 create mode 100644 php/7.1/mods-available/imagick.ini
 create mode 100644 php/7.2/mods-available/imagick.ini
 create mode 120000 php/7.3/cli/conf.d/20-imagick.ini
 create mode 120000 php/7.3/fpm/conf.d/20-imagick.ini
 create mode 100644 php/7.3/mods-available/imagick.ini

Enable the module using -

sudo phpenmod imagick

Restart apache or nginx -

//restart nginx server
sudo /etc/init.d/nginx restart

//or restart apache
sudo service apache2 reload

Check phpinfo(); and see if the imagick section appears as below.

imagick config

Or confirm using the terminal -

$ php -m | grep imagick
imagick

If you still don't see the above output, try restarting the fpm processes by -

sudo /etc/init.d/php-fpm restart