How to install PECL PHP extension on 64bit linux while you are using 32bit XAMPP
OK, here is a problem. I wanted to play a little bit with uploadprogress PECL extension. Normally installation of PECL extension is very easy, you just do
$sudo ./bin/pecl install uploadprogress
form console and PECL installer would do the rest, which was my case also - extension was downloaded from Internet and compiled successfully. After adding extension="uploadprogress.so" to php.ini and restarting XAMPP I've got next error
$ sudo ./lampp restartapache
XAMPP: Stopping Apache with SSL...
Warning: PHP Startup: Unable to load dynamic library '/opt/lampp/lib/php/extensions/no-debug-non-zts-20090626/uploadprogress.so' - /opt/lampp/lib/php/extensions/no-debug-non-zts-20090626/uploadprogress.so: wrong ELF class: ELFCLASS64 in Unknown on line 0
Running file on uploadprogress.so confirmed that system compiled 64bit version of library
$ file lib/php/extensions/no-debug-non-zts-20090626/uploadprogress.so
lib/php/extensions/no-debug-non-zts-20090626/uploadprogress.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, not stripped
When you sit back and think for a moment, this is actually OK because I am running 64bit version of Kubuntu and 32bit version of XAMPP (there is no 64bit version of XAMPP for now) for my development environment, so my C compiler and linker are 64bit and will produce 64bit libraries.
Here is a solution for this situation.
First you need to add 32bit libraries for compilation, for example on ubuntu systems this would look like
$sudo apt-get install g++-multilib
Then you need to manually download PHP PECL extension that you want
$tar xzf uploadprogress-1.0.1.tgz
Now if you have multiple PHP installed, like I do, you need to tell in console which one you want to use currently. I for example have /usr/bin/php installed from my package manager, but my main php is in my XAMPP which is on /opt/lampp/bin path. So first you need to find out which php you are currently using in console
Now we are ready to compile and link our PHP extension
$CFLAGS=-m32 CPPFLAGS=-m32 CCASFLAGS=-m32 ./configure
This m32 flags are telling compiler to create 32bit extension. All we have to do now is to copy our new extension to current XAMPP PHP extension directory
$cp modules/uploadprogress.so /path_to_ext_lib
And then add "extension=uploadprogress.so" to our php.ini.
That's it, we now have 32bit version of uploadprogress.so PHP extension which is compatible with our XAMPP installation.
Note: if you are getting following error when trying to restart apache or when you start php from command line
Warning: PHP Startup: uploadprogress: Unable to initialize module
Module compiled with module API=20060613
PHP compiled with module API=20090626
These options need to match
That actually means that you have compiled PECL extension against wrong PHP header files - which was exactly the error I have done. I upgraded XAMPP couple of times in the past, but didn't refresh development packages. Downloading latest development package from http://www.apachefriends.org/download.php?xampp-linux-devel-1.7.4.tar.gz and updating my XAMPP installation fixed this - of course you need to recompile extension again.