[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Successor to CentOS] AlmaLinux OS server construction/migration service

[Successor to CentOS] AlmaLinux OS server construction/migration service

[For WordPress only] Cloud server “Web Speed”

[For WordPress only] Cloud server “Web Speed”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Reservation system development] EDISONE customization development service

[Reservation system development] EDISONE customization development service

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[Global exclusive service] Beyond's MSP in North America and China

[Global exclusive service] Beyond's MSP in North America and China

[YouTube] Beyond official channel “Biyomaru Channel”

[YouTube] Beyond official channel “Biyomaru Channel”

Memo about zip compression with PHP7.1

Hello.
I'm Mandai, in charge of Wild on the development team.

I was asked to write code to perform zip compression using PHP for content that is being developed in a PHP7.1 environment.
I wanted to release it after merging and confirming it, but it took a little time, so I would like to share the solution.

It started with an error about missing 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 happened because I didn't install the module, so I'll try to install it.

The currently installed PHP-related 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

 

Certainly not.
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 # It should be around here zlib

 

Not really.
So, let's quickly install it using yum.

 

Try installing php-pecl-zip using yum

Since PHP was prepared using yum, 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.

 

You got angry 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 is a PECL module, let's try compiling it directly.

 

Try compiling the PECL module

The source was downloaded from PECL::Package::zip

$ phpize Configuring for: PHP Api Version: 20160303 Zend Module Api No: 20160303 Zend Extension Api No: 320160303 $ ./configure checking for grep that handles long lines and -e... /bin/grep checking for egrep... / bin/grep -E checking 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 for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether cc accepts -g. .. yes checking for cc option to accept ISO C89... none needed checking how to run the C preprocessor... cc -E checking for icc... no checking 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 checking 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 for PHP extension directory... /usr/lib64/php/modules checking for PHP installed headers prefix... /usr/include/php checking if debug is enabled... no checking 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 angry because the libzip version was low.
There is also a way to increase the version of libzip, but I don't want it to affect various things, so I did a little research.

There's not much information.
There are quite a few articles about installing PHP, but when it comes to php-pecl-zip, the number of articles suddenly decreases. Even if the scope is expanded to include English, this may still be a rare case.

 

Isn't it yum after all? suspicion that

Let's change our thinking a bit and go back to the basics and look at the results of yum.
When I installed it with yum, the installation stopped due to php-commom, so wouldn't it be possible to bypass this? I thought.

$ 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 due to dependency resolution, but php-pecl-zip was successfully installed!
It has a different name, libzip5, so there should be no problem!

 

summary

On CentOS, the PHP registered in the standard yum repository is still 5 series, so I would like to do something about this, but by excluding php-common with the --exclude option, unnecessary dependency resolution can be avoided. I was able to install it without any problems.

Yum is quite good, so it's a case that you don't see very often.
When performing zip compression with PHP, you may want to be careful about the PHP version.

That's it.

If you found this article helpful , please give it a like!
0
Loading...
0 votes, average: 0.00 / 10
14,971
X facebook Hatena Bookmark pocket
[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

The person who wrote this article

About the author

Yoichi Bandai

My main job is developing web APIs for social games, but I'm also fortunate to be able to do a lot of other work, including marketing.
Furthermore, my portrait rights in Beyond are treated as CC0 by him.