Website Vidya
Linux & ServersStep-by-Step Guide

How to Install PHP ZIP Extension on Ubuntu / CentOS: 4 Easy Steps

The PHP ZIP extension is essential for working with ZIP archives in PHP applications. It enables developers to create, read, and modify ZIP files directly from PHP scripts. By adding this extension, developers can significantly enhance thei...

RR
Rajesh RayLead Systems Educator
Published:
4 min read
How to Install PHP ZIP Extension on Ubuntu / CentOS: 4 Easy Steps
AI Executive SummaryCORE CIS AI

4 min read

The PHP ZIP extension is essential for working with ZIP archives in PHP applications. It enables developers to create, read, and modify ZIP files directly from PHP scripts. By adding this extension, developers can significantly enhance thei...

Key Highlights
  • How to Install PHP ZIP Extension on Ubuntu
  • How to Install PHP ZIP Extension on CentOS/Fedora/Rocky Linux/AlmaLinux
  • Alternative Installation Methods
Grounded in full engineering runbookCORE CIS Ai Engine

The PHP ZIP extension is essential for working with ZIP archives in PHP applications. It enables developers to create, read, and modify ZIP files directly from PHP scripts.

By adding this extension, developers can significantly enhance their PHP environment, making it versatile for projects involving file compression and decompression.

This guide provides an in-depth look at installing the PHP ZIP extension on popular Linux distributions such as Ubuntu, CentOS, Fedora, and others, with multiple methods and troubleshooting tips included.

How to Install PHP ZIP Extension on Ubuntu


Step 1: Update Package Lists

Before installing any new packages, ensure your system’s package lists are up-to-date to avoid issues caused by outdated data:

Advertisement
sudo apt update

This command refreshes the list of available packages and ensures you’re accessing the most recent versions.

Step 2: Install PHP ZIP Extension

The next step involves installing the PHP ZIP extension. The exact command depends on the PHP version you’re using. Here are the appropriate commands for different versions:

For PHP 8.3:

sudo apt-get install php8.3-zip

For PHP 8.2:

sudo apt-get install php8.2-zip

For PHP 8.1:

sudo apt-get install php8.1-zip

For PHP 8.0:

sudo apt-get install php8.0-zip

For PHP 7.4:

sudo apt-get install php7.4-zip

For PHP 7.3:

sudo apt-get install php7.3-zip

If you’re unsure about your PHP version, you can check it by running:

php -v

This command displays the installed PHP version, which helps you pick the correct package.

Step 3: Restart Apache Server

After successfully installing the extension, restart the Apache server to apply the changes and activate the ZIP module:

Advertisement
sudo service apache2 restart

If you’re using Nginx instead of Apache, restart PHP-FPM:

sudo service php8.x-fpm restart

Replace 8.x with your PHP version.

Step 4: Verify Installation

To confirm that the PHP ZIP extension is installed and enabled, use the following command:

php -m | grep -i zip

If the extension is installed, you’ll see “zip” in the output. Alternatively, you can verify it by creating a PHP file named check_zip.php with the following content:

<?php
if (extension_loaded('zip')) {
    echo "ZIP extension is installed.";
} else {
    echo "ZIP extension is not installed.";
}
?>

Save this file in your web server’s document root and access it via your browser or run it from the command line to confirm the extension’s status.

Advertisement


How to Install PHP ZIP Extension on CentOS/Fedora/Rocky Linux/AlmaLinux

Step 1: Check PHP Version

Knowing your PHP version is crucial for installing the appropriate package. Check it with:

php -v

This command outputs the installed PHP version, ensuring you install a compatible ZIP extension.

Step 2: Install PHP ZIP Extension

The method of installation varies slightly between CentOS versions and Fedora. Below are the steps for each:

For CentOS 7:

Install the PHP ZIP extension using the YUM package manager:

sudo yum install php-zip

For CentOS 8 and Fedora:

CentOS 8 and Fedora use the DNF package manager. Use the following command:

sudo dnf install php-zip

Step 3: Restart Web Server

After installation, restart your web server to activate the extension. For Apache:

sudo systemctl restart httpd

For Nginx with PHP-FPM:

sudo systemctl restart php-fpm

Step 4: Verify Installation

Check if the ZIP extension is enabled using:

php -m | grep zip

Alternatively, you can use the same check_zip.php script described earlier to verify the extension’s status.


Alternative Installation Methods

Using PECL (PHP Extension Community Library)

PECL is a widely used tool for managing PHP extensions. Follow these steps to install the PHP ZIP extension via PECL:

  1. Install the PECL tool by running:sudo yum install php-pear
  2. Use PECL to install the ZIP extension:sudo pecl install zip
  3. Add the extension to your PHP configuration:echo "extension=zip.so" | sudo tee -a /etc/php.ini
  4. Restart your web server to apply the changes. For Apache:sudo systemctl restart httpd

Compiling from Source

If you encounter issues with package managers or need a specific version of the ZIP extension, you can compile it from the source. Here’s how:

  1. Download the source code for the ZIP extension:wget https://pecl.php.net/get/zip-1.19.3.tgz
  2. Extract the downloaded archive:tar -xzvf zip-1.19.3.tgz
  3. Navigate to the extracted directory:cd zip-1.19.3
  4. Prepare the built environment:phpize
  5. Configure, compile, and install the extension:./configure make sudo make install
  6. Enable the extension by adding it to your PHP configuration:echo "extension=zip.so" | sudo tee -a /etc/php.ini
  7. Restart your web server to activate the changes:sudo systemctl restart httpd

Troubleshooting Common Issues

Repository Problems

Sometimes, the PHP ZIP package isn’t available due to outdated or missing repositories. Resolve this by:

  1. Cleaning and updating your repositories:sudo yum clean all sudo yum update
  2. Adding the EPEL repository if necessary:sudo yum install epel-release sudo yum update

Dependency Conflicts

Dependency conflicts can prevent installation. To identify and resolve these issues:

  1. Check for missing or conflicting dependencies:sudo yum deplist php-zip
  2. Install any missing dependencies:sudo yum install [package-name]
  3. If problems persist, use the --skip-broken option to bypass conflicts:sudo yum install php-zip --skip-broken

You may also like:

Learn PHP

Conclusion


By following these detailed instructions, you can seamlessly install and enable the PHP ZIP extension on Ubuntu, CentOS, Fedora, and other Linux distributions. Whether you choose to use the package manager, PECL, or compile the extension from source, these steps ensure a reliable and efficient setup for handling ZIP archives in PHP applications. Proper verification and troubleshooting techniques are also included to help address common issues, making this guide comprehensive and practical for developers of all skill levels.

If you found this guide on how to install PHP ZIP extension useful, share it with others in your network who might benefit from it. For more advanced configurations or related topics, check the official PHP documentation.


RR
Written byVerified Author

Rajesh Ray

I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.

SPAM-FREE MODERATED DISCOURSE

Join the Conversation & Perspective

Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.

AT
MP
JV
+2

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

Linux & Servers•

How to Install PDO Extension in PHP

PHP Data Objects (PDO) is one of the most important extensions in PHP for working with databases in a secure, consistent, and modern way. If you are building dynamic websites, APIs, CMS platforms, or enterprise applications, PDO is not opti...

RR
Rajesh Rai
Read More
Featured Infrastructure PartnerUp to 75% OFF + 3 Months Free

Supercharge Your Linux & Cloud Workloads with Hostinger

Deploy high-speed NVMe KVM VPS, Docker containers, and LiteSpeed-accelerated WordPress servers in under 60 seconds with full root access, dedicated IPv4, and 24/7 technical support.

Pure NVMe SSD StorageFull Root Access & SSHFree Domain & Unlimited SSL99.9% Uptime SLA
Plans from$2.99/mo
Claim Hostinger DealAffiliate link • Special discount applied at checkout