Is your PHP saying that it cannot find the ZipArchive class? Then, this post will show you how to enable the ZipArchive module.

Bạn đang xem: Class "ziparchive" not found


$zip = new ipArchive();$x = $zip->open($target_path);if ($x === true) $zip->extractTo($target_dir . $name<0>); $zip->close();

What does this error mean?

This error means that PHP could not find the ZipArchive class. Therefore, PHP needs khổng lồ have the zip extension installed for the ZipArchive Class to lớn be present.

You can kiểm tra whether ZipArchive is installed by using a PHP info file.

See an example below:

Your PHP info file should return something lượt thích this:


Next, scroll down until you find the heading “Configuration” & then continue until you see the following:


You will know that the ZipArchive class is not enabled if you cannot see: “Zip” configuration “enabled”.

Or you can use “php -m” lớn show the PHP information in the CLI.

How to lớn enable ZipArchive on Windows

Windows users have it easy! You vày not need to vì chưng anything if you use PHP 5.3 or newer. So, don’t trust that the code written và evaluated on Windows will work on Linux.

As of PHP 5.3, this extension is built-in. Before, Windows users needed lớn enablephp_zip.dllinside ofphp.ini to lớn use these functions.

Before you enable ZipArchive

You can enable Zip support during the installation of PHP and after the fact. This post will focus on an after-the-fact ZipArchive installation on Linux. Please read the installing Zip instruction from the PHP manual for more information.

Before you continue, note the following helpful command khổng lồ get your current version of PHP:

Note the version in the example above being: 7.4.2. We will, therefore, need to install the Zip module for PHP version 7.4. Please remember to lớn change the version number lớn match yours if the command requires it!

Also, make sure that your packages are up lớn date using the “apt-get update” command:

server:/var/www/html# apt-get updateHit:1 buster/updates InReleaseHit:2 buster InReleaseHit:3 buster-updates InReleaseReading package lists... Done
Lastly, you may need to lớn determine the location of the loaded php.ini file. Please note that the CLI uses its version.

Use the following command lớn help you:

server:/var/www/html# php --iniConfiguration tệp tin (php.ini) Path: /usr/local/etc/phpLoaded Configuration File: /usr/local/etc/php/php.iniScan for additional .ini files in: /usr/local/etc/php/conf.dAdditional .ini files parsed: /usr/local/etc/php/conf.d/docker-php-ext-pdo_mysql.ini,/usr/local/etc/php/conf.d/docker-php-ext-redis.ini,/usr/local/etc/php/conf.d/docker-php-ext-sodium.ini,/usr/local/etc/php/conf.d/docker-php-ext-zip.ini

How to lớn enable ZipArchive on Docker

First, run the following command to install Zip and compile PHP correctly khổng lồ run it.

Xem thêm: Cài Win 7 Song Song Với Win 8/10/11 Chuẩn Uefi, Cài Đặt Song Song Windows 10 Với Windows 7 Hoặc 8

Below you will see how khổng lồ restart Apache or NGINX. Once you install, you have finished.

Note that you will get an “E: Package ‘php-XXX’ has no installation candidate” error if you try lớn install any of Debian‘s PHP packages. This error is the default intended behavior of the official PHP Docker image.

You can see an example of this behavior below:

server:/var/www/html# apt-get install php-zipReading package lists... DoneBuilding dependency treeReading state information... DonePackage php-zip is a virtual package provided by: php7.3-zip 7.3.14-1~deb10u1 php7.3-zip 7.3.11-1~deb10u1 E: Package 'php-zip' has no installation candidate
server:/var/www/html# apt-get install php7.0-zipReading package lists... DoneBuilding dependency treeReading state information... DoneE: Unable khổng lồ locate package php7.0-zipE: Couldn't find any package by glob 'php7.0-zip'E: Couldn't find any package by regex 'php7.0-zip'
server:/home/user# sudo apt-get install php-zipReading package lists... DoneBuilding dependency tree Reading state information... DoneThe following additional packages will be installed: libzip5 php-common php7.3-common php7.3-zipThe following NEW packages will be installed: libzip5 php-common php-zip php7.3-common php7.3-zip0 khổng lồ upgrade, 5 to lớn newly install, 0 lớn remove and 48 not to upgrade.1 not fully installed or removed.Need to lớn get 1,003 kB of archives.After this operation, 7,443 kB of additional disk space will be used.
Please note that you may need to lớn specify the PHP version if you upgraded lớn a recent version of PHP.

Don’t forget to restart your web server!

The configuration file (php.ini) is only read when PHP or the webserver starts. Equally, the php.ini tệp tin is only read at invocation for the CGI and CLI versions.

You can restart Apache using:

service apache2 restart
Likewise, you can restart NGINX using:

service nginx restart

Wrapping up

It is easy to lớn get your trang web zipping files and avoid a fatal error. I hope that you now know how khổng lồ enable ZipArchive for PHP. No one likes seeing a “Fatal error: Class’ ZipArchive’ not found in”.

You may also be interested in

About the Authors"s editorial team loves the cloud as much as you! Each member of"s editorial team is a Cloud expert in their own right. Online takes great pride in helping fellow Cloud enthusiasts. Let us know if you have an excellent idea for the next topic! tương tác Online if you want to contribute.

Support the Cause

Support Online và buy us a coffee. Anything is possible with coffee and code.

Buy me a coffee


Solve the “Cannot read properties of undefined (reading ‘type’)” error with these simple fixes

December 19, 2022December 19, 2022


How to set up CORS for an AWS Lambda Proxy REST API resource

May 13, 2022June 10, 2022


Entering the Job Market? Here Are the Most In-Demand Programming Languages for 2022

January 17, 2022June 17, 2022

Post navigation

Previous Article How lớn install và use the Windows 10 SSH feature
Next Article The Ultimate Guide on How to Secure WordPress

About Online

Having started his career in 1999 as a Desktop tư vấn Engineer, soon changed paths và became a developer. After several years of development experience, he transitioned into a consultant. As an enterprise application consultant for a leading SaaS software provider, specializes in AWS"s serverless technologies.By day, focuses on helping customers leverage the power nguồn of serverless technologies. By night, he indulges his passion for cloud computing by playing with Python & trying out things that are currently beyond the scope of his work.Sometimes needs help as there are not enough hours at night. So relies on a team of fellow Cloud enthusiasts lớn help him out. Each one is a Cloud expert in their own right, and takes great pride in helping them learn và grow.