How to Install PHP-IMAGICK on Debian 13, 12 and 11

Learn how to install PHP-Imagick on Debian 13, 12, or 11 using APT or the Ondřej Surý repository for image processing in PHP apps.

UpdatedPublished AuthorJoshua JamesRead time9 minGuide typeDebian

Image uploads, thumbnail generation, and PDF previews usually fail in PHP applications when the Imagick extension is missing. To install PHP-Imagick on Debian, use the default php-imagick package when the server follows Debian’s PHP branch, or use a versioned Sury package such as php8.5-imagick, php8.4-imagick, or php8.2-imagick when the PHP runtime came from the Sury repository.

The package names are easy to mix up. php-imagick installs the PHP extension that lets PHP code call ImageMagick libraries; it is not the standalone magick or convert command-line toolkit. If your goal is shell-based image conversion rather than PHP integration, install ImageMagick on Debian instead.

Install PHP-Imagick on Debian

Pick the package source before installing anything. Debian’s default package is the safer choice for most servers because APT keeps the extension aligned with Debian’s PHP branch. Sury is useful when your application already runs a non-default PHP branch, but the extension package must match that exact branch.

Choose the Correct PHP-Imagick Package

Use the package name that matches the PHP runtime serving your application. Installing the wrong branch can make php -m look correct in one PHP binary while PHP-FPM, Apache, or a web application still reports that the Imagick class is missing.

PackageSourceWhat It InstallsUse When
php-imagickDebian packagesThe Imagick extension for Debian’s default PHP branch.The server uses Debian’s packaged PHP runtime.
php8.5-imagick, php8.4-imagick, php8.3-imagick, or similarSury PHP repositoryThe Imagick extension for one exact Sury PHP branch.The server already uses, or needs, that Sury PHP branch.
imagemagickDebian packagesThe standalone ImageMagick command-line tools.You need magick, convert, or batch image commands outside PHP.

Debian 13 (Trixie) maps php-imagick to the PHP 8.4 extension package. Debian 12 (Bookworm) maps it to PHP 8.2. Debian 11 (Bullseye) installs the PHP 7.4-compatible extension package. Those defaults are fine for applications that use Debian’s PHP stack, but they are not enough for a Sury-managed PHP 8.5, 8.4, 8.3, or 8.2 stack unless the active branch matches.

The upstream PECL Imagick package can move ahead of Debian’s packaged version. For normal Debian servers, stay with APT-managed packages unless you intentionally want to own extension builds, PHP development headers, rebuilds after PHP upgrades, and manual cleanup. Check the installed extension with php --ri imagick instead of assuming the newest PECL release is the version Debian or Sury installed.

Use one PHP package source for a given branch. Mixing Debian PHP packages and Sury PHP packages on the same branch can leave extensions, SAPIs, and module directories out of sync. If you use Sury for PHP itself, install the matching Sury extension package too.

Install PHP-Imagick from Debian’s Default APT Sources

Refresh APT metadata so the package manager sees the current Debian archive state:

sudo apt update

These commands use sudo for package-manager tasks that need root privileges. If your account cannot use sudo yet, add a user to sudoers on Debian before continuing.

Install Debian’s generic Imagick package:

sudo apt install php-imagick

A clean install also pulls the PHP CLI package for the default branch when PHP is not already present. Debian 13 installs the PHP 8.4 CLI and php8.4-imagick, Debian 12 installs PHP 8.2 and php8.2-imagick, and Debian 11 installs PHP 7.4-compatible Imagick support. For a fuller web-stack setup before adding extensions, install PHP on Debian first, then return to Imagick after the active PHP branch is clear.

Confirm that the PHP command-line runtime can load the extension:

php -m | grep -x imagick
imagick

For a slightly clearer first-use check, ask PHP to test the extension directly:

php -r 'echo extension_loaded("imagick") ? "imagick loaded\n" : "imagick missing\n";'
imagick loaded

These checks prove the CLI SAPI can load Imagick. Web requests still run through PHP-FPM, Apache mod_php, or another SAPI, so restart the web-serving PHP process after installing the extension.

Install Version-Specific PHP-Imagick from the Sury Repository

Use the Sury repository when your PHP branch does not come from Debian’s default packages. Common examples include a Debian 12 server running PHP 8.4 or 8.5, or a Debian 11 server kept on a specific Sury branch for application compatibility.

Install the small tools needed for HTTPS downloads and repository setup:

sudo apt update
sudo apt install ca-certificates curl

Sury publishes a keyring package for its repository signing key. Download and install that package before writing the APT source file:

curl -fsSLo /tmp/debsuryorg-archive-keyring.deb https://packages.sury.org/debsuryorg-archive-keyring.deb
sudo apt install /tmp/debsuryorg-archive-keyring.deb
rm -f /tmp/debsuryorg-archive-keyring.deb

The curl -fsSLo options make the download fail on HTTP errors, keep normal output quiet, show errors, follow redirects, and save the file to the exact path used by the install command. Installing the local .deb with APT keeps dependency handling inside the package manager.

Detect the Debian codename from /etc/os-release. This works on minimal Debian systems without installing lsb-release:

CODENAME=$(. /etc/os-release && echo "$VERSION_CODENAME")
printf '%s\n' "$CODENAME"
trixie

Your system prints trixie, bookworm, or bullseye. Keep the same terminal session for the next command so the CODENAME variable remains available.

Write the Sury repository as a DEB822 source file:

printf '%s\n' \
"Types: deb" \
"URIs: https://packages.sury.org/php/" \
"Suites: ${CODENAME}" \
"Components: main" \
"Signed-By: /usr/share/keyrings/debsuryorg-archive-keyring.gpg" | sudo tee /etc/apt/sources.list.d/sury-php.sources > /dev/null

The printf | sudo tee form writes a root-owned file without relying on a shell redirection that would run as your normal user. This DEB822 file uses the same Sury repository and keyring path as the keyring package while keeping the source easy to audit and remove later.

Inspect the source file before refreshing APT:

cat /etc/apt/sources.list.d/sury-php.sources
Types: deb
URIs: https://packages.sury.org/php/
Suites: trixie
Components: main
Signed-By: /usr/share/keyrings/debsuryorg-archive-keyring.gpg

Refresh APT and verify the package name for the PHP branch you use. The example checks PHP 8.5 because Sury currently publishes that branch, but you can set php_branch to 8.4, 8.3, 8.2, or another branch that exists in the Sury metadata.

sudo apt update
php_branch=8.5
apt-cache policy "php${php_branch}-imagick"

The policy output should show a candidate from https://packages.sury.org/php. Do not install the unversioned php-imagick package from Sury unless you intentionally want Sury’s current default PHP branch. Use a versioned package name to keep the extension tied to the runtime already serving your application.

When you want to inspect the dependency transaction before changing the host, simulate the install first:

apt-get -s install "php${php_branch}-imagick"

If the PHP runtime itself is not installed yet, use the branch-specific Debian PHP guide before adding Imagick: install PHP 8.5 on Debian, install PHP 8.4 on Debian, install PHP 8.3 on Debian, or install PHP 8.2 on Debian.

Install the matching versioned extension package:

sudo apt install "php${php_branch}-imagick"

Confirm that the active PHP CLI branch can load Imagick:

php -v | head -n 1
php -m | grep -x imagick

If the first line reports a different PHP branch than the package you installed, call the versioned binary directly, such as php8.5 -m or php8.4 -m. The web-facing SAPI must also use that same branch.

Get Started with PHP-Imagick on Debian

After installation, check the extension from the same PHP context your application uses. A terminal check is useful, but it only proves the CLI SAPI. Web applications can still fail until PHP-FPM or Apache reloads the extension.

Inspect the Loaded Imagick Module

Use php --ri when you need the extension version and the linked ImageMagick library:

php --ri imagick | grep -E '^(imagick module|Imagick using)'

Debian 13 uses ImageMagick 7 libraries for the default extension, while Debian 12 and Debian 11 use ImageMagick 6 libraries. That difference matters when an application depends on behavior or policy defaults that changed between ImageMagick major versions.

Check Which PHP Binary Your Shell Uses

Servers with several PHP branches can make php point to a different binary than the web server uses. Check the CLI binary and version before interpreting module output:

command -v php
php -v | head -n 1

For Sury branches, versioned commands such as php8.5, php8.4, and php8.2 let you test the exact runtime without changing the system default:

php8.5 -m | grep -x imagick

Use the branch that actually serves the application. A Nextcloud, WordPress, Laravel, or custom PHP site may run through PHP-FPM even when your terminal uses a different default PHP binary.

Confirm Basic Class Availability

When an application reports Class "Imagick" not found, test the class from PHP itself:

php -r 'echo class_exists("Imagick") ? "Imagick class available\n" : "Imagick class missing\n";'
Imagick class available

If the CLI class check passes but the web application still fails, the extension is installed but the web-serving PHP process has not loaded it yet, or the web server is using a different PHP branch.

Troubleshoot PHP-Imagick on Debian

Most Imagick failures come from one of four causes: the extension package is missing, the installed package targets the wrong PHP branch, the web SAPI has not restarted, or the application is asking for the ImageMagick command-line tools instead of the PHP extension.

Restart PHP-FPM After Installing PHP-Imagick

If CLI checks show imagick but the website does not, restart the PHP-FPM service for the active branch. List installed PHP-FPM services first so you do not restart the wrong version:

systemctl list-units --type=service --all 'php*-fpm.service'

Restart the service that matches the web application. For Debian 13’s default branch, that usually means PHP 8.4:

sudo systemctl restart php8.4-fpm
systemctl is-active php8.4-fpm
active

Use php8.2-fpm on Debian 12’s default branch, php7.4-fpm on Debian 11’s default branch, or the Sury branch that your application actually uses. For a full FastCGI handoff, use the dedicated guide to configure Nginx with PHP-FPM.

Restart Apache When Using mod_php

Apache hosts that use libapache2-mod-php load PHP inside Apache instead of through PHP-FPM. Restart Apache after installing or changing the extension package:

sudo systemctl restart apache2
systemctl is-active apache2

If the server still needs a web stack, install the server first with the Debian guides for Nginx or Apache, then return to the matching PHP-FPM or Apache module step.

Fix Class Imagick Not Found

The Class "Imagick" not found error usually means the active PHP branch cannot load the extension. Compare the PHP branch with the installed Imagick package names:

php -v | head -n 1
dpkg-query -W -f='${db:Status-Abbrev} ${binary:Package} ${Version}\n' 'php*imagick' 2>/dev/null | grep '^ii'

If PHP reports 8.5 but only php8.2-imagick is installed, install php8.5-imagick from Sury. If PHP reports Debian’s default branch, install or reinstall Debian’s php-imagick package.

sudo apt install php-imagick

For Sury, use the versioned branch package instead:

sudo apt install php8.5-imagick

Restart PHP-FPM or Apache after changing the package so the web SAPI loads the module.

Fix Optional Module Imagick Is Not Installed or Disabled

Applications such as Nextcloud can report that the optional Imagick module is missing even after package installation. Start by checking whether PHP sees the module:

php -m | grep -x imagick

If the package is installed but the module was disabled manually, re-enable it for the default PHP configuration:

sudo phpenmod imagick
php -m | grep -x imagick

On a server with several PHP branches, enable the module for the branch that serves the application and test that same branch:

sudo phpenmod -v 8.5 imagick
php8.5 -m | grep -x imagick

Then restart the web-serving PHP process. For PHP-FPM, restart the branch-specific service such as php8.4-fpm or php8.5-fpm. For Apache mod_php, restart apache2. If an application says it needs Imagick or GD, choose the backend the application documentation recommends; this article covers Imagick, not the separate GD extension.

Use ImageMagick CLI Tools When PHP Is Not the Problem

Some application errors mention ImageMagick when they need command-line tools, not the PHP extension. Check whether the application expects a binary such as magick or convert:

command -v magick || command -v convert

If neither command exists and the application documentation asks for ImageMagick binaries, use the dedicated ImageMagick guide instead of adding more PHP extension packages.

Update or Remove PHP-Imagick on Debian

APT owns updates and removals for both Debian and Sury package methods. The important difference is the package name: Debian’s default method uses php-imagick, while Sury branch installs use versioned package names.

Update PHP-Imagick

Update Debian’s default package with a targeted APT upgrade:

sudo apt update
sudo apt install --only-upgrade php-imagick

For Sury, update the versioned package that matches the installed PHP branch:

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

Replace 8.5 with the branch you use. If a package is already current, APT reports that nothing needs to change.

Remove PHP-Imagick

Remove Debian’s default package with APT:

sudo apt remove php-imagick

Remove a Sury branch package by its versioned name:

sudo apt remove php8.5-imagick

Review optional dependencies that APT now considers unused:

apt-get -s autoremove

Autoremove can remove PHP CLI packages and ImageMagick libraries that were installed only to satisfy Imagick dependencies on a minimal host. Review the package list before running a real autoremove on a server that also runs PHP applications, web stacks, or image-processing tools.

If the simulated list contains only packages you no longer need, run the real cleanup:

sudo apt autoremove

Confirm that Debian’s default package is no longer installed. This check proves installed state, not just package availability in the archive:

dpkg-query -W -f='${db:Status-Abbrev} ${binary:Package}\n' php-imagick 2>/dev/null | grep '^ii' || echo "php-imagick is not installed"
php-imagick is not installed

For a Sury branch package, check the versioned package name instead:

dpkg-query -W -f='${db:Status-Abbrev} ${binary:Package}\n' php8.5-imagick 2>/dev/null | grep '^ii' || echo "php8.5-imagick is not installed"
php8.5-imagick is not installed

Remove the Sury PHP Repository

Remove the Sury source only when no installed PHP packages still depend on that repository for updates. If the server still runs Sury PHP, keep the source enabled.

Delete the DEB822 source file and refresh APT:

sudo rm -f /etc/apt/sources.list.d/sury-php.sources
sudo apt update

Verify that the versioned package candidate no longer comes from Sury. Replace 8.5 with the branch you removed:

apt-cache policy php8.5-imagick | grep -F "packages.sury.org/php" || echo "No Sury candidate found for php8.5-imagick"
No Sury candidate found for php8.5-imagick

Remove the Sury keyring package only after no remaining source file references its keyring:

find /etc/apt/sources.list /etc/apt/sources.list.d -type f -print 2>/dev/null | xargs -r grep -H "debsuryorg-archive-keyring.gpg"

If that check prints no source file, purge the keyring package so the repository trust package does not remain in residual-config state:

if dpkg-query -W -f='${db:Status-Abbrev}\n' debsuryorg-archive-keyring 2>/dev/null | grep -Eq '^(ii|rc)'; then
  sudo apt purge debsuryorg-archive-keyring
else
  echo "debsuryorg-archive-keyring is not installed"
fi

Check that the Sury PHP source no longer appears in APT source files:

if grep -R "packages.sury.org/php" /etc/apt/sources.list /etc/apt/sources.list.d 2>/dev/null; then
  echo "Sury source is still configured"
else
  echo "Sury source not found"
fi
Sury source not found

Run sudo apt update again after any source cleanup if APT reports stale metadata or missing package candidates.

Conclusion

PHP-Imagick is installed on Debian with the package source matched to the active PHP branch. Debian’s default package covers the distro PHP stack, while Sury’s versioned packages cover alternate branches. After the module loads in CLI and the web SAPI has restarted, image previews, thumbnails, and PHP image-processing workflows can use Imagick without a separate PECL build.

Share this guide

Help another Linux user troubleshoot faster

Share this guide with someone troubleshooting Linux systems or saving it for later.

Follow LinuxCapable

Want more LinuxCapable guides in Google?

Add LinuxCapable as a preferred source so Google can show more of our fresh Linux tutorials in Top Stories and From your sources when relevant.

Add LinuxCapable as a preferred source on Google
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 coffeeBuy 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 in published comments:

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

Got a Question or Feedback?

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

Let us know you are human: