Image uploads, thumbnail generation, and PDF previews usually fail in PHP applications when the Imagick extension is missing. To install PHP-Imagick on Ubuntu, use the php-imagick package from Ubuntu’s Universe component when your server follows the default PHP branch for Ubuntu 26.04, 24.04, or 22.04.
That default-package path matters because current Sury-based PHP branch workflows use packages.sury.org for the PHP runtime, but as of May 15, 2026, those Ubuntu indexes do not publish versioned Imagick packages such as php8.5-imagick, php8.4-imagick, or php8.3-imagick. If you need the standalone ImageMagick command-line tools instead of the PHP binding, use the separate guide to install ImageMagick on Ubuntu.
Choose the PHP-Imagick Package on Ubuntu
Start by matching the extension package to the PHP branch that actually serves the application. Ubuntu’s default PHP branch changes by release, while Sury packages let you install alternate PHP branches without necessarily providing every optional extension package.
| Ubuntu Release | Default PHP Branch | Archive Imagick Package | Best Path |
|---|---|---|---|
| Ubuntu 26.04 LTS | PHP 8.5 | php-imagick pulls php8.5-imagick | Use Ubuntu’s Universe package for the default PHP stack |
| Ubuntu 24.04 LTS | PHP 8.3 | php-imagick pulls php8.3-imagick | Use Ubuntu’s Universe package unless you intentionally run another PHP branch |
| Ubuntu 22.04 LTS | PHP 8.1 | php-imagick pulls php8.1-imagick | Use Ubuntu’s Universe package for the default PHP stack |
| Sury PHP branch on Ubuntu | PHP 8.5, 8.4, 8.3, or 8.2 | No current direct Sury Imagick package in the checked Ubuntu indexes | Check the candidate first and avoid mixing the older Launchpad PPA beside Sury |
Ubuntu’s package search for php-imagick is the package-source reference for the default branch. If your host still needs the PHP runtime itself, start with the broader guide to install PHP on Ubuntu.
If the server intentionally uses a Sury PHP runtime, keep that runtime setup aligned with the matching branch guide for PHP 8.5 on Ubuntu, PHP 8.4 on Ubuntu, PHP 8.3 on Ubuntu, or PHP 8.2 on Ubuntu, then check whether Imagick has a real candidate from the active package sources.
Install PHP-Imagick from Ubuntu’s Archive
Refresh APT metadata before checking the package candidate.
sudo apt update
These commands use
sudofor 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 supported Ubuntu LTS releases. Most standard installs already have that component enabled, but if APT cannot find php-imagick, enable Universe first. The guide to enable Universe and Multiverse in Ubuntu covers the repository component step; only Universe is required for this package.
Confirm that the package candidate comes from Ubuntu’s archive before installing it.
apt-cache policy php-imagick
On Ubuntu 26.04, relevant output includes:
php-imagick:
Installed: (none)
Candidate: 3.8.0-3ubuntu1
Version table:
3.8.0-3ubuntu1 500
500 http://archive.ubuntu.com/ubuntu resolute/universe amd64 Packages
Install the PHP CLI package with Imagick on clean hosts. Including php-cli gives you a direct verification command and avoids letting APT satisfy the generic PHP dependency through an Apache-only path.
sudo apt install php-cli php-imagick
On Ubuntu 26.04, relevant output includes:
The following NEW packages will be installed: php-cli php-common php-imagick php8.5-cli php8.5-common php8.5-imagick php8.5-readline
APT also installs the ImageMagick libraries that the PHP extension needs. The exact library package names differ by Ubuntu release because Ubuntu 26.04 uses ImageMagick 7, while Ubuntu 24.04 and 22.04 use ImageMagick 6.
Verify that the active CLI SAPI loads the extension. The grep exact-match pattern in Linux keeps the result to the single module name.
php -m | grep -x imagick
imagick
For WordPress sites, this package is one part of the wider PHP-FPM extension set. The full guide to install WordPress with Nginx, MariaDB, and PHP-FPM on Ubuntu shows it beside the web server, database, upload limits, and PHP-FPM socket configuration.
Check Versioned PHP-Imagick Candidates
Use versioned package names only when they match an enabled package source and the PHP branch that serves your application. On Ubuntu’s default branches, the matching versioned package appears from Ubuntu’s archive. In the direct Sury Ubuntu indexes checked on May 15, 2026, versioned Imagick package names had no candidate.
for pkg in php8.5-imagick php8.4-imagick php8.3-imagick php8.2-imagick php8.1-imagick; do
candidate="$(apt-cache policy "$pkg" | sed -n 's/^[[:space:]]*Candidate: //p')"
if [ -n "$candidate" ] && [ "$candidate" != "(none)" ]; then
printf '%s candidate: %s\n' "$pkg" "$candidate"
else
printf '%s has no candidate from enabled sources.\n' "$pkg"
fi
done
On Ubuntu 26.04 with only Ubuntu’s archive enabled, relevant output includes:
php8.5-imagick candidate: 3.8.0-3ubuntu1 php8.4-imagick has no candidate from enabled sources. php8.3-imagick has no candidate from enabled sources. php8.2-imagick has no candidate from enabled sources. php8.1-imagick has no candidate from enabled sources.
On Ubuntu 24.04, php8.3-imagick is the archive package because PHP 8.3 is that release’s default branch. On Ubuntu 22.04, the matching archive package is php8.1-imagick. If a non-default Sury branch such as PHP 8.4 needs Imagick and no package candidate exists, do not add the older Launchpad PHP PPA beside the direct Sury repository just to satisfy one extension name; that mixed-source setup can make PHP candidates and updates harder to reason about.
Restart PHP-FPM or Apache After Installing Imagick
The CLI check proves the extension loads in terminal PHP. Web requests still use the PHP handler behind your site, so restart the matching service after installing or changing the extension.
systemctl list-units 'php*-fpm.service' --state=running --no-pager
If PHP-FPM is running, restart the unit that matches the active PHP branch. The small detection block keeps the service name aligned across Ubuntu 26.04, 24.04, and 22.04.
php_branch="$(php -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')"
sudo systemctl restart "php${php_branch}-fpm"
If Apache serves PHP through mod_php instead of PHP-FPM, restart Apache with
sudo systemctl restart apache2. For Nginx or Apache stacks that need a cleaner PHP-FPM handoff, use the guide to configure PHP-FPM on Ubuntu.
Troubleshoot PHP-Imagick on Ubuntu
Most Imagick failures come from a PHP branch mismatch, an extension package that belongs to a different source, or a web SAPI that has not been restarted since installation.
Fix the Class Imagick Not Found Error
Compare the PHP branch in use with the installed Imagick packages.
php -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION.PHP_EOL;'
dpkg -l 'php*-imagick' | grep '^ii'
On Ubuntu 26.04, relevant output includes:
8.5 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 PHP reports one branch but the installed Imagick package belongs to another, install the package that matches the active branch when a candidate exists. If the CLI check works but the website still fails, restart the matching PHP-FPM service or Apache handler so the web process loads the new module.
Inspect PHP-Imagick Configuration
Use PHP’s module information view when you need to confirm the extension version and the ImageMagick library linked behind it.
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
For a versioned PHP binary, run the same check with that command name, such as php8.3 --ri imagick on Ubuntu 24.04.
Fix Missing Sury or PPA Package Candidates
If APT cannot locate a versioned package such as php8.4-imagick, inspect the enabled PHP package sources before adding another repository.
grep -R -E "ondrej/php|packages[.]sury[.]org/php" /etc/apt/sources.list /etc/apt/sources.list.d/ 2>/dev/null
A direct Sury source usually appears as a DEB822 file similar to this:
/etc/apt/sources.list.d/php.sources:URIs: https://packages.sury.org/php/
If the output also shows ppa.launchpadcontent.net/ondrej/php, decide which source should own the server’s PHP packages before continuing. Current Sury branch workflows should keep the direct packages.sury.org source and avoid the older Launchpad PPA unless the whole PHP stack was intentionally built around that PPA and you have tested its package set for your release.
Update or Remove PHP-Imagick on Ubuntu
APT handles updates and removal for Ubuntu’s Imagick packages. Review removal prompts carefully on shared web servers because dependencies can be used by more than one PHP application.
Update PHP-Imagick on Ubuntu
Refresh package metadata, then upgrade the installed Imagick package.
sudo apt update
sudo apt install --only-upgrade php-imagick
If you installed the versioned archive package directly, replace the package name with the branch that appears in dpkg -l 'php*-imagick', such as php8.5-imagick on Ubuntu 26.04.
Remove PHP-Imagick on Ubuntu
Remove the extension package first, then run autoremove only after you review the dependency list APT proposes.
sudo apt remove php-imagick
sudo apt autoremove
If you installed a versioned package directly, remove that branch package instead.
sudo apt remove php8.5-imagick
Confirm that no Imagick package remains installed.
dpkg -l 'php*-imagick' | grep '^ii'
If the command prints nothing, no matching Imagick package remains installed.
Remove a Legacy Ondrej PHP PPA Source
Remove the older Launchpad PHP PPA only when no installed PHP package still depends on it. Keep Sury repository cleanup separate from Imagick removal because other PHP branches may still receive APT-managed updates through Sury.
grep -R -E "ppa.launchpadcontent.net/ondrej/php|ondrej/php" /etc/apt/sources.list /etc/apt/sources.list.d/ 2>/dev/null
If that search returns only the old Launchpad PPA and you no longer need it, remove the PPA and refresh APT. The dedicated guide to remove a PPA from Ubuntu covers additional cleanup checks for manually edited source files.
sudo add-apt-repository --remove ppa:ondrej/php -y
sudo apt update
Conclusion
PHP-Imagick is ready on Ubuntu when the installed extension package, PHP branch, and web handler all match. Use Ubuntu’s php-imagick package for default PHP stacks on Ubuntu 26.04, 24.04, and 22.04, check versioned candidates before touching alternate PHP branches, and keep old Launchpad PPA sources out of direct Sury setups unless the whole server has been tested around that source.


Formatting tips for your comment
You can use basic HTML to format your comment. Useful tags currently allowed in published comments:
<code>command</code>command<strong>bold</strong><em>italic</em><blockquote>quote</blockquote>