October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Enable ZipArchive in PHP Docker Containers

Install libzip-dev, run docker-php-ext-install zip, rebuild the image and recreate the container to make ZipArchive available in PHP Docker applications.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For the Debian/Ubuntu-based official PHP image used in the documented SitePoint example, add the libzip-dev build dependency and compile PHP’s ZIP extension with docker-php-ext-install zip:

FROM php:8.1-apache

RUN apt-get update && apt-get install -y 
    libzip-dev 
    zip 
    && docker-php-ext-install zip

Then rebuild the image and recreate the container. This enables the ZipArchive class in the PHP runtime inside Docker; installing an extension only on your WSL2 or Windows host will not change the container’s PHP.

What the ZIP extension provides

ZipArchive is PHP’s class for opening, creating, modifying and extracting ZIP archives. It is provided by PHP’s ZIP extension, which must be compiled into (or loaded by) the PHP runtime that executes your application. The PHP manual documents libzip as the extension dependency and says Linux builds use the --with-zip configure option.

See the PHP ZIP requirements and ZIP installation instructions for version-specific details.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use the Dockerfile recipe for official Debian-based PHP images

The accepted SitePoint solution targets php:8.1-apache and installs the development files before compiling the extension:

FROM php:8.1-apache

RUN apt-get update && apt-get install -y 
    libzip-dev 
    zip 
    && docker-php-ext-install zip
  • libzip-dev supplies the headers and libraries needed while the extension is built.
  • zip provides command-line ZIP utilities; it is separate from PHP’s ZipArchive class but is included in the forum example.
  • docker-php-ext-install zip compiles and enables the extension using the helper included in official PHP images.

The forum poster reported that this Dockerfile addition solved the missing class. That is confirmation for the shown image and package family, not a guarantee that the same commands apply unchanged to every PHP tag or Linux distribution.

Check whether ZipArchive is already enabled

Do this inside the container that runs the application, not on the host:

docker compose exec app php -m | grep -i zip
docker compose exec app php -r 'var_dump(class_exists("ZipArchive"));'

Replace app with your service name. A module-list result containing zip and a bool(true) result mean the class is available. If your project uses a different container or PHP-FPM service, run the commands there; a CLI binary and a web server can load different configuration files.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Rebuild and recreate the running container

  1. Save the dependency and extension commands in the Dockerfile used by the application.
  2. Rebuild the image so the new layer actually runs:
    docker compose build --no-cache app

    A normal docker compose build app is sufficient when cache invalidation is reliable; --no-cache is useful when diagnosing a stale build.

  3. Recreate the container:
    docker compose up -d --force-recreate app
  4. Repeat the module and class_exists() checks inside the new container.

Restarting an old container without rebuilding does not add an extension that was absent from its image.

Verify with a real archive operation

After the class check succeeds, test the operation your application needs:

<?php
$archive = new ZipArchive();
$result = $archive->open('/tmp/example.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE);
if ($result !== true) {
    throw new RuntimeException("ZipArchive::open() failed: {$result}");
}
$archive->addFromString('check.txt', 'ZIP works');
if (!$archive->close()) {
    throw new RuntimeException('The archive could not be written.');
}

ZipArchive::open() can open an archive for reading, writing or modification. When creating one, PHP does not necessarily write the final file until close(); filesystem errors can therefore appear at that point. The API behavior is described in the PHP manual for ZipArchive::open().

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Match the instructions to your image

First identify the exact image in the Dockerfile, including its PHP version and base distribution. The documented command uses Debian/Ubuntu-style apt-get and the official PHP helper scripts. An Alpine-based image uses a different package manager and dependency names, and a non-official image may not include docker-php-ext-install. Do not paste the Debian recipe into those images without adapting it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The original question mentioned PHP 8.2, while the forum’s working example uses php:8.1-apache. The discussion does not establish a universal PHP 8.2 recipe or the defaults of every current tag, so inspect the selected image and verify the enabled modules after each image change.

libzip and PHP version considerations

The PHP manual lists libzip 0.11 as the minimum supported version and recommends a newer release. Features introduced by newer libzip versions may not be available when only the minimum is present. Your distribution’s libzip-dev package determines the development version installed by the Docker build; check the package and PHP documentation when you need a specific ZIP feature.

Older guides can also be misleading because PHP’s ZIP build process changed before PHP 7.4. For current official images, use the image’s documented helper scripts and the package manager for its base distribution rather than copying instructions written for an older PHP release.

If ZipArchive is still missing

  • Confirm the runtime: print php -v and php --ini inside the container serving the request. Host PHP in WSL2 may be unrelated.
  • Inspect loaded modules: run php -m and class_exists('ZipArchive') in that same container.
  • Read the image build log: look for failures finding libzip headers or libraries. A failed docker-php-ext-install zip step means no usable extension was produced.
  • Check that the new layer is present: rebuild the image and recreate the container, rather than only restarting an existing one.
  • Check web-server configuration: if CLI reports ZIP but the application does not, compare the PHP SAPI and loaded php.ini files used by the web process.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.