[Solved] Composer error: PHP extension zip is missing

Updated: January 12, 2024 By: Guest Contributor Post a comment

Introduction

If you’re working with PHP, Composer is an indispensable tool for managing your project’s dependencies. However, while installing or updating Composer, you may encounter an error message stating that the PHP extension zip is missing. This tutorial will guide you through the steps to solve this issue and get Composer running smoothly.

Understanding the Issue

The PHP extension zip error occurs when Composer detects that the required zip extension is not enabled in your PHP configuration. Composer requires the zip extension to unzip packages during the installation or update process.

Prerequisites

  • Access to the command line or terminal.
  • PHP installed on your system.
  • Basic understanding of PHP and Composer.

Steps to Fix the Error

Step 1: Check PHP Installation

Ensure that PHP is installed and properly configured on your system. You can check the version of PHP installed by typing the following command:

php -v

If PHP is not installed, you will need to install it before proceeding. Use the relevant package manager for your operating system to install PHP.

Step 2: Verify PHP Zip Extension

Check if the zip extension is currently installed and enabled in your PHP configuration. You can list the installed PHP extensions using:

php -m

If zip is not included in the list, it is not installed or enabled.

Step 3: Install PHP Zip Extension

The process to install the extension varies based on your operating system.

For Debian/Ubuntu:

sudo apt-get update
sudo apt-get install php-zip

For CentOS/Red Hat:

sudo yum update
sudo yum install php-zip

For Windows:

You need to edit the php.ini file to enable the extension. Locate your php.ini file (often found in your PHP installation directory), and uncomment the following line by removing the semicolon:

;extension=zip

Change it to:

extension=zip

Save the changes and restart your web server.

Step 4: Verify Installation

After installation or enabling the extension, you should verify that it is active. Restart your web server and check the list of PHP extensions again:

php -m

The zip extension should now be listed. If it’s not, ensure you restarted your web server and the changes were made to the correct php.ini file.

Step 5: Updating Composer

With the zip extension enabled, you can proceed to install or update Composer. Run the following command to get the latest version of Composer:

composer self-update

Further Troubleshooting

If you encounter further issues:

  • Check Composer’s documentation for any additional extensions required.
  • Ensure the PHP php.ini used by the command line matches the one used by your web server.
  • Consult your hosting provider’s resources or forums for any server-specific configurations.

Conclusion

By following these steps, the PHP extension zip is missing error in Composer should be resolved, allowing you to manage PHP dependencies effectively. Remember to keep your PHP and Composer installations up to date to avoid potential compatibility issues.