Installing PHP Zip Extension

Installing PHP Zip Extension

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.

Installing PHP 7.3 Zip Extension

I copied zip.so to default extension directory

No.

If you use base package (php-*) you need php-pecl-zip.

php73-php-pecl-zip is a SCL package designed for parallel installation.

See the repository FAQ

For a proper configuration, and to avoid such issues, follow the Wizard instructions.

Zip Module Not loading PHP 8.0.12

I was finally able to get the zip extension to load by installing the pecl zip module

sudo yum install php-pecl-zip Once it installed and I reloaded apache running php -m showed

bcmath
bz2
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
readline
Reflection
session
shmop
SimpleXML
sockets
sodium
SPL
sqlite3
standard
sysvmsg
sysvsem
sysvshm
tokenizer
xml
xmlreader
xmlwriter
xsl
zip
zlib

[Zend Modules]

Install php-zip on php 5.6 on Ubuntu

Try either

  • sudo apt-get install php-zip or
  • sudo apt-get install php5.6-zip

Then, you might have to restart your web server.

  • sudo service apache2 restart or
  • sudo service nginx restart

If you are installing on centos or fedora OS then use yum in place of apt-get. example:-

sudo yum install php-zip or
sudo yum install php5.6-zip and
sudo service httpd restart

install ext-zip for Mac

I had the same problem after updating my Mac to Catalina. Here is what worked for me.

brew update
brew install php@7.3
brew link php@7.3

Then reload your console.

It will install php 7.3.10 with zip module. You can use php -v to check for the version, and php -m for the modules.

How to install zip extension for PHP 7.4 compiled from scratch on CentOS 7?

The zip extension requires the libzip library. So you can compile it from source. However the libzip library requires the zlib library. To make sure that you won't miss anything important, the best if I show you how I'm doing it.

This is how I compile 7.4 from source on our centos 7 servers

First I'm installing package update and installing the missing packages:

sudo yum update
sudo yum -y install lzip oniguruma oniguruma-devel

# OR if you cant find the packages you can use RPMs - example:
curl https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/o/oniguruma-5.9.5-3.el7.x86_64.rpm --output oniguruma-5.9.5-3.el7.x86_64.rpm
rpm -Uvh oniguruma-5.9.5-3.el7.x86_64.rpm

Installing the CMake:

cd
# installing compiled cmake
wget -c https://cmake.org/files/LatestRelease/cmake-3.16.0-Linux-x86_64.tar.gz
tar zxvf cmake-3.*

# OR install it from source:
curl -OL https://github.com/Kitware/CMake/archive/v3.16.5.tar.gz
tar zxvf v3.16.5.tar.gz

cd CMake-3.*
./bootstrap --prefix=/usr/local
sudo make -j2
sudo make install
# maybe this is not required:
sudo cp ~/CMake-3.16.5/bin/cmake /usr/bin/

Compile the zlib:

wget -c http://www.zlib.net/zlib-1.2.11.tar.gz
tar zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
sudo make -j2
sudo make install

Compile the libzip for the zip extension:

cd
wget -c https://libzip.org/download/libzip-1.6.1.tar.gz
tar zxvf libzip-1.6.1.tar.gz
cd libzip*
mkdir build
cd build
cmake ..
sudo make -j2
make test
sudo make install

Copy the built file and add it to the variables

sudo cp /home/centos/libzip-1.6.1/build/libzip.pc /usr/local/lib64/pkgconfig/libzip.pc

# Also add this to the env variables for each session - later in the guide
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib64/pkgconfig/

Compiling php:

if php is already installed through a package installer, then delete it.

sudo yum-config-manager --disable remi-php74
sudo yum remove php php-cli php-common php-opcache php-mcrypt php-gd php-curl php-fpm php-dom php-intl php-pecl-mongodb php-mbstring php-xml php-pear php-devel php-pecl-zip

Extra info for compiling: https://shaunfreeman.name/compiling-php-7-on-centos

# for some reason libzip-last wont do what you need, so you need to compile it as it's written above
sudo yum install httpd-devel git gcc gcc-c++ readline-devel libxml2-devel libzip-last libxslt-devel pkgconfig openssl-devel bzip2-devel curl-devel libpng-devel libjpeg-devel libXpm-devel freetype-devel gmp-devel libmcrypt-devel mariadb-devel aspell-devel recode-devel autoconf bison re2c libicu-devel
sudo mkdir /usr/local/php7
cd

# OPTION A
git clone https://github.com/php/php-src.git
cd php-src
git checkout PHP-7.4.5

# OPTION B
# use the release tar instead of the source branch
curl -OL https://github.com/php/php-src/archive/php-7.4.5.tar.gz
tar zxvf php-7.4.5.tar.gz

cd php-src-php-7.4.5
./buildconf --force
./configure --prefix=/usr/local/php7 \
--with-config-file-path=/usr/local/php7/etc \
--with-config-file-scan-dir=/usr/local/php7/etc/conf.d \
--with-apxs2=/usr/bin/apxs \
--enable-bcmath \
--enable-fpm \
--with-bz2 \
--with-curl \
--disable-phpdbg \
--disable-phpdbg-webhelper \
--enable-filter \
--enable-gd \
--with-freetype \
--with-jpeg \
--enable-intl \
--with-mysql-sock=/var/lib/mysql/mysql.sock \
--with-openssl \
--enable-simplexml \
--enable-xmlreader \
--enable-xmlwriter \
--enable-pcntl \
--enable-shmop \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--with-xsl \
--enable-opcache \
--enable-calendar \
--enable-sockets \
--enable-mbstring \
--with-readline \
--with-zlib=~/libzip-1.6.1/build/ \
--with-zip \
--enable-exif \
--with-gettext \
--without-sqlite3 \
--with-mhash \
--enable-maintainer-zts
sudo make -j2
sudo make install
sudo mkdir /usr/local/php7/etc/conf.d
sudo cp -v ./php.ini-production /usr/local/php7/lib/php.ini
sudo cp -v ./sapi/fpm/www.conf /usr/local/php7/etc/php-fpm.d/www.conf
sudo cp -v ./sapi/fpm/php-fpm.conf /usr/local/php7/etc/php-fpm.conf
sudo vim /usr/local/php7/etc/conf.d/modules.ini

the make -j2 defines how much core threads you would like to use to compile.

The other line you should notice is this one:

--with-zlib=~/libzip-1.6.1/build/ \

During the configuration use the package of your own need.

php is running primarily from here: /usr/bin/php

And your built php will be located here: /usr/local/php7/bin/php

so you might will need overwrite it:

sudo mv /usr/local/php7/bin/php /usr/bin/php

That's not all, but it covers every important part with the zip extension.

How can I install ziparchive on php 7.4?

I am on Debian 9, which does not ship with PHP7.4, but it can be installed if you add the repository from 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

After that, I ran this with success:

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

How to install php-zip extention on scrutinizer-ci?

The correct config is:

build:
tests:
override:
- true

nodes:
tests:
environment:
php:
version: 7.4
pecl_extensions:
- zip
analysis:
environment:
php:
version: 7.4
pecl_extensions:
- zip
tests:
override: [php-scrutinizer-run]

I just copied from this repo (I googled with keyword '.scrutinizer.yml php github zip'), but actually already described on the official docs . I was read it but misunderstood.

Docker php adding Zip Extension

The solution is as simple as removing the docker-php-ext-configure zip --with-libzip line entirely for PHP >= 7.4. Defaults are sufficient.

As commented by hackel on their issue tracker: https://github.com/laradock/laradock/issues/2421#issuecomment-567728540

So a working Dockerfile would be:

FROM php:7.4-fpm-alpine

RUN apk add --no-cache \
libzip-dev \
zip \
&& docker-php-ext-install zip


Related Topics



Leave a reply



Submit