求助:找不到ZipArchive但似乎已安装(PHP 7.2)

我正在一个 Amazon EC2实例(Amazon Linux 2)上安装一个需要 ziparchave 的 CMS。需求向导说不支持 ziparchave。

但是如果我按照在网上找到的说明安装 ziparchave,服务器会告诉我它已经安装了:

[ec2-user@ip-***-**-**-** ~]$ sudo yum install php-zip
Loaded plugins: langpacks, priorities, update-motd
amzn2-core                                                                                                                                                                         | 2.0 kB  00:00:00     
Package matching php-common-5.4.16-43.amzn2.0.1.x86_64 already installed. Checking for update.
Nothing to do

我已经重新启动了httpd服务。

我也尝试过:

[ec2-user@ip-***-**-**-** ~]$ sudo yum install php7.0-zip
Loaded plugins: langpacks, priorities, update-motd
amzn2-core                                                                                                                                                                         | 2.0 kB  00:00:00     
No package php7.0-zip available.
Error: Nothing to do

我也曾尝试补充 extension=zip.so 到php.ini并重新启动httpd服务,但还是没用。

zipparchave 的 PHP 手册中说:“为了使用这些函数,必须使用——enable-zip configure 选项编译支持 zip 的 PHP。”我不知道何时何地该这么做,所以我只是简单地使用了:

yum install php php-mysql

我花了将近一天的时间来解决这个问题,我不知道接下来该怎么办。谁能告诉我正确的方向?

I had the same problem (Amazon Linux 2 AMI) trying to install Laravel. The problem is that this AMI uses libzip 0.10.1 while at least 0.11 is required, and if you check in your extension folder (in this AMI: /usr/lib64/php/modules), the file zip.so is missing. So, if you enable the extension in your php.ini file, you'll get an error in apache's log. I solved the issue using Remi's RPM repository to install libzip 1.1.3. This is what I did:

  1. install epel repo (needed to install Remi's RPM)
  2. install Remi's repo
  3. install libzip from the repo. You can check the new libzip version, ie:

    $ yum list "*libzip*"
    Installed Packages
    libzip-last.x86_64         1.1.3-1.el7.remi            installed
    
  4. Now that you have a compatible libzip, you can compile the zip extension: download the package from PECL in your tmp folder, extract the files and from the package root:

    $ sudo phpize
    $ sudo ./configure
    $ sudo make
    $ sudo make install
    
  5. after the make install command, the output should be:

    Installing shared extensions:     /usr/lib64/php/modules/
    

    and if you go in that dir, now you should finally see the zip.so file.

  6. Change your php.ini adding

    extension=zip
    
  7. Restart webserver and check your php info. This is what I see in mine:

    Zip enabled
    Zip version 1.15.2
    Libzip version  0.11.2
    

In my case I was able to install laravel.

If you are using Remi's repo, I noticed the zip module is a pecl extension, so to install and enable zip run

 sudo yum -y install php-pecl-zip

Then restart php-fpm is you are using NGINX or restart APACHE

 sudo service php-fpm restart
 sudo service httpd restart

You can install Remi repo

**RHEL or CentOS**
yum install yum-utils
yum-config-manager --enable remi-php72

See instructions on Remi Repo