How to Install PHP ImageMagick on Ubuntu 22.04 or 20.04

The PHP-ImageMagick extension is a powerful tool for manipulating images within PHP scripts. It allows you to perform operations such as resizing, cropping, and format conversion on images using the command-line ImageMagick library. This article will discuss installing the PHP-ImageMagick extension on Ubuntu 20.04 or 22.04 using the command-line terminal.

Step 1: Update Ubuntu

Begin by updating your system to ensure all packages are current, minimizing potential conflicts during installation.

sudo apt update

Use the command below to check for available updates for review or information.

apt list --upgradable

The command below updates all installed packages to their latest versions.

sudo apt upgrade

Step 2: Install ImageMagick

You can skip this section if you’re only looking for a PHP extension. However, for developers or regular users who want to use the ImageMagick command to edit images, installing the full package is necessary.

The good news is that you don’t need to add third-party repositories for Ubuntu or earlier versions. Instead, you can download the required packages from Ubuntu’s official default repositories using the APT package manager.

To install ImageMagick, run the following command:

sudo apt install imagemagick imagemagick-doc

Once the installation is complete, you can check the version using the following command:

convert -version

Step 3: Install PHP-ImageMagick

The simplest method of installing the PHP-ImageMagick extension is through the APT package manager with the following command:

sudo apt install imagemagick php-imagick

If you want to upgrade your PHP along with the PHP ImageMagick extension, check out how to upgrade PHP on Ubuntu 22.04 or 20.04 LTS.

Next, confirm that PHP ImageMagick is installed by typing the following command in your terminal:

php -m | grep imagick

If the extension is correctly installed and enabled, the terminal will output “imagick.” If the output is empty, then the extension is not installed or not enabled.

Conclusion

In conclusion, this guide provides an overview of installing the PHP-ImageMagick extension on Ubuntu 20.04 or 22.04 using the command-line terminal and the APT package manager. It is a straightforward process that will enable you to use the powerful ImageMagick library within your PHP scripts to manipulate images efficiently.

Share to...