Imagick is a PHP extension that allows you to manipulate images programmatically. 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.
First thing, download and install Imagick. In Terminal, run the following commands on your server. This will install Imagick for PHP 7:
sudo apt-get update sudo apt-get install php-imagick
Verify that Imagick is now installed. This command should output the word
imagick if it was installed successfully:
php -m | grep imagick
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):
Verify that the file
imagick.so exists in that directory:
Now you need to edit the
php.ini configuration file. To find out where this file is located, you 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 <?php phpinfo(); ?>
Load that file in your browser and look for the
Loaded Configuration File setting. It should have the path to the
php.ini file you need to edit (the path to your php.ini file may be different than what's shown in this example):
sudo pico /etc/php/7.2/fpm/php.ini
Add the following line (you may add it at the end of the file) and save it:
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.
Once you're done, remember to delete the
info.php file you created. This file reveals a lot about your system, so you don't want it to remain there, accessible to the public. Simply delete it.