Install php-zip on php 5.6 on Ubuntu

Install php-zip on php 5.6 on Ubuntu

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Installing PECL Extensions on Legacy PHP Versions

When working with legacy environments like PHP 5.6, you often encounter situations where standard system packages aren't enough to satisfy your application's requirements. The error PHP Fatal error: Class 'ZipArchive' not found is a classic symptom of a missing PECL extension rather than a broken Composer dependency or a misconfigured Apache server. This specific failure mode frequently arises when using older versions of libraries like PHPEXL, which rely on the ziparchive class to handle file packaging.

On modern Ubuntu releases, PHP 5.6 is no longer available in the default repositories. However, if you are maintaining an existing Virtual Machine or a container with a pinned version, you must build the extension from source or use specific third-party repositories. The "easy" apt-get install php-zip command often fails because the official Ubuntu packaging for PHP 5.6 has been deprecated or removed from the standard main and universe archives.

Building from Source

Since the package is unavailable in the default repositories, you will need to compile the extension directly against your installed PHP headers. This approach ensures binary compatibility with your specific version of PHP 5.6 and your system's OpenSSL configuration.

First, ensure that the development tools and libraries required for compiling are present on your Ubuntu VM:

sudo apt-get update
sudo apt-get install git build-essential libzip-dev php5.6-dev

The libzip-dev package provides the underlying C library headers needed by the PECL extension. Without this, the compilation will fail with missing header file errors.

Next, clone the official PHP ZipArchive repository and compile it:

git clone https://github.com/php/pecl_zip.git
cd pecl_zip
phpize
make clean
make
sudo make install

The phpize command initializes the build environment by detecting your installed PHP 5.6 installation location, including headers and libraries. Running make compiles the C code into a shared object file (.so), and sudo make install places this file in the correct directory for Apache to load it.

Registering the Extension

Once compiled and installed, the extension is not automatically active. You must explicitly enable it by editing your PHP configuration file. Locate the main configuration file, typically found at /etc/php/5.6/apache2/php.ini.

Add the following line to the end of the file:

extension=zip.so

After saving the changes, you must restart Apache for the new configuration to take effect:

sudo service apache2 restart

You can verify that the extension is loaded by creating a test script in your web root or running it via CLI:

<?php
echo class_exists('ZipArchive') ? 'Success' : 'Failed';
?>

If this outputs "Success," the PHPExcel library and other dependencies requiring the ZipArchive class should now function correctly.

Considerations for Legacy Systems

Compiling extensions from source is often the only viable path for PHP 5.6, but it introduces maintenance overhead. Every time you upgrade system libraries, such as libzip, you may need to recompile the extension to ensure ABI compatibility. Additionally, relying on PHP 5.6 exposes your application to known security vulnerabilities that have been patched in newer versions.

If your project allows for minor infrastructure changes, migrating to a supported PHP version (such as 7.4 or 8.x) is strongly recommended. Modern repositories usually include php-zip as a pre-compiled package, eliminating the need for manual compilation and reducing the risk of build errors. However, if upgrading the entire stack is not an option due to legacy database dependencies or third-party libraries, the source compilation method described above provides a functional workaround to restore the missing class functionality.

Our network