PhpSpreadSheet报Class ZipArchive not found错误:本地正常服务器异常求助
Hey there, let's sort out that annoying error you're hitting when trying to generate Excel files with PhpSpreadSheet on your PHP 5.6 server. The core issue here is that PhpSpreadSheet relies on the ZipArchive extension to handle compressed Excel formats (like .xlsx), and your server's PHP 5.6 setup either doesn't have this extension installed or enabled.
Here's how to fix it based on your server's operating system:
For Linux Servers
- Install the ZipArchive extension
Depending on your distro, run the appropriate command:- Debian/Ubuntu:
sudo apt-get install php5.6-zip - CentOS/RHEL (using Remi repo for PHP 5.6):
sudo yum install php56u-zip
- Debian/Ubuntu:
- Restart your web server
After installation, you need to reload your web server and PHP-FPM (if you're using it) to apply the changes:# For Apache sudo service apache2 restart # For Nginx + PHP-FPM sudo service nginx restart sudo service php5.6-fpm restart
For Windows Servers
- Enable the ZipArchive extension
- Locate the
php.inifile for your PHP 5.6 installation (usually in the PHP root directory on your server) - Open it and look for a line that reads
;extension=php_zip.dll - Remove the leading semicolon (
;) to uncomment it, so it becomesextension=php_zip.dll
- Locate the
- Restart your web server
Reboot IIS or Apache to make sure the extension loads properly.
Quick Check to Verify
If you're still seeing the error after these steps, create a simple phpinfo.php file with this content:
<?php phpinfo(); ?>
Upload it to your server, access it in your browser, and search for "ZipArchive". If you see a section for it, the extension is loaded correctly—if not, double-check your config or installation steps.
One last note: PhpSpreadSheet's official minimum PHP version is 7.1, so while PHP 5.6 might work temporarily, you'll likely run into more compatibility issues down the line. If possible, upgrading your server's PHP version to 7.1 or higher will save you a lot of headaches!
内容的提问来源于stack exchange,提问作者Ambili Bijesh

