简体   繁体   English

php 错误:未找到 Class 'Imagick'

[英]php error: Class 'Imagick' not found

I am getting the error "Class 'Imagick' not found".我收到错误“找不到类‘Imagick’”。 Somehow I need to make this library accessible to php.不知何故,我需要让 php 可以访问这个库。 I am using Php 5.2.6 on Fedora 8. my php_info has no mention of ImageMagick.我在 Fedora 8 上使用 Php 5.2.6。我的 php_info 没有提到 ImageMagick。

I have tried: yum install ImageMagick and restarted apache, which didn't work.我试过: yum install ImageMagick 并重新启动 apache,但没有用。

I also added extension=imagick.ext to my php.ini file and restarted apache, which didn't work.我还在我的 php.ini 文件中添加了 extension=imagick.ext 并重新启动了 apache,但没有成功。

For all to those having problems with this i did this tutorial: 对于所有对此有疑问的人,我做了本教程:

How to install Imagemagick and Php module Imagick on ubuntu? 如何在ubuntu上安装Imagemagick和Php模块Imagick?

i did this 7 simple steps: 我做了这7个简单的步骤:

Update libraries, and packages 更新库和包

apt-get update

Remove obsolete things 删除过时的东西

apt-get autoremove

For the libraries of ImageMagick 对于ImageMagick的库

apt-get install libmagickwand-dev

for the core class Imagick 对于Imagick的核心课程

apt-get install imagemagick

For create the binaries, and conections in beetween 用于创建二进制文件,以及之间的连接

pecl install imagick

Append the extension to your php.ini 将扩展名附加到您的php.ini

echo "extension=imagick.so" >> /etc/php5/apache2/php.ini

Restart Apache 重新启动Apache

service apache2 restart

I found a problem. 我发现了一个问题。 PHP searches for .so files in a folder called /usr/lib/php5/20100525, and the imagick.so is stored in a folder called /usr/lib/php5/20090626. PHP在名为/ usr / lib / php5 / 20100525的文件夹中搜索.so文件,而imagick.so存储在名为/ usr / lib / php5 / 20090626的文件夹中。 So you have to copy the file to that folder. 因此,您必须将文件复制到该文件夹​​。

From: http://news.ycombinator.com/item?id=1726074 来自: http : //news.ycombinator.com/item?id=1726074

For RHEL-based i386 distributions: 对于基于RHEL的i386发行版:

yum install ImageMagick.i386
yum install ImageMagick-devel.i386
pecl install imagick
echo "extension=imagick.so" > /etc/php.d/imagick.ini
service httpd restart

This may also work on other i386 distributions using yum package manager. 使用yum软件包管理器,这在其他i386发行版上也可能起作用。 For x86_64, just replace .i386 with .x86_64 对于x86_64,只需将.i386替换为.x86_64

Ubuntu 的Ubuntu

sudo apt-get install php5-dev pecl imagemagick libmagickwand-dev
sudo pecl install imagick
sudo apt-get install php5-imagick
sudo service apache2 restart

Some dependencies will probably already be met but excluding the Apache service, that's everything required for PHP to use the Imagick class. 一些依赖关系可能已经满足,但不包括Apache服务,这是PHP使用Imagick类所需的一切。

For MAMP running on Mac OSX 对于在Mac OSX上运行的MAMP

Find out the what version of PHP and install the right version via brew 找出什么版本的PHP并通过brew安装正确的版本

brew install homebrew/php/php56-imagick

Add the extension by modifying the php.ini template in MAMP 通过修改MAMP中的php.ini模板来添加扩展名

在此处输入图片说明

Verify the Imagick 验证Imagick

在此处输入图片说明

Debian 9 Debian 9

I just did the following and everything else needed got automatically installed as well. 我只是做了以下事情,其他所有需要的东西也都自动安装了。

sudo apt-get -y -f install php-imagick
sudo /etc/init.d/apache2 restart

在PHP7中安装Imagic:

sudo apt-get install php-imagick

Docker container installation for php:XXX Debian based images: 用于php:XXX基于Debian的映像的Docker容器安装:

RUN apt-get update && apt-get install -y --no-install-recommends libmagickwand-dev
RUN pecl install imagick && docker-php-ext-enable imagick
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* || true

On an EC2 at AWS, I did this: 在AWS的EC2上,我这样做:

 yum list | grep imagick

Then found a list of ones I could install... 然后找到了我可以安装的列表...

 php -v

told me which version of php I had and thus which version of imagick 告诉我我拥有哪个版本的php,以及哪个版本的imagick

yum install php56-pecl-imagick.x86_64

Did the trick. 做到了。 Enjoy! 请享用!

在 <= php7.0 中不支持 imagick 理想的解决方案是替代包请在这里找到这个https://github.com/DantSu/php-image-editor

Install Base Imagick Repos安装基础 Imagick 存储库

Many of these answers are great, if you are using PHP5, but PHP8 offers too many features to just pass up, and imagick is a bit different here.如果您使用的是 PHP5,这些答案中的许多都很棒,但是 PHP8 提供了太多的功能,而 imagick 在这里有点不同。

Install the base imagick repos:安装基础 imagick 存储库:

sudo apt-get install php8.0-imagick php8.1-imagick imagemagick php-imagick php-pear php-dev

Install Imagick's Extension into PHP将 Imagick 的扩展安装到 PHP

You may want to omit php8.1-imagick if you are not up to version 8.1 yet.如果您尚未升级到 8.1 版,您可能需要省略php8.1-imagick php-pear is where the pecl command lives, so, if that doesn't install correctly, you'll get an error when you need to do the next command... php-pearpecl命令所在的位置,因此,如果安装不正确,当您需要执行下一个命令时会出现错误...

sudo pecl install imagick

Update PHP.ini更新 PHP.ini

Find your php.ini file with...找到您的php.ini文件...

php -i | grep  -i php.ini

You may get output like...您可能会得到 output 之类的...

Configuration File (php.ini) Path => /etc/php/8.1/cli
Loaded Configuration File => /etc/php/8.1/cli/php.ini

Open this file and add to the end of the file this text: extension=imagick.so .打开此文件并将以下文本添加到文件末尾: extension=imagick.so

Restart PHP重启 PHP

Then restart your server.然后重启你的服务器。 Any of these will do:这些中的任何一个都可以:

systemctl restart apache2
/etc/init.d/apache2 restart
sudo service apache2 graceful

Check if the Install Worked检查安装是否有效

  • See the results of phpinfo() on a web page, which should mention imagick.在 web 页面上查看phpinfo()的结果,其中应该提到 imagick。
  • See the results of simulated phpinfo() info calls from the command line with php -r "echo phpinfo();" | grep 'imagick';使用php -r "echo phpinfo();" | grep 'imagick';从命令行查看模拟phpinfo()信息调用的结果php -r "echo phpinfo();" | grep 'imagick'; . .
  • See the internal storage of phpinfo() from the command line with php -i | grep 'imagick'使用php -i | grep 'imagick'从命令行查看phpinfo()的内部存储php -i | grep 'imagick' . php -i | grep 'imagick'
  • See the installed packages containing imagick in the name with dpkg --list | grep 'imagick'使用dpkg --list | grep 'imagick'查看名称中包含imagick的已安装软件包dpkg --list | grep 'imagick' . dpkg --list | grep 'imagick'

Note: These are all important, because while I was debugging, I was able to see Imagick installed at lower layers (ie with dpkg ), but was not seeing it in the higher layers (ie with phpinfo(); through webhost).注意:这些都很重要,因为当我调试时,我能够看到 Imagick 安装在较低层(即使用dpkg ),但在较高层没有看到它(即使用phpinfo();通过 webhost)。 Cheers.干杯。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM