无法在树莓派OS(Debian 10)和PHP 8.2上加载/运行Imagick。

huangapple go评论62阅读模式
英文:

Cannot load/run Imagick on Raspberry OS (Debian 10) and PHP 8.2

问题

背景

亲爱的各位,

我已经在我的Raspbian OS上安装了PHP 8.2(某些库要求PHP 8.x)。我需要安装PHP imagemagick扩展以转换图像(SVG到PNG)。然而,我无法使它正常运行。

这是我尝试的

首先,我安装了imagemagick(不知道是否必要,但为了安全起见):

$ sudo apt install imagemagick

这是成功的。没有其他可用的软件包:

$ sudo apt install imagemagick -a
imagemagick/oldstable,now 8:6.9.10.23+dfsg-2.1+deb10u1 armhf  [已安装]

其次,我安装了Imagick:

$ sudo apt install php-imagick

这也成功了。没有其他可用的软件包:

$ sudo apt list php-imagick -a
php-imagick/oldstable,now 3.4.3-4.1 armhf [已安装]

我在我的php.ini中添加了以下条目:

[Imagick]
extension=imagick.so

最后,我重新启动了Apache:
$ sudo systemctl restart apache2

在故障排除过程中,我甚至重新启动了php:
$ sudo service php8.2-fpm reload

目前的问题和故障排除

Imagick没有出现,无论我尝试 php -r 'phpinfo();' | grep imagick 还是 php -m | grep imagick 都不行。

也就是说,当我执行 $im = new \Imagick(); 时会出现以下错误:

致命错误:未捕获的错误:未找到类"Imagick"

我已经研究了网页(包括https://stackoverflow.com/questions/3790191/php-error-class-imagick-not-found)和手册超过两个小时,但没有成功。非常感谢任何帮助/提示!

编辑:迄今为止找到的提示

也许一个提示是,imagick.so被安装在目录/usr/lib/php/20180731中,而当前的php扩展目录(根据php.ini)是/usr/lib/php/20220829。将文件复制到20220829(并重新启动服务)没有帮助。

另一个提示可能是,/etc/php/7.3/cli/conf.d 包含一个(链接文件)20-imagick.ini(指向 /etc/php/7.3/mods-available/imagick.ini),而/etc/php/8.2/cli/conf.d没有包含这样的链接,而/etc/php/8.2/mods-available也没有包含imagick.ini文件。同样适用于/etc/php/x.y/apache2/conf.d。这看起来很可疑,所以我复制了以下文件

/etc/php/7.3/mods-available/imagick.ini -> /etc/php/8.2/mods-available/imagick.ini [内容:extension=imagick.so]
/etc/php/7.3/cli/conf.d/20-imagick.ini -> /etc/php/8.2/cli/conf.d/20-imagick.ini
/etc/php/7.3/apache2/conf.d/20-imagick.ini -> /etc/php/8.2/apache2/conf.d/20-imagick.ini
/etc/php/7.3/fpm/conf.d/20-imagick.ini -> /etc/php/8.2/fpm/conf.d/20-imagick.ini
/usr/lib/php/20180731/imagick.so -> /usr/lib/php/20220829/imagick.so

在执行$ sudo systemctl restart apache2后,当我运行 $ php -m | grep imagick 时,现在会得到以下警告:

PHP警告:PHP启动:无法加载动态库'imagick.so'(尝试:/usr/lib/php/20220829/imagick.so (/usr/lib/php/20220829/imagick.so: 未定义符号: add_next_index_zval),/usr/lib/php/20220829/imagick.so.so (/usr/lib/php/20220829/imagick.so.so: 无法打开共享对象文件:没有这样的文件或目录))位于未知位置的第0行

也许由于某种原因,apt install和/或php-imagick认为我的当前php版本是7.3,因此它更新了错误的文件并取了错误的共享库(imagick.so),而实际上是8.2(7.3仍然安装但未激活,8.2已激活)?

找到了这个链接,至少与错误消息相匹配:https://stackoverflow.com/questions/65521238/the-propcedure-entry-point-add-index-zval-could-not-be-located-in-the-dynamic-li

可能的解决方案:根据更改日志https://pecl.php.net/package-changelog.php?package=imagick,我必须获得Imagick版本>=3.5.0,以便支持PHP 8.x(希望支持8.2)。

英文:

Background

Dear all,

I've installed PHP 8.2 on me Raspbian OS (PHP 8.x required by some libraries). I need to install the PHP imagemagick extension to convert images (SVG to PNG). However, I can't get it running.

Here is what i tried

Firstly, I installed imagemagick (don't know wheather that's necessary, but just to be on the safe side):

$ sudo apt install imagemagick

That was successful. There are no other packages avaiable:

$ sudo apt install imagemagick -a
imagemagick/oldstable,now 8:6.9.10.23+dfsg-2.1+deb10u1 armhf  [installiert]

Secondly, I installed Imagick:

$ sudo apt install php-imagick

That was successful as well. There are no other packages avaiable:

$ sudo apt list php-imagick -a
php-imagick/oldstable,now 3.4.3-4.1 armhf [installiert]

I've added the following entry in my php.ini:

[Imagick]
extension=imagick.so

Finally, I restarted apache:
$ sudo systemctl restart apache2

During troubleshooting, I even restarted php:
$ sudo service php8.2-fpm reload

Problem and troubleshooting so far

Imagick doesn't show up, neither when I try php -r 'phpinfo();' | grep imagick nor php -m | grep imagick.

Saying that, of course $im = new \Imagick(); results in a

Fatal error: Uncaught Error: Class "Imagick" not found.

I've studied web pages (including https://stackoverflow.com/questions/3790191/php-error-class-imagick-not-found) and manuals for more than two hours now without any success. Any help/hint is highly appreciated!

Edit: Hints found so far

Maybe one hint is that imagick.so was installed in the directory /usr/lib/php/20180731, while the current php extensions directory (according to php.ini) is /usr/lib/php/20220829. Copying the file to 20220829 (and restarting the services) didn't help.

Another hint might be that /etc/php/7.3/cli/conf.d contains a (link file) 20-imagick.ini (pointing to /etc/php/7.3/mods-available/imagick.ini), while /etc/php/8.2/cli/conf.d doesn't contain such a link, and /etc/php/8.2/mods-available doesn't contain an imagick.ini file. Same is applicable for /etc/php/x.y/apache2/conf.d. That seems suspicious, so I copied the following files

/etc/php/7.3/mods-available/imagick.ini -> /etc/php/8.2/mods-available/imagick.ini [content: extension=imagick.so]
/etc/php/7.3/cli/conf.d/20-imagick.ini -> /etc/php/8.2/cli/conf.d/20-imagick.ini
/etc/php/7.3/apache2/conf.d/20-imagick.ini -> /etc/php/8.2/apache2/conf.d/20-imagick.ini
/etc/php/7.3/fpm/conf.d/20-imagick.ini -> /etc/php/8.2/fpm/conf.d/20-imagick.ini
/usr/lib/php/20180731/imagick.so -> /usr/lib/php/20220829/imagick.so

After $ sudo systemctl restart apache2 when I run $ php -m | grep imagick I now get

PHP Warning:  PHP Startup: Unable to load dynamic library 'imagick.so' (tried: /usr/lib/php/20220829/imagick.so (/usr/lib/php/20220829/imagick.so: undefined symbol: add_next_index_zval), /usr/lib/php/20220829/imagick.so.so (/usr/lib/php/20220829/imagick.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0

Maybe for some reason apt install and/or php-imagick think that my current php version is 7.3, so it updated the wrong files and took the wrong shared library (imagick.so), while it is 8.2 (7.3 is still installed, but inactive and 8.2 is active)?

Found this link here, that at least matches the error message: https://stackoverflow.com/questions/65521238/the-propcedure-entry-point-add-index-zval-could-not-be-located-in-the-dynamic-li

Possible solution: I have to get Imagick version>=3.5.0, according to the change log https://pecl.php.net/package-changelog.php?package=imagick, in order to have PHP 8.x supported (hopefully 8.2).

答案1

得分: 0

以下是翻译好的部分:

主要问题:存储库证书未安装

主要问题是,我从额外的存储库安装了PHP 8.2,因为树莓派基金会尚不支持PHP 8.x,但我需要PHP 8.x来使用一些扩展。存储库本身没有问题,但我没有添加某些证书,所以apt无法从此存储库加载所有所需的文件。

当无法从存储库加载所需的文件时,会引发许多头痛问题。

逐步解决方案(适用于Debian 10 Buster)

以下是我为解决(或更具体地说,是为了避免)问题而采取的步骤。

清理到存储库的连接

  1. 将存储库的gpg密钥添加到受信任存储库列表中。
$ sudo wget /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
$ echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
  1. 更新apt包信息
    此步骤非常重要,不要忽略它。
$ sudo apt update
  1. 按照存储库提供商的说明操作
    不幸的是,我当时不知道以下步骤,这导致了我的问题。根据https://packages.sury.org/php/README.txt的说明:
$ sudo apt-get -y install lsb-release ca-certificates curl
$ sudo curl -sSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg
$ sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
$ sudo apt-get update

否则,所需的证书不会安装,apt不会从存储库下载所有文件(尽管它下载了一些文件 - 我不知道为什么会这样)。

获取phpize

  1. 获取phpize
    您需要phpize以后安装Imagick。phpize包含在php-dev软件包中。当我在解决证书问题之前尝试这样做时,由于软件包要求的限制,我未能成功。请确保正确连接了存储库(参见上文)。

错误消息类似于以下消息(我必须翻译它,希望我翻译得正确):

以下软件包有未满足的依赖关系:
 libpcre2-dev:依赖于libpcre2-8-0(= 10.32-5),但要安装10.34-7+0~20191219.5+debian9

一旦解决了证书问题,以下命令将为PHP 8.2安装phpize

$ sudo apt-get install php-dev 

安装PECL

  1. 安装PECL
    我选择使用PECL而不是使用apt来安装imagick,正如PHP文档中推荐的那样。
    首先,我需要下载go-pear.phar。
    其次,我安装它
$ wget http://pear.php.net/go-pear.phar

我将go-pear.phar移动到一个名为~/Downloads/pear/的目录中。

$ sudo php ~/Downloads/pear/go-pear.phar
以下是新的PEAR安装的建议文件布局。要更改各个位置,请在目录前键入编号。输入'all'来更改所有位置,或只需按Enter接受这些位置。

 1. 安装基础目录($prefix):/usr
 2. 用于处理的临时目录:/tmp/pear/install
 3. 下载的临时目录:/tmp/pear/install
 4. 二进制文件目录:/usr/bin
 5. PHP代码目录($php_dir):/usr/share/php
 6. 文档目录:/usr/docs
 7. 数据目录:/usr/data
 8. 用户可修改的配置文件目录:/usr/cfg
 9. 公共Web文件目录:/usr/www
10. 系统手册页目录:/usr/man
11. 测试目录:/usr/tests
12. 配置文件的名称:/etc/pear.conf

1-12,'all'或Enter继续:

重要的是要以sudo身份运行此操作,否则将建议用户特定的目录。我按Enter继续。

安装imagemagick和Imagick

  1. 安装imagemagick
$ sudo apt-get install imagemagick
$ sudo apt-get install libmagickwand-dev libmagickcore-dev
  1. 安装imagick(通过PECL)
$ sudo pecl install imagick

在此安装期间,需要使用phpize来编译imagick。phpize的路径设置错误(请参阅文件phpize中的前几行)。

为了确保安全,我将sed作为(硬)链接复制了一份

$ sudo ln /bin/sed /usr/bin/sed

断开首步添加的存储库的连接

如果您希望断开与sury.org/php存储库的连接,您必须执行以下命令。我不建议这样做,因为所安装软件的可能的更新或更改依赖于该存储库。

sudo rm -rf /etc/apt/trusted.gpg.d/php.gpg
sudo rm -rf /etc/apt/sources.list.d/php.list
英文:

Main problem: Certificates of repository not installed

The main problem was that I had installed PHP 8.2 from an additional repository, as PHP 8.x is not yet supported by the Raspberr Pi Foundation, but I needed PHP 8.x for some extensions. The repository is fine, but I hadn't added the some certificates, so apt couldn't load all required files from this repository.

And you get lots of headache, when you can't load required files from a repository.

Step by step solution (for Debian 10 Buster)

Here is what I did in order to solve (or, to be more specific, to avoid) the problem.

Clean connection to repository

  1. Add repository gpg to your list if trusted repositories.
$ sudo wget /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
$ echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
  1. Update apt package information
    This step is imporant, don't omit it.
$ sudo apt update
  1. Follow instructions of the repository provider
    Unfortunately, I wasn't aware of the following steps, and this caused my problems. According to https://packages.sury.org/php/README.txt
$ sudo apt-get -y install lsb-release ca-certificates curl
$ sudo curl -sSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg
$ sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
$ sudo apt-get update

Otherwise, the required cerficicates are not installed, and apt doesn't download all files from the repository (although it downloaded some - I have no idea why this is the case).

Get phpize

  1. Get phpize
    You need phpize to install Imagick later. phpize is included in the package pho-dev. When I tried this before solving the certificate issue (see above), I failed to do so due to package requiremens restrictions. Make sure to have the repostories properly connected (see above).

The error message was similar to this one (I had to translate it and hope I got it right):

The following packages have unmet dependencies:
 libpcre2-dev : Depends: libpcre2-8-0 (= 10.32-5) but 10.34-7+0~20191219.5+debian9 is to be installed

As soon the certificate issue was solved, the following command installed phpsize für PHP 8.2:

$ sudo apt-get install php-dev 

Install PECL

  1. Install PECL
    Rather then installing installing imagick with apt, I installed it by using PECL, as recommended in the PHP documentation.
    First, I had to download go-pear.phar.
    Second, I installed it
$ wget http://pear.php.net/go-pear.phar

I moved go-pear.phar to a directory ~/Downloads/pear/.

$ sudo php ~/Downloads/pear/go-pear.phar
Below is a suggested file layout for your new PEAR installation.  To
change individual locations, type the number in front of the
directory.  Type 'all' to change all of them or simply press Enter to
accept these locations.

 1. Installation base ($prefix)                   : /usr
 2. Temporary directory for processing            : /tmp/pear/install
 3. Temporary directory for downloads             : /tmp/pear/install
 4. Binaries directory                            : /usr/bin
 5. PHP code directory ($php_dir)                 : /usr/share/php
 6. Documentation directory                       : /usr/docs
 7. Data directory                                : /usr/data
 8. User-modifiable configuration files directory : /usr/cfg
 9. Public Web Files directory                    : /usr/www
10. System manual pages directory                 : /usr/man
11. Tests directory                               : /usr/tests
12. Name of configuration file                    : /etc/pear.conf

1-12, 'all' or Enter to continue:

It is important to run this with sudo, otherwise user-specific directories are suggested.
I pressed Enter to continue.

Install imagemagick and Imagick

  1. Install imagemagick
$ sudo apt-get install imagemagick
$ sudo apt-get install libmagickwand-dev libmagickcore-dev
  1. Install imagick (via PECL)
$ sudo pecl install imagick

During this installation, phpize is required to compile imagick. phpize had the wrong path for sed configured (see the first lines in the file phpize).

To be on the save side, I copied sed as (hard) link

$ sudo ln /bin/sed /usr/bin/sed

Disconnect repository added as first step

If you wish to disconnect the repository sury.org/php, you have to execute this commands. I'm not recommending this, as the possible updates or changes of the software installed depends on this repository.

sudo rm -rf /etc/apt/trusted.gpg.d/php.gpg
sudo rm -rf /etc/apt/sources.list.d/php.list

huangapple
  • 本文由 发表于 2023年2月26日 22:35:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/75572695.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定