Website Vidya
DeploymentStep-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
Website Vidya TeamLead Systems Educator
Published:
6 min read
How to Install PHP ZIP Extension on Ubuntu / CentOS: 4 Easy Steps
AI Executive SummaryCORE CIS AI

6 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:

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:

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.



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.


FAQs: How to Install PHP ZIP Extension

The PHP ZIP extension allows PHP to handle ZIP archives, enabling functionalities like creating, extracting, and modifying ZIP files in your applications.

You need the PHP ZIP extension to work with ZIP files in PHP, which is required by many frameworks, CMS platforms (like WordPress), and applications.

Run the following command in your terminal:

php -m | grep zip

Use the following commands:

sudo apt update
sudo apt install php-zip
sudo systemctl restart apache2 # Or restart PHP-FPM

Run these commands:

sudo yum install php-pecl-zip
sudo systemctl restart httpd # Or restart PHP-FPM

Yes, restart your web server (Apache or Nginx) or PHP-FPM service to apply the changes.

  • Ensure the extension is listed in the output of php -m.
  • Verify your php.ini configuration includes extension=zip.
  • Restart the server.

Yes, but ensure your PHP version is supported. Use a package manager like apt or yum for your OS or manually compile the extension.

php -v

Yes, the PHP ZIP extension is compatible with PHP 8. Install it using your system’s package manager.

Written by

Website Vidya Team

Technology educator and researcher at Website Vidya.

Discussion

0
Share your thoughts, ask a question, or suggest a tip...
Write →

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

Deployment•

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
Deployment•

How to Install PHPMyAdmin on Ubuntu: 4 Simple Steps

If you’re working with MySQL or MariaDB on Ubuntu, managing databases purely from the command line can quickly feel overwhelming. That’s where phpMyAdmin comes in. PHPMyAdmin is a web-based application that provides a Graphical User Interfa...

RR
Rajesh Rai
Read More
Deployment•

25 Best Linux Commands Every Sysadmin Should Know

If you’ve spent any time managing Linux servers, you already know this truth: the command line is not optional. It’s where real troubleshooting happens, where performance issues are understood, and where outages are prevented before users e...

RR
Rajesh Rai
Read More
Deployment•

How to Fix Snapd Consuming High CPU / RAM on Linux

If you’ve ever opened your system monitor and noticed snapd quietly eating up your CPU or RAM, you’re not alone. Many Linux users—especially on Ubuntu and Ubuntu-based distributions—eventually run into this issue and wonder what’s going on ...

RR
Rajesh Rai
Read More
Deployment•

How to Fix Broken Packages in Ubuntu: 7 Simple Ways

If you’ve been using Ubuntu for a while, chances are you’ve run into package-related issues at least once. A failed update, an interrupted installation, or conflicting dependencies can easily leave your system in a messy state. When that ha...

RR
Rajesh Rai
Read More