如何在PHP 7.4上安装ziparchive?

8

我在CentOS 7上运行Virtuamin,但无法在PHP 7.4上安装Ziparchive。但是,当我切换到PHP 7.2时,它可以正常工作。我需要让PHP 7.4工作,因为它更快,并且WordPress脚本需要7.3以上版本才能有效地工作。

5个回答

13
sudo apt-get install php7.4-zip

这适用于Ubuntu 18.04


7
也许您想看一下这篇帖子: https://www.cloudbooklet.com/upgrade-php-version-to-php-7-4-on-ubuntu/ 基本上,它告诉您要做以下几点: 添加 PHP 7.4 的 PPA 添加 ondrej/php,里面包含 PHP 7.4 包和其他所需的 PHP 扩展。
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update

然后您可以安装该扩展。

sudo apt install php7.4-zip

或者安装所有常用的软件包:

sudo apt install php7.4-common php7.4-mysql php7.4-xml php7.4-xmlrpc php7.4-curl php7.4-gd php7.4-imagick php7.4-cli php7.4-dev php7.4-imap php7.4-mbstring php7.4-opcache php7.4-soap php7.4-zip php7.4-intl -y

4
这是我在Ubuntu上安装它的方法:
对于PHP:
sudo apt-get install php7.0-zip

对于Centos

You can try: yum install php-pecl-zip.x86_64

Try installing that and enabling it by running: echo "extension=zip.so" >> /etc/php.d/zip.ini


请注意:安装以上内容后,请确保重新启动您的服务器。
sudo /etc/init.d/apache2 restart 或 sudo service nginx restart

1
我正在运行CentOS而不是Ubuntu,ZipArchive已经安装在PHP 7.2上,我需要它能够在PHP 7.4上工作。 - Puneet Chandhok

3

我正在使用Debian 9操作系统,该操作系统不自带PHP7.4,但是如果你添加Sury存储库,就可以安装它。

sudo apt install ca-certificates apt-transport-https
wget -q https://packages.sury.org/php/apt.gpg -O- | sudo apt-key add -
echo "deb https://packages.sury.org/php/ stretch main" | sudo tee /etc/apt/sources.list.d/php.list

之后,我成功地运行了这个命令:

apt install php7.4-zip
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  php7.4-zip
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 20.5 kB of archives.
After this operation, 94.2 kB of additional disk space will be used.
Get:1 https://packages.sury.org/php stretch/main amd64 php7.4-zip amd64 7.4.7-1+                                                                           0~20200612.18+debian9~1.gbp671911 [20.5 kB]
Fetched 20.5 kB in 0s (149 kB/s)
Selecting previously unselected package php7.4-zip.
(Reading database ... 107553 files and directories currently installed.)
Preparing to unpack .../php7.4-zip_7.4.7-1+0~20200612.18+debian9~1.gbp671911_amd                                                                           64.deb ...
Unpacking php7.4-zip (7.4.7-1+0~20200612.18+debian9~1.gbp671911) ...
Processing triggers for libapache2-mod-php7.4 (7.4.7-1+0~20200612.18+debian9~1.g                                                                           bp671911) ...
Setting up php7.4-zip (7.4.7-1+0~20200612.18+debian9~1.gbp671911) ...
Creating config file /etc/php/7.4/mods-available/zip.ini with new version
Processing triggers for php7.4-fpm (7.4.7-1+0~20200612.18+debian9~1.gbp671911) .                                                                           ..
NOTICE: Not enabling PHP 7.4 FPM by default.
NOTICE: To enable PHP 7.4 FPM in Apache2 do:
NOTICE: a2enmod proxy_fcgi setenvif
NOTICE: a2enconf php7.4-fpm
NOTICE: You are seeing this message because you have apache2 package installed.
Processing triggers for libapache2-mod-php7.4 (7.4.7-1+0~20200612.18+debian9~1.g                                                                           bp671911) ...
Processing triggers for php7.4-cgi (7.4.7-1+0~20200612.18+debian9~1.gbp671911) .                                                                           ..
Processing triggers for php7.4-cli (7.4.7-1+0~20200612.18+debian9~1.gbp671911) .                                                                           ..

0
这实际上取决于你使用的PHP版本。通常情况下,你只需要执行以下命令就可以了:sudo apt-get install php-zip,但是这对我来说并没有起作用。解决方案取决于PHP的版本。
对于目前可用的三个主要版本的PHP,最后一个(实际上与我的版本8.1匹配)对我有效:

PHP 5.6

sudo apt-get install php5.6-zip

PHP 7.0

sudo apt-get install php7.0-zip

PHP 8.0

sudo apt-get install php8.0-zip

安装后别忘了重新启动 Apache!

以下任一方法都可以重新启动 Apache:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接