XAMPP – PHP Fatal error: Class ‘ZipArchive’ not found

I just finished writing a program written in PHP today. When I moved to the another environment, I found that the script didn’t work. After some investigations, I found that the program stopped running because of the following error:

PHP Fatal error:  Class 'ZipArchive' not found in ...

The error is obvious, some PHP extensions were missing. Therefore, I ran the following to see which modules were being loaded by the php:

#Make sure that the php is living in /opt/lampp/
#which php

#php -m
[PHP Modules]

Okay, the problem is clear, zip is missing.

For some (stupid) reasons, XAMPP (1.8.1) removes the zip support from the package. I don’t understand why because it was available in the older version (1.7.3). Removing a popular package will create troubles and backward compatibility issues. Anyway, the XAMPP is a non-professional product. It is not designed for production uses.

Before we go further, please make sure that your PHP is 5.4.7. It is because this tutorial is version specific.

#php -v

PHP 5.4.7

Here are the details:

#As always, we want to switch to root user first
sudo su

#Switch to the extension directory
cd /opt/lampp/lib/php/extensions/no-debug-non-zts-20100525

#Download the missing zip.so
#This zip.so was extracted from a 32-bit Linux environment, and was complied using PHP 5.4.7 32-bit i686
#It will not work with a different PHP version.
wget http://icesquare.com/download/zip.so

#Modify the permissions
chmod a+x zip.so
chown root:root zip.so

Now, we will need to modify the php.ini

#nano /opt/lampp/etc/php.ini

#Look for the zip.so and remove the comment



Next, we will need to verify that the extension is being loaded by php:

#php -m
[PHP Modules]
zip < ------------ This one

If everything looks good, we will need to restart the apache.

#/opt/lampp/lampp reloadapache

That’s it! Now the error is gone. You can also verify it by including phpinfo() in your code. It should display the details about the zip package.

My last word: Stay away from XAMPP when possible. It is using 32-bit stone-age technology, full of security-related bugs (because they release one or two versions ever year), and is packaged in a very non-professional way (such as backward compatibility). Consider to move to native Apache + PHP + MySQL. Believe me, you will see at least 10% of the performance improvement.


Our sponsors:

Leave a Reply

Your email address will not be published. Required fields are marked *