在我的ubuntu 20.04服务器上安装php-rar插件时,我收到了这个错误。我该怎么解决?
root@root:/# free -m
total used free shared buff/cache available
Mem: 2000 870 113 36 1016 821
Swap: 0 0 0
sudo pecl -v install rar
/tmp/pear/temp/rar/rar_stream.c: In function ‘_rar_get_archive_and_fragment’:
/tmp/pear/temp/rar/rar_stream.c:787:66: warning: passing argument 1 of ‘zend_resolve_path’ from incompatible pointer type [-Wincompatible-pointer-types]
787 | zend_string *arc_str = zend_resolve_path(tmp_archive, tmp_arch_len);
| ^~~~~~~~~~~
| |
| char *
/tmp/pear/temp/rar/rar_stream.c:787:66: note: expected ‘zend_string *’ {aka ‘struct _zend_string *’} but argument is of type ‘char *’
/tmp/pear/temp/rar/rar_stream.c:787:48: error: too many arguments to function ‘zend_resolve_path’
787 | zend_string *arc_str = zend_resolve_path(tmp_archive, tmp_arch_len);
| ^~~~~~~~~~~~~~~~~
make: *** [Makefile:215: rar_stream.lo] Error 1
rolling back 454 file operations
ERROR: `make' failed
PHP版本
root@root:/# php -v
PHP 8.0.22 (cli) (built: Aug 15 2022 09:40:14) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.22, Copyright (c) Zend Technologies
with Zend OPcache v8.0.22, Copyright (c), by Zend Technologies
PECL中的rar
扩展只支持PHP 8.0,而不支持PHP 8.1,这是Ubuntu 20.04上的默认版本,所以如果你有PHP/8.0,它应该适合你,但你的环境现在可能安装了多个版本的PHP,这可能会破坏你的环境。
对您来说,您可能需要修复所有的alternatives
以指向正确的版本(我假设您使用ppa:ondrej/php
来安装旧的PHP版本(。
sudo update-alternatives --set php /usr/bin/php8.0
sudo update-alternatives --set php-config /usr/bin/php-config8.0
sudo update-alternatives --set php /usr/bin/phpize-8.0
下面是如何在Ubuntu 20.04上安装带有PHP 8.0或8.1的扩展。
在PHP 8.0上安装rar
以下是它在php-8.0
上工作的证明,使用原始环境和您可以从ppa:ondrej/php
安装的版本。
首先,我们从运行一个干净的基本容器开始:
docker run -it ubuntu:latest /bin/bash
然后运行所有必要的软件包安装
# inside container
apt-get update && apt-get install -y software-properties-common
add-apt-repository ppa:ondrej/php
apt-get update
apt-get install -y php8.0 php8.0-dev php8.0-xml
pecl install rar
这是安装输出的尾部:
Build complete.
Don't forget to run 'make test'.
running: make INSTALL_ROOT="/tmp/pear/temp/pear-build-defaultuserPcQEEc/install-rar-4.2.0" install
Installing shared extensions: /tmp/pear/temp/pear-build-defaultuserPcQEEc/install-rar-4.2.0/usr/lib/php/20200930/
running: find "/tmp/pear/temp/pear-build-defaultuserPcQEEc/install-rar-4.2.0" | xargs ls -dils
183533087 0 drwxr-xr-x. 3 root root 17 Sep 1 11:24 /tmp/pear/temp/pear-build-defaultuserPcQEEc/install-rar-4.2.0
199246884 0 drwxr-xr-x. 3 root root 17 Sep 1 11:24 /tmp/pear/temp/pear-build-defaultuserPcQEEc/install-rar-4.2.0/usr
200375743 0 drwxr-xr-x. 3 root root 17 Sep 1 11:24 /tmp/pear/temp/pear-build-defaultuserPcQEEc/install-rar-4.2.0/usr/lib
201589234 0 drwxr-xr-x. 3 root root 22 Sep 1 11:24 /tmp/pear/temp/pear-build-defaultuserPcQEEc/install-rar-4.2.0/usr/lib/php
202922222 0 drwxr-xr-x. 2 root root 20 Sep 1 11:24 /tmp/pear/temp/pear-build-defaultuserPcQEEc/install-rar-4.2.0/usr/lib/php/20200930
202922223 1964 -rwxr-xr-x. 1 root root 2010160 Sep 1 11:24 /tmp/pear/temp/pear-build-defaultuserPcQEEc/install-rar-4.2.0/usr/lib/php/20200930/rar.so
Build process completed successfully
Installing '/usr/lib/php/20200930/rar.so'
install ok: channel://pecl.php.net/rar-4.2.0
configuration option "php_ini" is not set to php.ini location
You should add "extension=rar.so" to php.ini
用PHP 8.1安装rar
您可以使用PHP 8.1安装rar
扩展,但不能通过pecl安装,因为该插件的v4.2.0
于2020年12月发布,不支持用于PHP 8.1的API。
相反,您必须使用phpize
从源代码手动安装。
再次运行干净的容器:
docker run -it ubuntu:latest /bin/bash
然后运行所有必要的命令:
apt-get update && apt-get install -y php8.1 php8.1-dev git
# Just to show that it's PHP 8.1
# root@e72cbf195c29:/# php -v
# PHP 8.1.2 (cli) (built: Aug 15 2022 12:24:10) (NTS)
# Get the source code
cd ~/
git clone https://github.com/cataphract/php-rar.git
cd php-rar
phpize
# phpize outputs that it's configuring for php8.1's API
# Configuring for:
# PHP Api Version: 20210902
# Zend Module Api No: 20210902
# Zend Extension Api No: 420210902
./configure && make && make install
构建成功,插件安装了
----------------------------------------------------------------------
Libraries have been installed in:
/root/php-rar/modules
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the '-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the 'LD_RUN_PATH' environment variable
during linking
- use the '-Wl,-rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to '/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
Build complete.
Don't forget to run 'make test'.
Installing shared extensions: /usr/lib/php/20210902/