解决Fatal error: Uncaught Error: Class ‘Imagick‘ not found

龚联
2023-12-01

原因

php需要安装Imagick扩展

环境

CentOS Linux release 7.9
PHP 7.3.26

安装步骤

根据环境下载合适 imagemagick程序 和 imagick扩展

安装ImageMagic

wget http://www.imagemagick.org/download/ImageMagick.tar.gz

tar zxvf ImageMagick.tar.gz 
cd ImageMagick-7.1.0-8/
./configure --prefix=/usr/local/webservice/imagemagick
make && make install

检查是否安装成功

/usr/local/webservice/imagemagick/bin/convert -version

Version: ImageMagick 7.1.0-8 Q16-HDRI x86_64 2021-09-18 https://imagemagick.org
Copyright: (C) 1999-2021 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI OpenMP(3.1) 
Delegates (built-in): fontconfig freetype jng jpeg lzma png x xml zlib
Compiler: gcc (4.8)

安装php扩展:imagick

下载地址

https://pecl.php.net/package/imagick
查看适合版本下载

 wget https://pecl.php.net/get/imagick-3.5.1.tgz
 tar zxvf imagick-3.5.1.tgz

cd imagick-3.5.1/
/usr/local/webservice/php73/bin/phpize
./configure --with-php-config=/usr/local/webservice/php73/bin/php-config --with-imagick=/usr/local/webservice/imagemagick
make && make install

安装成功显示

Build complete.
Don't forget to run 'make test'.

Installing shared extensions:     /usr/local/webservice/php73/lib/php/extensions/no-debug-zts-20180731/
Installing header files:          /usr/local/webservice/php73/include/php/

修改配置文件,将extension=imagick.so写进去

vim /usr/local/webservice/php73/etc/php.ini
末尾加上
extension=/usr/local/webservice/php73/lib/php/extensions/no-debug-zts-20180731/imagick.so

重启php-fpm,测试是否安装成功
systemctl restart php-fpm

php -m | grep imagick

 类似资料: