How to Install PHP-Imagick on Ubuntu 26.04, 24.04 and 22.04

Last updated Wednesday, March 25, 2026 9:24 am 7 min read

Image uploads, thumbnail generation, and PDF previews break quickly when the Imagick extension is missing from a PHP stack. You can install PHP-Imagick on Ubuntu from the default repositories on 26.04, 24.04, and 22.04, then load the ImageMagick-backed module in PHP CLI or the web SAPI that serves your application.

On Ubuntu, php-imagick installs the distro-default Imagick extension, while versioned packages such as php8.5-imagick come from the Ondrej PHP PPA. The stock package works on server and minimal installs too, but it lives in the Universe component. Use the PPA only on Ubuntu 24.04 or 22.04 when you need a specific PHP branch outside Ubuntu’s default track. If you need the standalone magick command instead of the PHP binding, install ImageMagick on Ubuntu.

Install PHP-Imagick on Ubuntu

Start with Ubuntu’s package when the host follows the distro PHP branch. Move to the Ondrej method only when Ubuntu 24.04 or 22.04 needs a versioned package such as php8.4-imagick or php8.5-imagick.

MethodChannelUbuntu SupportPHP BranchesBest For
Ubuntu default APT sourcesUbuntu Packages26.04, 24.04, and 22.04PHP 8.5 on 26.04, PHP 8.3 on 24.04, PHP 8.1 on 22.04Most hosts that stay on Ubuntu’s packaged PHP branch
Ondrej PHP PPALaunchpad PPA24.04 and 22.04 onlyVersion-specific packages such as PHP 8.5, 8.4, 8.3, 8.2, and 8.1Hosts that already run a specific non-default PHP branch

Install PHP-Imagick from Ubuntu’s Default Repositories

Refresh APT metadata first so Ubuntu resolves the current package set for your release.

sudo apt update && sudo apt upgrade

These commands use sudo for tasks that need root privileges. If your account does not have sudo access yet, follow the guide to add a new user to sudoers on Ubuntu.

The package lives in Universe on all supported Ubuntu LTS releases. Most standard installs already have that component enabled, but if apt cannot find php-imagick, follow the guide to enable Universe and Multiverse in Ubuntu first. Only Universe is required for php-imagick. Do not add a separate imagick package name here, because Ubuntu ships the standalone CLI suite as imagemagick, while php-imagick is the PHP extension.

Check the package before you install it:

apt-cache policy php-imagick
php-imagick:
	Installed: (none)
	Candidate: 3.8.0-3ubuntu1
	Version table:
		 3.8.0-3ubuntu1 500
				500 http://au.archive.ubuntu.com/ubuntu resolute/universe amd64 Packages

Ubuntu maps the generic package to the distro PHP branch. That means php8.5-imagick on Ubuntu 26.04, php8.3-imagick on Ubuntu 24.04, and php8.1-imagick on Ubuntu 22.04.

Install php-cli alongside php-imagick on clean hosts. That gives you a CLI SAPI for verification and avoids letting Ubuntu satisfy the generic PHP dependency by pulling Apache’s mod_php package by default.

sudo apt install php-cli php-imagick

On Ubuntu 26.04, relevant output includes:

The following NEW packages will be installed:
	imagemagick-7-common libargon2-1 libfftw3-double3 liblqr-1-0
	libmagickcore-7.q16-10 libmagickwand-7.q16-10 libraw23t64 libsodium23
	php-cli php-common php-imagick php8.5-cli php8.5-common php8.5-imagick
	php8.5-readline
0 upgraded, 15 newly installed, 0 to remove and 124 not upgraded.

Confirm that the active CLI SAPI loads the extension. Use the same grep exact-match pattern in Linux when you want the result trimmed to one exact imagick line.

php -m | grep -x imagick
imagick

If the server still needs the rest of the runtime, install PHP on Ubuntu first. When a website still reports Class 'Imagick' not found after the CLI check passes, restart the PHP-FPM or Apache service that serves the application.

Install Version-Specific PHP-Imagick Packages from the Ondrej PHP PPA

Use this path only on Ubuntu 24.04 or 22.04 when the host already runs a versioned PHP branch outside Ubuntu’s default track. The PPA does not currently publish a usable resolute Release file for Ubuntu 26.04, so skip this method there.

Install the repository helper first if the host does not already provide add-apt-repository:

sudo apt install software-properties-common

Add the Ondrej PHP PPA and refresh APT:

sudo add-apt-repository -y ppa:ondrej/php
sudo apt update

On Ubuntu 24.04, relevant output includes:

Hit:5 https://ppa.launchpadcontent.net/ondrej/php/ubuntu noble InRelease

Check which versioned extension packages the PPA exposes. Ubuntu 24.04 shows the noble suite here, while Ubuntu 22.04 shows jammy.

apt-cache policy php8.5-imagick php8.4-imagick php8.3-imagick
php8.5-imagick:
	Installed: (none)
	Candidate: 3.8.1-1+ubuntu24.04.1+deb.sury.org+1
	Version table:
		 3.8.1-1+ubuntu24.04.1+deb.sury.org+1 500
				500 https://ppa.launchpadcontent.net/ondrej/php/ubuntu noble/main amd64 Packages
php8.4-imagick:
	Installed: (none)
	Candidate: 3.8.1-1+ubuntu24.04.1+deb.sury.org+1
	Version table:
		 3.8.1-1+ubuntu24.04.1+deb.sury.org+1 500
				500 https://ppa.launchpadcontent.net/ondrej/php/ubuntu noble/main amd64 Packages
php8.3-imagick:
	Installed: (none)
	Candidate: 3.8.1-1+ubuntu24.04.1+deb.sury.org+1
	Version table:
		 3.8.1-1+ubuntu24.04.1+deb.sury.org+1 500
				500 https://ppa.launchpadcontent.net/ondrej/php/ubuntu noble/main amd64 Packages

Install the package that matches the PHP runtime you actually use. This example installs the newest branch from the PPA, but you can swap in php8.4-imagick, php8.3-imagick, or another published branch as needed. If the host still needs the runtime itself, install PHP on Ubuntu before you add the extension.

sudo apt install php8.5-imagick

On Ubuntu 24.04, relevant output includes:

The following NEW packages will be installed:
	imagemagick-6-common libfftw3-double3 liblqr-1-0 libmagickcore-6.q16-7t64
	libmagickwand-6.q16-7t64 libraw23t64 libsodium23 php-common php8.5-cli
	php8.5-common php8.5-imagick php8.5-phpdbg php8.5-readline
0 upgraded, 13 newly installed, 0 to remove and 41 not upgraded.

Verify the module with the versioned PHP binary that matches the package you installed:

php8.5 -m | grep -x imagick
imagick

If you install a different branch, change both the package name and the CLI binary to match, such as php8.4-imagick with php8.4 -m.

Troubleshoot PHP-Imagick on Ubuntu

Most failures come from a branch mismatch between the active PHP runtime and the installed extension package, or from a web SAPI that has not been restarted yet.

Fix the Class Imagick Not Found Error on Ubuntu

List the installed Imagick packages first, then compare that result with the PHP branch your application actually uses.

dpkg -l 'php*-imagick' | grep '^ii'

On Ubuntu 26.04, relevant output includes:

ii  php-imagick    3.8.0-3ubuntu1 all          Provides a wrapper to the ImageMagick library
ii  php8.5-imagick 3.8.0-3ubuntu1 amd64        Provides a wrapper to the ImageMagick library

If the host runs PHP 8.3 but only php8.5-imagick is installed, install the matching extension package instead. When the CLI check is correct but the website still fails, restart the matching PHP-FPM service such as php8.5-fpm, php8.3-fpm, or php8.1-fpm, or restart apache2 when Apache serves PHP directly.

Inspect PHP-Imagick Configuration on Ubuntu

Use PHP’s module information view when you need to confirm the extension version and the ImageMagick library it is linked against.

php --ri imagick | sed -n '1,8p'

On Ubuntu 26.04, relevant output includes:

imagick

imagick module => enabled
imagick module version => 3.8.0
imagick classes => Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator, ImagickKernel
Imagick compiled with ImageMagick version => ImageMagick 7.1.2-13 Q16 x86_64 23522 https://imagemagick.org
Imagick using ImageMagick library version => ImageMagick 7.1.2-15 Q16 x86_64 23686 https://imagemagick.org

If you installed a version-specific PPA branch, run the same command with that binary, such as php8.5 --ri imagick.

Update or Remove PHP-Imagick on Ubuntu

APT handles both update and removal cleanly, but review any autoremove list before you confirm it on a host that already runs other PHP workloads.

Update PHP-Imagick on Ubuntu

Use the package name that matches the source you installed from.

sudo apt update && sudo apt install --only-upgrade php-imagick
sudo apt update && sudo apt install --only-upgrade php8.5-imagick

The first command updates Ubuntu’s default package. The second updates the version-specific PPA package, so replace 8.5 with the branch you actually use.

Remove PHP-Imagick on Ubuntu

Remove the extension package first, then run autoremove only after you review the list of dependencies that would also be removed.

sudo apt remove php-imagick
sudo apt autoremove

If you installed a version-specific PPA package, remove that branch directly:

sudo apt remove php8.5-imagick

Confirm that Ubuntu no longer has the generic package installed:

apt-cache policy php-imagick
php-imagick:
	Installed: (none)
	Candidate: 3.8.0-3ubuntu1
	Version table:
		 3.8.0-3ubuntu1 500
				500 http://au.archive.ubuntu.com/ubuntu resolute/universe amd64 Packages

If you removed a version-specific branch instead, swap the package name in the same check, such as apt-cache policy php8.5-imagick.

Remove the Ondrej PHP PPA from Ubuntu

Delete the PPA only if you no longer need any of its PHP packages, then refresh APT so Ubuntu stops reading that source.

sudo add-apt-repository -y --remove ppa:ondrej/php
sudo apt update

Ubuntu 24.04 removes the generated .sources file, while Ubuntu 22.04 removes the generated .list file. Check that no Ondrej source remains:

grep -R "ppa.launchpadcontent.net/ondrej/php" /etc/apt/sources.list /etc/apt/sources.list.d 2>/dev/null
No output

PHP-Imagick on Ubuntu FAQ

Do I need the Ondrej PPA to install PHP-Imagick on Ubuntu?

No. Ubuntu 26.04, 24.04, and 22.04 already provide php-imagick in the Universe repository. Use the Ondrej PHP PPA only on Ubuntu 24.04 or 22.04 when you need a version-specific branch such as php8.4-imagick or php8.5-imagick.

Is php-imagick the same as ImageMagick on Ubuntu?

No. php-imagick is the PHP extension that talks to the ImageMagick libraries, while ImageMagick itself provides the standalone command-line tools such as magick and related utilities.

Should I install php-imagick or a versioned package such as php8.5-imagick on Ubuntu?

Use php-imagick when the host stays on Ubuntu’s default PHP branch. Use a versioned package such as php8.5-imagick or php8.4-imagick only when Ubuntu 24.04 or 22.04 already runs that matching PHP branch from the Ondrej PPA.

Why does the Ondrej PHP PPA fail on Ubuntu 26.04?

The PPA does not currently publish a resolute Release file, so apt update rejects it on Ubuntu 26.04. Stay with Ubuntu’s stock php-imagick and php8.5-imagick packages on 26.04 until the PPA adds native support.

Conclusion

PHP-Imagick is installed on Ubuntu and ready for thumbnails, format conversion, and other image-processing work inside your PHP stack. If the host still needs the base runtime, install PHP on Ubuntu, then pair it with install Nginx on Ubuntu or install Apache on Ubuntu depending on the web server you run.

Search LinuxCapable

Need another guide?

Search LinuxCapable for package installs, commands, troubleshooting, and follow-up guides related to what you just read.

Found this guide useful?

Support LinuxCapable to keep tutorials free and up to date.

Buy me a coffee Buy me a coffee

Before commenting, please review our Comments Policy.
Formatting tips for your comment

You can use basic HTML to format your comment. Useful tags currently allowed:

You type Result
<code>command</code> command
<strong>bold</strong> bold
<em>italic</em> italic
<blockquote>quote</blockquote> quote block

Leave a Comment

We read and reply to every comment - let us know how we can help or improve this guide.

Let us know you are human: