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
/opt/lampp/bin/php

#php -m
[PHP Modules]
...
...
xsl
zlib

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

#From
;extension="zip.so"

#To
extension="zip.so"

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

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

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.

–Derrick

Our sponsors:

install: /usr/ports/…/doc/: Inappropriate file type or format

While I tried to upgrade both of my FreeBSD server (9 & 10) today, I got the following error:

install: /usr/ports/…/doc/: Inappropriate file type or format

Actually, here is the complete error message:

===>  Staging for memcached-1.4.17_1
===>   memcached-1.4.17_1 depends on shared library: libevent-2.0.so - found
===>   Generating temporary packing list
/usr/bin/make  install-recursive
Making install in doc
/usr/bin/make  install-am
test -z "/usr/local/man/man1" || /bin/mkdir -p "/usr/ports/databases/memcached/work/stage/usr/local/man/man1"
 install  -o root -g wheel -m 444 memcached.1 '/usr/ports/databases/memcached/work/stage/usr/local/man/man1'
test -z "/usr/local/bin" || /bin/mkdir -p "/usr/ports/databases/memcached/work/stage/usr/local/bin"
  install  -s -o root -g wheel -m 555 memcached '/usr/ports/databases/memcached/work/stage/usr/local/bin'
test -z "/usr/local/include/memcached" || /bin/mkdir -p "/usr/ports/databases/memcached/work/stage/usr/local/include/memcached"
 install  -o root -g wheel -m 444 protocol_binary.h '/usr/ports/databases/memcached/work/stage/usr/local/include/memcached'
install  -o root -g wheel -m 555 /usr/ports/databases/memcached/work/memcached-1.4.17/scripts/memcached-tool /usr/ports/databases/memcached/work/stage/usr/local/bin
install  -o root -g wheel -m 444 /usr/ports/databases/memcached/work/memcached-1.4.17/doc/ /usr/ports/databases/memcached/work/stage/usr/local/man/man1
install: /usr/ports/databases/memcached/work/memcached-1.4.17/doc/: Inappropriate file type or format
*** [post-install] Error code 71

Stop in /usr/ports/databases/memcached.
*** [install] Error code 1

Stop in /usr/ports/databases/memcached.

Initially, I thought the problem was caused by the syntax error of the code, therefore, I tried to do the following:

#Shut down the server
sudo /usr/local/etc/rc.d/memcached stop

#Remove Memcached from the system
sudo make deinstall

#Clean up the package
sudo make clean

#Compile the package
sudo make

#Install the package
sudo make install

Unfortunately, it still gave the same error message. I noticed that the error message has something to do with the documentation, so I decide to remove the documentation option in the installation page, i.e.,

#Enter the package setup
sudo make config

#Remove the "doc" option.

Unfortunately, it still gave the same response. I then tried to investigate the cause of the error. So I tried to copy the error command and re-ran it:

install  -o root -g wheel -m 444 /usr/ports/databases/memcached/work/memcached-1.4.17/doc/ /usr/ports/databases/memcached/work/stage/usr/local/man/man1

Which return the exact the same error message:

install: /usr/ports/databases/memcached/work/memcached-1.4.17/doc/: No such file or directory

So I came up an idea. Since I don’t really need the documentation, why not I disable the document option?

cd /usr/ports/databases/memcached

sudo nano Makefile

Change the following from:

post-install:
        ${INSTALL_SCRIPT} ${WRKSRC}/scripts/memcached-tool ${STAGEDIR}${PREFIX}/bin
        ${INSTALL_MAN} ${WRKSRC}/doc/${MAN1} ${STAGEDIR}${MAN1PREFIX}/man/man1
        @${MKDIR} ${STAGEDIR}${DOCSDIR}

To:

post-install:
        ${INSTALL_SCRIPT} ${WRKSRC}/scripts/memcached-tool ${STAGEDIR}${PREFIX}/bin
#        ${INSTALL_MAN} ${WRKSRC}/doc/${MAN1} ${STAGEDIR}${MAN1PREFIX}/man/man1
        @${MKDIR} ${STAGEDIR}${DOCSDIR}

That’s right, I just want to comment out the installation of the man/documentation part. Now, let’s try to reinstall the package again.

#sudo make install

Guess what, it works! Have fun!

–Derrick

Our sponsors: