DEV Community

Mario
Mario

Posted on • Originally published at mariordev.com on

How to Install and Enable Imagick for PHP 7 on Ubuntu 16.04

Imagick is a PHP extension that allows you to manipulate images. Some libraries or packages require that Imagick be installed on your server. However, because Imagick is optional, it’s not installed with PHP by default. Here’s how to install and enable Imagick on your Ubuntu server.

Installation

First thing, download and install Imagick. In Terminal, run the following commands. This will install Imagick for PHP 7:

$ sudo apt-get update
$ sudo apt-get install php-imagick
Enter fullscreen mode Exit fullscreen mode

Verify that Imagick is now installed. This command should output the word imagick if it was installed successfully:

$ php -m | grep imagick
Enter fullscreen mode Exit fullscreen mode

imagick.so

Find out the directory where your PHP extensions are installed. This command should output the path to that directory (example: /usr/lib/php/20170718, your path may be different):

$ php-config --extension-dir
Enter fullscreen mode Exit fullscreen mode

Verify that the file imagick.so exists in that directory:

$ ll /usr/lib/php/20170718
Enter fullscreen mode Exit fullscreen mode

Edit php.ini

Now we need to edit the php.ini configuration file. To find out where this file is located, we need to look at the current php configuration. To do that, create a php info file that you can access from your browser. You may call it info.php:

// info.php
<?php phpinfo(); ?>
Enter fullscreen mode Exit fullscreen mode

Load that file in your browser and look for the Loaded Configuration File setting. It should have the path to the php.ini file we need to edit (the path to your php.ini file may be different than what’s shown in this example):

PHP Info

Open that php.ini file:

$ sudo pico /etc/php/7.2/fpm/php.ini
Enter fullscreen mode Exit fullscreen mode

Add the following line (you may add it at the end of the file) and save it:

extension=imagick
Enter fullscreen mode Exit fullscreen mode

Restart

If you’re doing this in your local development environment, restart your computer or virtual machine. If you’re doing this on an actual server, restart it. You may want to try restarting your web server only (apache, nginx, etc), but this may not work. It’s more effective to just do a restart on the machine so that all the changes take effect.

After restarting, verify that Imagick is available by loading your info.php file in your browser again, and this time you should see in it many references to the Imagick extension.

Top comments (0)