A note about zip compression in PHP7.1

table of contents
Hello.
I'm Mandai, the Wild team member in charge of development.
I was developing content in a PHP 7.1 environment, and I had someone write code to perform zip compression using PHP.
I wanted to release it after merging and testing, but I ran into some trouble, 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
It's definitely not there.
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
No, it's not there.
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.
That was a strange way to get scolded.
Since you're using PHP version 7.1, it's odd that php-common-5.4 is the reason you can't install it.
Since it's a PECL module, let's try compiling it directly
Compiling a PECL module
the source codePECL :: Package :: zipI downloaded
$ 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 got an error message saying my libzip version was too low.
I could upgrade libzip, but I don't want to risk causing other problems, so I did a little research.
There isn't much information available.
There are a fair number of articles on installing PHP, but when it comes to php-pecl-zip, the number of articles drops dramatically. Even expanding the search to English-language resources, it seems to be a fairly rare case.
The suspicion that it's yum after all?
Let's change our approach a bit and go back to basics and look at the results of yum.
When installing with yum, the installation was stopped because of php-commom, so I thought that if we could bypass it, we might be able to fix it.
$ 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 a new libzip was installed during dependency resolution, but I was able to successfully install php-pecl-zip!
It has a different name, libzip5, so there shouldn't be any problems!
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
yum is quite efficient, so this is a rather rare case.
When using PHP for zip compression, you might want to pay attention to the PHP version.
That's all
0
