Installing PHP Zip Extension in CentOS

Installing PHP Zip Extension in CentOS

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

Stefan Bogdanescu

Founder & Senior Architect

Installing PHP Zip Extension in CentOS

The core issue here isn't that you are missing a step; it is that you are trying to install a module using a method that conflicts with your specific environment constraints. You downloaded zip-1.10.2.tgz from PECL and attempted to run pear install zip-1.10.2.tgz. While this command appears logical, PEAR's installation mechanism relies heavily on fetching dependencies automatically and often expects an internet connection to validate signatures or download required libraries like libzip. Since your CentOS server lacks external internet access, the PEAR installer likely failed silently or partially during the dependency resolution phase, even if it reported a "success" status.

Furthermore, there is a critical compatibility mismatch between the version you selected and your PHP runtime. You are running PHP 5.2.16, which was released in early 2011. The zip extension version 1.10.2 was released in 2013. While older versions of the extension were available for PHP 5.2, attempting to use a newer PECL package on an ancient PHP version will result in a compilation failure or a binary that cannot be loaded by the Zend Engine. The zip.so file you see in your extension_dir is almost certainly incomplete, corrupted, or simply not compatible with PHP 5.2.16 architecture.

To resolve this without internet access, you must bypass PEAR entirely and compile the extension from source directly against your existing PHP installation. This approach gives you granular control over the compilation flags and ensures the resulting binary matches your specific PHP version headers.

First, identify the exact path to your PHP installation's include directory. On CentOS 6 with Apache 2.2.3 and PHP 5.2.16, this is typically /usr/lib/php/5.2 or /usr/lib/php. You can confirm this by running:

php --ini | grep scan_dir
# Or check the extension directory directly
php -i | grep extension_dir

Next, download a compatible source tarball from the official PECL archive for PHP 5.2. Since you cannot rely on the zip-1.10.2 release, look for a version explicitly marked as compatible with PHP 5.2.x (often labeled as "released" rather than "stable" in the legacy archives). Transfer this file to your server using FTP or SCP.

Once transferred, extract the archive:

tar -zxvf zip-<compatible-version>.tgz
cd zip-*

You must compile this extension specifically for your PHP binary. Run phpize, which configures the build environment based on your installed PHP headers:

phpize

This command will verify that your system has the necessary development tools (gcc, make) and locate the correct php-config path. If phpize fails, ensure you have the php-devel package installed via yum.

Now, configure the compilation. The most critical flag is ensuring the extension targets the correct PHP version:

./configure --with-zip-dir=/usr/lib/php/5.2

If you have a specific include path or library path required by your CentOS setup, add those flags as well. For example, if libzip is installed locally in a non-standard location, use --with-libzip=/path/to/libzip. However, for PHP 5.2, the extension often bundles its own compression logic, so this might not be necessary depending on the specific release you chose.

Compile and install:

make
sudo make install

The make install command will copy the compiled zip.so file to your designated extension_dir. Verify that the file exists in the expected location (e.g., /usr/lib/php/5.2/modules/zip.so).

Finally, update your php.ini configuration file located in your web root or the standard system path. Add the line:

extension=zip.so

Ensure there is no space between extension= and zip.so. After saving the file, restart Apache:

service httpd restart

Reload the module list using php -m. If the compilation was successful and the binary matches your PHP version, zip will now appear in the output. If it still does not load, check the error log at /var/log/httpd/error_log for messages regarding "shared object" loading failures, which often indicate a mismatch between the extension's internal libraries and the main PHP executable.

In production environments where internet access is restricted, maintaining legacy stacks like PHP 5.2 requires careful version matching. While upgrading to a modern PHP version would eliminate these headaches by allowing you to use the latest zip extensions and security patches, the source compilation method described above provides a functional workaround for your immediate needs. If you are maintaining a legacy application stack, this manual approach ensures stability without relying on external package managers that might attempt to pull incompatible dependencies.

Our network