Fixing the PHP Ziparchive Not Found Error
* Web 2.0 University is supported by it's audience. If you purchase through links on our site, we may earn an affiliate commision.
The “PHP ZipArchive class not found” error typically occurs when the Zip extension is not installed or enabled in your PHP environment.
Here’s how you can resolve this issue:
Install Zip Extension
Depending upon your server’s operating system, the command to install the zip extension varies:
On Ubuntu/Debian systems, you can use the following command:
sudo apt-get install php-zip
On CentOS/RHEL systems, you can use:
sudo yum install php-pecl-zip
Enable Zip Extension
After installing the extension, you need to enable it.
For many systems, installing the package will automatically enable it. However, if it doesn’t, you will have to manually enable it by modifying your php.ini file (the configuration file for PHP). You can find this file’s location by creating a PHP file with the following code and accessing it from your web server:
<?php phpinfo(); ?>
This file will display a lot of information about your PHP installation. Look for “Loaded Configuration File” to find the path to your php.ini file.
Open your php.ini file and look for a line like ;extension=zip. If the line is present, remove the semicolon at the beginning of the line to uncomment it and enable the extension. If the line is not present, add extension=zip at the bottom of the file.
Restart Your Web Server
After installing and enabling the extension, you need to restart your web server for the changes to take effect. The command to do this will depend on your web server and system, but here are the commands for Apache on Ubuntu and CentOS:
Ubuntu:
sudo service apache2 restart
CentOS:
sudo service httpd restart
After following these steps, the ZipArchive class should be available in your PHP environment. You can confirm this by creating a PHP file with the following code and accessing it from your web server:
<?php
if (class_exists('ZipArchive')) {
echo 'ZipArchive is available';
} else {
echo 'ZipArchive is not available';
}
This code will tell you whether the ZipArchive class is available or not. If it’s available, you have successfully resolved the issue. If it’s not, there might be an issue with your PHP installation or configuration.