Fatal error: Uncaught Error: Class 'Imagick' not found in /var/www/app/src/Image/ThumbnailGenerator.php:25
ID: php/imagick-extension-missing
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| php:8.1.0 | active | — | — | — |
| php:8.2.0 | active | — | — | — |
| php:8.3.0 | active | — | — | — |
Root Cause
The Imagick PHP extension is not installed or enabled on the server, so PHP cannot load the Imagick class for image manipulation.
generic中文
服务器上未安装或未启用 Imagick PHP 扩展,因此 PHP 无法加载用于图像处理的 Imagick 类。
Official Documentation
https://www.php.net/manual/en/imagick.installation.phpWorkarounds
-
95% success Install the Imagick extension on Ubuntu/Debian: 'sudo apt-get install php-imagick' or for a specific PHP version 'sudo apt-get install php8.2-imagick'. Then restart the web server: 'sudo systemctl restart apache2' or 'sudo systemctl restart php8.2-fpm'.
Install the Imagick extension on Ubuntu/Debian: 'sudo apt-get install php-imagick' or for a specific PHP version 'sudo apt-get install php8.2-imagick'. Then restart the web server: 'sudo systemctl restart apache2' or 'sudo systemctl restart php8.2-fpm'.
-
90% success If using a Docker container, add to your Dockerfile: 'RUN apt-get update && apt-get install -y libmagickwand-dev && pecl install imagick && docker-php-ext-enable imagick'
If using a Docker container, add to your Dockerfile: 'RUN apt-get update && apt-get install -y libmagickwand-dev && pecl install imagick && docker-php-ext-enable imagick'
-
85% success Verify installation by creating a PHP file with '<?php phpinfo(); ?>' and searching for 'imagick' in the output, or run 'php -m | grep imagick' from the command line.
Verify installation by creating a PHP file with '<?php phpinfo(); ?>' and searching for 'imagick' in the output, or run 'php -m | grep imagick' from the command line.
中文步骤
在 Ubuntu/Debian 上安装 Imagick 扩展:'sudo apt-get install php-imagick' 或针对特定 PHP 版本 'sudo apt-get install php8.2-imagick'。然后重启 Web 服务器:'sudo systemctl restart apache2' 或 'sudo systemctl restart php8.2-fpm'。
如果使用 Docker 容器,在 Dockerfile 中添加:'RUN apt-get update && apt-get install -y libmagickwand-dev && pecl install imagick && docker-php-ext-enable imagick'
通过创建包含 '<?php phpinfo(); ?>' 的 PHP 文件并在输出中搜索 'imagick',或从命令行运行 'php -m | grep imagick' 来验证安装。
Dead Ends
Common approaches that don't work:
-
90% fail
Installing the imagick package via Composer (e.g., 'composer require imagick/imagick') does not install the underlying C extension; it only provides a PHP wrapper that still requires the extension to be installed at the system level.
-
80% fail
Adding 'extension=imagick.so' to php.ini without first installing the ImageMagick libraries (libmagickcore-dev, libmagickwand-dev) results in a PHP startup warning and the extension fails to load.
-
50% fail
Running 'php -m | grep imagick' to check if the extension is loaded, but the check may show it's missing even if the system has ImageMagick installed, because the PHP extension is a separate package.