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...

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...
- How to Install PHP ZIP Extension on Ubuntu
- How to Install PHP ZIP Extension on CentOS/Fedora/Rocky Linux/AlmaLinux
- Alternative Installation Methods
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:
- Install the PECL tool by running:
sudo yum install php-pear - Use PECL to install the ZIP extension:
sudo pecl install zip - Add the extension to your PHP configuration:
echo "extension=zip.so" | sudo tee -a /etc/php.ini - 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:
- Download the source code for the ZIP extension:
wget https://pecl.php.net/get/zip-1.19.3.tgz - Extract the downloaded archive:
tar -xzvf zip-1.19.3.tgz - Navigate to the extracted directory:
cd zip-1.19.3 - Prepare the built environment:
phpize - Configure, compile, and install the extension:
./configure make sudo make install - Enable the extension by adding it to your PHP configuration:
echo "extension=zip.so" | sudo tee -a /etc/php.ini - 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:
- Cleaning and updating your repositories:
sudo yum clean all sudo yum update - 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:
- Check for missing or conflicting dependencies:
sudo yum deplist php-zip - Install any missing dependencies:
sudo yum install [package-name] - If problems persist, use the
--skip-brokenoption to bypass conflicts:sudo yum install php-zip --skip-broken
You may also like:
- How to Install PHP JSON Extension on Ubuntu / CentOS: 7 Easy Step
- How to Install PHP 8.4 on RHEL 9: Easy Steps
- How to Install PHP 8.4 on RHEL 9: Easy Steps
- How to Install PHP Extensions for WordPress: 3 Easy Steps
Learn PHP
- PHP for Beginners
- PHP for Beginners â Become a PHP Master â CMS Project
- Become a WordPress Developer: Unlocking Power With Code
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.iniconfiguration includesextension=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.
Website Vidya Team
Technology educator and researcher at Website Vidya.
Related Technical Guides
Tested runbooks, server administration walkthroughs, and troubleshooting guides











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