安装 PHP Zip 扩展

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18774568/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 18:11:31  来源:igfitidea点击:

Installing PHP Zip Extension

phpcentoszippearphp-extension

提问by Ubunfu

I'm attempting to install the PHP Zip extension.

我正在尝试安装 PHP Zip 扩展。

My server does not have external internet access, so I downloaded it myself from PECL: http://pecl.php.net/package/zip. I chose 1.10.2, the latest "stable" release, and transferred it to my server.

我的服务器没有外部互联网访问,所以我自己从 PECL 下载了它:http: //pecl.php.net/package/zip。我选择了最新的“稳定”版本 1.10.2,并将其转移到我的服务器上。

I ran:

我跑了:

pear install zip-1.10.2.tgz

and added

并添加

extension=zip.so

to php.ini as instructed. I can see that zip.so was created and placed in the right extension_dir folder as well. I restarted apache and then checked to see if it was loaded by running:

按照指示转到 php.ini。我可以看到 zip.so 已创建并放置在正确的 extension_dir 文件夹中。我重新启动了 apache,然后检查它是否通过运行加载:

php -m

Despite all of this, "zip" is still not in that list.

尽管如此,“zip”仍然不在该列表中。

Am I missing a step or doing something wrong? I thought this should be really simple, and I'm starting to feel pretty dumb, haha.

我是否遗漏了一步或做错了什么?我想这应该很简单,我开始觉得很愚蠢,哈哈。

Other probably important stuff:

其他可能很重要的东西:

CentOS Apache 2.2.3 PHP 5.2.16

CentOS Apache 2.2.3 PHP 5.2.16

采纳答案by cweiske

You may have several php.inifiles, one for CLI and one for apache. Run php --inito see where the CLI ini location is.

您可能有多个php.ini文件,一个用于 CLI,一个用于 apache。运行php --ini以查看 CLI ini 位置。

回答by Ajeet Shah

This is how I installed it on my machine (ubuntu):

这是我在我的机器(ubuntu)上安装它的方式:

php 7:

php 7:

sudo apt-get install php7.0-zip

php 5:

php 5:

sudo apt-get install php5-zip

Edit:
Make sure to restart your server afterwards.

编辑:
确保之后重新启动服务器。

sudo /etc/init.d/apache2 restartor sudo service nginx restart

sudo /etc/init.d/apache2 restart或者 sudo service nginx restart

PS: If you are using centOS, please check above cweiske's answer
But if you are using a Debian derivated OS, this solution should help you installing php zip extension.

PS:如果您使用的是centOS,请查看上面cweiske回答
但是如果您使用的是 Debian 派生的操作系统,这个解决方案应该可以帮助您安装 php zip 扩展。

回答by Rafael Corrêa Gomes

1 Step -Install a required extension

1 步 -安装所需的扩展

sudo apt-get install libz-dev -y

2 Step -Install the PHP extension

2 步 -安装 PHP 扩展

pecl install zlib zip

3 Step -Restart your Apache

3 步 -重启你的 Apache

sudo /etc/init.d/apache2 restart

Enable PHP ZIP Extension

启用 PHP ZIP 扩展

If does not work you can check if the zip.ini is called in your phpinfo, to check if the zip.so was included.

如果不起作用,您可以检查 zip.ini 是否在您的 phpinfo 中被调用,以检查是否包含 zip.so。

回答by priojeet priyom

Simply use sudo yum install php-zip

只需使用 sudo yum install php-zip

回答by M_R_K

for PHP 7.3 / Ubuntu

适用于 PHP 7.3 / Ubuntu

sudo apt install php7.3-zip

for PHP 7.4

PHP 7.4

sudo apt install php7.4-zip

回答by kosala manojeewa

For php 7.3 on ubuntu 16.04

对于 ubuntu 16.04 上的 php 7.3

sudo apt-get install php7.3-zip

sudo apt-get install php7.3-zip

回答by Dr. Aaron Dishno

On Amazon Linux 2 and PHP 7.4 I finally got PHP-ZIP to install and I hope it helps someone else - by the following (note the yum install command has extra common modules also included you may not need them all):

在 Amazon Linux 2 和 PHP 7.4 上,我终于安装了 PHP-ZIP,我希望它可以帮助其他人 - 通过以下操作(注意 yum install 命令还包含额外的常用模块,您可能不需要全部):

sudo yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

sudo yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm

sudo yum -y install yum-utils

sudo yum-config-manager --enable remi-php74

sudo yum update

sudo yum install php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json

sudo pecl install zip

php --modules

sudo systemctl restart httpd

回答by lakshmikandan

The PHP5 version do not support in Ubuntu 18.04+ versions, so you have to do that configure manually from the source files. If you are using php-5.3.29,

PHP5 版本在 Ubuntu 18.04+ 版本中不支持,因此您必须从源文件中手动配置。如果您使用的是php-5.3.29

# cd /usr/local/src/php-5.3.29
# ./configure --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=MySQL_LOCATION/mysql --prefix=/usr/local/apache/php --with-config-file-path=/usr/local/apache/php --disable-cgi --with-zlib --with-gettext --with-gdbm --with-curl --enable-zip --with-xml --with-json --enable-shmop
# make
# make install

Restart the Apache server and check phpinfo function on the browser <?php echo phpinfo(); ?>

重启Apache服务器,在浏览器查看phpinfo功能 <?php echo phpinfo(); ?>

Note: Please change the MySQL_Location: --with-mysql=MySQL_LOCATION/mysql

注意:请更改 MySQL_Location:--with-mysql=MySQL_LOCATION/mysql

回答by D.Dimitrioglo

If you use php5.6 then execute this:

如果你使用 php5.6 然后执行这个:

sudo apt-get install php5.6-zip

sudo apt-get install php5.6-zip