2

I'm trying to install zipArchive with pecl. After running the command, I get an error - "Please reinstall the libzip distribution".

I'm running PHP 7.2 on Amazon Linux 2.

Here's my output:

$ ./pecl install zip
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
downloading zip-1.15.2.tgz ...
Starting to download zip-1.15.2.tgz (249,280 bytes)
....................................................done: 249,280 bytes
8 source files, building
running: phpize
Configuring for:
PHP Api Version:         20170718
Zend Module Api No:      20170718
Zend Extension Api No:   320170718
building in /tmp/pear/install/pear-build-ec2-userIZcX1f/zip-1.15.2
running: /tmp/pear/install/zip/configure --with-php-config=/usr/bin/php-config
checking for grep that handles long lines and -e... /usr/bin/grep

...<snip up to warning>...

configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... gawk
checking for zip archive read/writesupport... yes, shared
checking libzip... yes
checking PHP version... PHP 7.x
checking for pkg-config... /usr/bin/pkg-config
checking for libzip... not found
configure: error: Please reinstall the libzip distribution
ERROR: `/tmp/pear/install/zip/configure --with-php-config=/usr/bin/php-config' failed

But if I check libzip it's already installed:

$ sudo yum install libzip
Loaded plugins: langpacks, priorities, update-motd
amzn2-core                                                                                                                                     | 2.0 kB  00:00:00     
Package libzip-0.10.1-8.amzn2.x86_64 already installed and latest version
Nothing to do

I'm using ./pecl as I had to install a new version of pear from my home directory and the old version is still in the path. This is the command I used to get the updated version of pear.

$ wget http://pear.php.net/go-pear.phar
$ php go-pear.phar

I don't know if that makes any difference? I do have the correct version referred to in my php.ini:

;***** Added by go-pear
include_path=".:/home/ec2-user/pear/share/pear"
;*****

Any help appreciated.

4
  • 1
    Is there a libzip-devel package maybe? Feb 20, 2018 at 16:56
  • Progress! Now I get "checking for libzip... configure: error: system libzip must be upgraded to version >= 0.11". I'm not sure how to upgrade the version... Feb 20, 2018 at 16:59
  • 0.11 was released five years ago. Is your Linux install up to date? Feb 20, 2018 at 17:51
  • It's a new AWS EC2 instance using Amazon Linux 2, so I had assumed everything would be up-to-date. uname -a shows "$ uname -a Linux ip----.eu-west-2.compute.internal 4.9.77-41.59.amzn2.x86_64 #1 SMP Thu Feb 1 19:26:09 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux" Any idea how I might resolve the outdated libzip? Feb 21, 2018 at 13:25

1 Answer 1

5

I have managed to compile PECL zip (partly due to snow in the UK cancelling my booked day!). I have not tested this in php, but it loads correctly into phpinfo();

Option 1: Update Libzip & Hope for the best

I used an external CentOS-7 repo (which amzn linux 2 is supposed to be pretty compatible with) and the following script:

#PECL requires libzip 11 - get it from a foreign repo
sudo rpm --import http://wiki.psychotic.ninja/RPM-GPG-KEY-psychotic
#this looks wrong but the repo uses a single release
sudo rpm -ivh http://packages.psychotic.ninja/6/base/i386/RPMS/psychotic-release-1.0.0-1.el6.psychotic.noarch.rpm

#YUM REPO HACKS START
#unfortunately amazon-linux-2 release numbering breaks it - force RHEL 7 numbering
sudo sed -i s/\$releasever/7/g /etc/yum.repos.d/psychotic.repo
#Need to exclude outdated amzn zip packages
sudo yum remove libzip libzip-devel
#check for an exclude line, add our one if not present (to the main repo)
grep -A 100 -m1 "\[amzn2-core" /etc/yum.repos.d/amzn2-core.repo | grep exclude= || sudo sed -i -E "s/($(grep -A 100 -m1 "\[amzn2-core" /etc/yum.repos.d/amzn2-core.repo | grep -m1 ^name=)$)/\1\nexclude=libzip libzip-devel/" /etc/yum.repos.d/amzn2-core.repo
#check this worked, if not modify the existing exclude line(s)
grep -A 100 -m1 "\[amzn2-core" /etc/yum.repos.d/amzn2-core.repo | grep "exclude=.*libzip" || sudo sed -i -E "s/exclude=/exclude=libzip libzip-devel /" /etc/yum.repos.d/amzn2-core.repo
#YUM REPO HACKS END

sudo yum install --enablerepo=psychotic-plus gcc libzip libzip-devel
#now install PECL
wget http://pear.php.net/go-pear.phar
sudo php go-pear.phar
#patch it to cope with the XML being a module
sudo sed -i "$ s|\-n||g" /usr/bin/pecl
#and this should now work
sudo pecl install zip
#may still need to manually add to the php.ini
grep "^extension=zip.so" /etc/php.ini || echo "extension=zip.so" | sudo tee -a /etc/php.ini

Be VERY careful with the bit of this script marked 'YUM REPO HACKS' - it intentionally includes commands to modify your repo configuration which have had minimal testing. All it is actually doing is replacing the '$releasever' variable in the pyschotic repo with '7' and adding 'exclude=libzip libzip-devel' to the amzn2-core repo. You could do this with vim!

Option 2: 2 versions of libzip

From my research: if you are not comfortable with a 'found-by-google' repo on your server (I don't blame you, depends on use case) then you could leave the amzn zip in place, use their source repo to install libzip 11.2 source, install that (and/or its libraries) to an alternate location (find the instructions elsewhere for that) and compile the php module manually.

To compile zip manually:

$ pecl download zip
$ tar -xf zip-*.tgz && cd zip-* && phpize
$ ./configure --with-libzip=/path/to/secondary/libzip

...etc

2
  • Thank you, I have marked your answer as useful though cannot test it at this time as I rebuilt the EC2 instance with Ubuntu (which solved all my issues this time around). Feb 28, 2018 at 14:45
  • I was able to install the system that needed pecl-zip (nextcloud) without issue and it seems to be working fine, so I think above is ok (though its still early days). Mar 1, 2018 at 10:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.