Installing PHP Zip Extension in CentOS
Asked Answered
V

13

75

I'm attempting to install the PHP Zip extension in CentOS.

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.

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 -m

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

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

Voiture answered 12/9, 2013 at 21:24 Comment(0)
G
33

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

Girlhood answered 16/9, 2013 at 7:25 Comment(4)
Thanks for the response. That returns the following (sorry for this I'm not sure how to linebreak in a comment): Loaded Configuration File: (none) Scan for additional .ini files in: (none) Additional .ini files parsed: (none). Also, find / -name "php.ini" tells me that this is the only php.ini file on the boxVoiture
It did not load any configuration file. That's your problem. My PHP also shows a "configuration file (php.ini) path" with php --ini. Use $ strace -eopen php --ini to find out where you php looks for the .ini file.Girlhood
Sorry for pretty much letting this die without explanation. php --ini says the config file path is /usr/bin ...do I just need to move it there? Also, if nothing from the config file is taking effect does PHP come with a set of defaults it uses instead?Voiture
yes, there are default values. they are documented in the php manual. try to move the php.ini to the path you found.Girlhood
S
102

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

php 7:

sudo apt-get install php7.0-zip

php 5:

sudo apt-get install php5-zip

Make sure to restart your server afterwards.

sudo /etc/init.d/apache2 restart or 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.

Sutter answered 4/5, 2016 at 4:39 Comment(4)
You seem to suggest to use a package manager to solve or prevent any issues. CentOS seems to use yum as a package manager.Duiker
for php7.1 sudo apt install php7.1-zipYell
has anyone been able to install the zip extension for php7.2 ? it keep on saying E: Unable to locate package php7.2-zip E: Couldn't find any package by regex 'php7.2-zip' i have tried alot of variations but none work, i have PHP Version 7.2.17-1+ubuntu14.04.1+deb.sury.org+3Jahdol
Note that the question was about CentOS and not Ubuntu (I tried to clarify that in the title)Tungting
G
33

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

Girlhood answered 16/9, 2013 at 7:25 Comment(4)
Thanks for the response. That returns the following (sorry for this I'm not sure how to linebreak in a comment): Loaded Configuration File: (none) Scan for additional .ini files in: (none) Additional .ini files parsed: (none). Also, find / -name "php.ini" tells me that this is the only php.ini file on the boxVoiture
It did not load any configuration file. That's your problem. My PHP also shows a "configuration file (php.ini) path" with php --ini. Use $ strace -eopen php --ini to find out where you php looks for the .ini file.Girlhood
Sorry for pretty much letting this die without explanation. php --ini says the config file path is /usr/bin ...do I just need to move it there? Also, if nothing from the config file is taking effect does PHP come with a set of defaults it uses instead?Voiture
yes, there are default values. they are documented in the php manual. try to move the php.ini to the path you found.Girlhood
C
26

Simply use sudo yum install php-zip

Celanese answered 30/11, 2018 at 18:27 Comment(2)
The question specifies that this is for CentOS, not Ubuntu. CentOS uses yum not apt-getEyebolt
Or sudo apt-get install php-zipEyebright
C
23

for PHP 7.3 / Ubuntu

sudo apt install php7.3-zip

for PHP 7.4

sudo apt install php7.4-zip
Cuomo answered 2/9, 2019 at 5:21 Comment(2)
"Unable to locate package php7.3-zip"Jacobson
Note that the question was about CentOS and not UbuntuTungting
J
17

1 Step - Install a required extension

sudo apt-get install libz-dev libzip-dev -y

2 Step - Install the PHP extension

pecl install zlib zip

3 Step - Restart your Apache

sudo /etc/init.d/apache2 restart

Enable PHP ZIP Extension

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

Johnathanjohnathon answered 19/12, 2016 at 17:29 Comment(2)
ERROR: `/tmp/pear/temp/zip/configure --with-php-config=/usr/local/bin/php-config' failedStonefish
Note that the question was about CentOS and not UbuntuTungting
P
7

For php 7.3 on ubuntu 16.04

sudo apt-get install php7.3-zip

Pervasive answered 10/5, 2020 at 2:48 Comment(1)
Note that the question was about CentOS and not UbuntuTungting
S
5

The best way to install the Zip extension in php7.2 on CentOS would be as below:

  1. Find the available extention by searching with yum command

    yum search zip

  2. This will list all the zip packages. We need to look for the php7.2 zip package enter image description here

  1. Then if your php version is 7.2 then run the command

    yum install ea-php72-php-zip

This will definetly resolve your issue.

Cheers !!

Soniasonic answered 19/8, 2020 at 12:45 Comment(0)
O
3

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):

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
Overstrain answered 13/3, 2020 at 14:35 Comment(2)
no need to "pecl install", ZIP extension available in the "remi-php74" repository !Aboulia
It didn't show up in my list of installed modules until i did. But I may have had something else wrong from my numerous attempts. Thanks for the note.Overstrain
G
2

I was trying to install it on CentOS 7 for php 7.1. In my case yum package php-zip was unavailable in remi repo, but I could install it using different name

yum install php-pecl-zip

So if you can't find it by query php-zip, try searching for php-pecl-zip.

Gasser answered 9/8, 2022 at 16:13 Comment(1)
"yum install php-zip" also works, as for any ext, don't rely on package name.Aboulia
L
1

If you use php5.6 then execute this:

sudo apt-get install php5.6-zip

Lozengy answered 6/12, 2016 at 19:48 Comment(2)
>CentOS Apache 2.2.3 PHP 5.2.16Ghazi
I get E: Unable to locate package php5.6-zip.Overburden
S
1

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,

# 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(); ?>

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

Shawnee answered 28/11, 2019 at 7:33 Comment(0)
B
1

I tried changing the repository list with:

http://security.ubuntu.com/ubuntu bionic-security main universe http://archive.ubuntu.com/ubuntu bionic main restricted universe

But none of them seem to work, but I finally found a repository that works running the following command

add-apt-repository ppa:ondrej/php

And then updating and installing normally the package using apt-get

As you can see it's installed at last.

Bergerac answered 26/8, 2020 at 13:23 Comment(0)
U
1

For those who need to install the zip extension in a Docker image being built.

Dockerfile:

FROM php:8.1-apache

RUN apt-get update \
  && apt-get install -y libzip-dev \
  && docker-php-ext-install zip
Ullyot answered 21/1, 2023 at 12:22 Comment(1)
This took forever to find. Thanks for putting this here!Spurn

© 2022 - 2024 — McMap. All rights reserved.