A note about zip compression in PHP7.1

table of contents
Hello,
I'm Mandai, the Wild Team member of the development team.
I was developing a piece of content in a PHP 7.1 environment, and I had someone write some code to compress a zip file in PHP.
I wanted to merge it, check it, and then release it, but it took a bit of time, so I'd like to share the solution.
It started with an error that there was no ZipArchive
When I merged and ran it, I got the following error:
Error - Class 'ZipArchive' not found in APPPATH/classes/logic/monitoring.php on line 721
Of course, this is because the module was not installed, so I will try to install it
The currently installed PHP modules are as follows:
$ yum list installed | grep php php.x86_64 7.1.22-1.el7.remi @remi-php71 php-cli.x86_64 7.1.22-1.el7.remi @remi-php71 php-common.x86_64 7.1.22-1.el7.remi @remi-php71 php-devel.x86_64 7.1.22-1.el7.remi @remi-php71 php-fpm.x86_64 7.1.22-1.el7.remi @remi-php71 php-gd.x86_64 7.1.22-1.el7.remi @remi-php71 php-json.x86_64 7.1.22-1.el7.remi @remi-php71 php-mbstring.x86_64 7.1.22-1.el7.remi @remi-php71 php-mcrypt.x86_64 7.1.22-1.el7.remi @remi-php71 php-mysqlnd.x86_64 7.1.22-1.el7.remi @remi-php71 php-pdo.x86_64 7.1.22-1.el7.remi @remi-php71 php-pecl-imagick.x86_64 3.4.3-8.el7.remi.7.1 @remi-php71 php-xml.x86_64 7.1.22-1.el7.remi @remi-php71
That's not true.
Let's check the modules that PHP is loading.
$ php -m [PHP Modules] bz2 calendar Core ctype curl date dom exif fileinfo filter ftp gd gettext hash iconv imagick json libxml mbstring mcrypt mysqli mysqlnd openssl pcntl pcre PDO pdo_mysql pdo_sqlite Phar readline Reflection session SimpleXML sockets SPL sqlite3 standard tokenizer wddx xml xmlreader xmlwriter xsl # Should be around here zlib
There isn't.
So let's quickly install it using yum.
Install php-pecl-zip using yum
PHP was prepared using yum, so we will install it using yum again this time
$ yum install –enablerepo=remi-php71 php-pecl-zip Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: ftp.jaist.ac.jp * epel: mirrors.kernel.org * extras: ftp.jaist.ac.jp * remi-safe: ftp.riken.jp * updates: ftp.jaist.ac.jp Package matching php-common-5.4.16-45.el7.x86_64 already installed. Checking for update.
I'm being told off in a strange way.
The version of PHP I'm using is 7.1, so it's strange that I can't install it because of php-common-5.4.
Since it's a PECL module, let's try compiling it directly
Compiling a PECL module
I downloaded the source PECL::Package::zip
$ phpize Configuring for: PHP Api Version: 20160303 Zend Module Api No: 20160303 Zend Extension Api No: 320160303 $ ./configure checking for grep checking that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E for a sed that does not truncate output... /bin/sed checking for cc... cc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether cc accepts -g... yes for cc option to accept ISO C89... none needed checking how to run the C preprocessor... cc -E for icc... no for suncc... no checking whether cc understands -c and -o together... yes checking for system library directory... lib checking if compiler supports -R... no checking if compiler supports -Wl,-rpath,... yes checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking target system type... x86_64-unknown-linux-gnu checking for PHP prefix... /usr for PHP includes... -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib checking checking for PHP extension directory... /usr/lib64/php/modules checking for PHP installed headers prefix... /usr/include/php checking if debug is enabled... no if zts is enabled... no checking for re2c... no 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.0 - 7.2 checking for pkg-config... /bin/pkg-config checking for libzip... configure: error: system libzip must be upgraded to version >= 0.11
I was told that my libzip version was too low.
I could try upgrading the libzip version, but I didn't want to have to deal with all the issues, so I did a bit of searching.
There isn't much information.
There are quite a few articles about installing PHP, but when it comes to php-pecl-zip, the number of articles drops dramatically. Even if you expand the scope to English, it may be a rare case.
The suspicion that it's yum after all?
Let's change our thinking a bit and go back to basics and look at the results of yum.
When I installed with yum, the installation stopped because of php-common, so I thought maybe if I could just bypass this, something would work.
$ yum install --enablerepo=remi-php71 php-pecl-zip --exclude=php-common Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: ftp.jaist.ac.jp * epel: mirrors.kernel.org * extras: ftp.jaist.ac.jp * remi-php71: ftp.riken.jp * remi-safe: ftp.riken.jp * updates: ftp.jaist.ac.jp Resolving Dependencies --> Running transaction check ---> Package php-pecl-zip.x86_64 0:1.15.3-1.el7.remi.7.1 will be installed --> Processing Dependency: libzip5(x86-64) >= 1.5.1 for package: php-pecl-zip-1.15.3-1.el7.remi.7.1.x86_64 --> Processing Dependency: libzip.so.5()(64bit) for package: php-pecl-zip-1.15.3-1.el7.remi.7.1.x86_64 --> Running transaction check ---> Package libzip5.x86_64 0:1.5.1-1.el7.remi will be installed --> Finished Dependency Resolution Dependencies Resolved ============================================================================================================== Package Arch Version Repository Size ============================================================================================================== Installing: php-pecl-zip x86_64 1.15.3-1.el7.remi.7.1 remi-php71 51 k Installing for dependencies: libzip5 x86_64 1.5.1-1.el7.remi remi-safe 55 k Transaction Summary ============================================================================================================== Install 1 Package (+1 Dependent package) Total download size: 107 k Installed size: 280 k Is this ok [y/d/N]: y Downloading packages: (1/2): php-pecl-zip-1.15.3-1.el7.remi.7.1.x86_64.rpm | 51 kB 00:00:00 (2/2): libzip5-1.5.1-1.el7.remi.x86_64.rpm | 55 kB 00:00:00 ------------------------------------------------------------------------------------------------------------------ Total 214 kB/s | 107 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : libzip5-1.5.1-1.el7.remi.x86_64 1/2 Installing : php-pecl-zip-1.15.3-1.el7.remi.7.1.x86_64 2/2 Verifying : libzip5-1.5.1-1.el7.remi.x86_64 1/2 Verifying : php-pecl-zip-1.15.3-1.el7.remi.7.1.x86_64 2/2 Installed: php-pecl-zip.x86_64 0:1.15.3-1.el7.remi.7.1 Dependency Installed: libzip5.x86_64 0:1.5.1-1.el7.remi Complete!
It seems that a new libzip was installed during dependency resolution, but php-pecl-zip was successfully installed!
It has a different name, libzip5, so there should be no problem!
summary
In CentOS, the PHP version registered in the standard yum repository is still version 5, so it would be nice if something was done about this, but by excluding php-common with the --exclude option, I was able to install it without unnecessary dependency resolution
Since yum is quite good, this is a rare case.
If you are using PHP to compress files, you may want to be careful about the version of PHP.
That's all
0