Linux is really crazy. I’m used to Windows. On windows, I download a program, and run it. If it doesn’t work- the program is broken. Maybe I can download a newer/older version, but for all intents and purposes that is all there is to it. But with Linux- you can usually get something to work, but it takes a lot of time and sleuthing. I definitely prefer the windows workflow. But hey- it’s free as in freedom, right?

I was trying to install the PHP Gearman module, but I kept getting compilation errors. Here is how I fixed it!

Gearman is a distributed job system written and released by the good folks at Danga Interactive. (They also made memcache). I setup a blank Ubuntu server and I wanted to test it out, but it didn’t go so well.

Here is the standard procedure:
apt-get update
apt-get install php5-cli php5-dev pear
apt-get install gearman-job-server libgearman2 libgearman-dev gearman-tools
pecl install “channel://pecl.php.net/gearman-0.7.0″

Usually the pecl command magically compiles php modules, but this time it did not.


This post details doing the following:

1) Install the libevent-dev libuuid-dev packages

2) Modify a libuuid files for some changes made to debian regarding .la files

3) Install the gearman repositories for apt to download the latest version of libgearman


First I had some missing dependencies.

pecl install “channel://pecl.php.net/gearman-0.7.0″
——————-
running: make
/bin/bash /var/tmp/pear-build-root/gearman-0.6.0/libtool –mode=compile cc -I.
-I/tmp/pear/temp/gearman -DPHP_ATOM_INC -I/var/tmp/pear-build-root/gearman-0.6.0/include
-I/var/tmp/pear-build-root/gearman-0.6.0/main -I/tmp/pear/temp/gearman -I/usr/include/php5
-I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext
-I/usr/include/php5/ext/date/lib -DHAVE_CONFIG_H -g -O2 -Wall -c
/tmp/pear/temp/gearman/php_gearman.c -o php_gearman.lo
libtool: compile: cc -I. -I/tmp/pear/temp/gearman -DPHP_ATOM_INC
-I/var/tmp/pear-build-root/gearman-0.6.0/include -I/var/tmp/pear-build-root/gearman-0.6.0/main
-I/tmp/pear/temp/gearman -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM
-I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -DHAVE_CONFIG_H -g
-O2 -Wall -c /tmp/pear/temp/gearman/php_gearman.c -fPIC -DPIC -o .libs/php_gearman.o
In file included from /tmp/pear/temp/gearman/php_gearman.c:24:
/usr/include/libgearman/gearman.h:28:19: error: event.h: No such file or directory
make: *** [php_gearman.lo] Error 1
ERROR: `make’ failed
——————-

so I needed to install the event and uuid libs:
apt-get install libevent-dev uuid-dev

pecl install “channel://pecl.php.net/gearman-0.7.0″
——————-
running: make
/bin/bash /var/tmp/pear-build-root/gearman-0.6.0/libtool –mode=compile cc -I.
-I/tmp/pear/temp/gearman -DPHP_ATOM_INC -I/var/tmp/pear-build-root/gearman-0.6.0/include
-I/var/tmp/pear-build-root/gearman-0.6.0/main -I/tmp/pear/temp/gearman -I/usr/include/php5
-I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext
-I/usr/include/php5/ext/date/lib -DHAVE_CONFIG_H -g -O2 -Wall -c
/tmp/pear/temp/gearman/php_gearman.c -o php_gearman.lo
libtool: compile: cc -I. -I/tmp/pear/temp/gearman -DPHP_ATOM_INC
-I/var/tmp/pear-build-root/gearman-0.6.0/include -I/var/tmp/pear-build-root/gearman-0.6.0/main
-I/tmp/pear/temp/gearman -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM
-I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -DHAVE_CONFIG_H -g
-O2 -Wall -c /tmp/pear/temp/gearman/php_gearman.c -fPIC -DPIC -o .libs/php_gearman.o
/bin/bash /var/tmp/pear-build-root/gearman-0.6.0/libtool –mode=link cc -DPHP_ATOM_INC
-I/var/tmp/pear-build-root/gearman-0.6.0/include -I/var/tmp/pear-build-root/gearman-0.6.0/main
-I/tmp/pear/temp/gearman -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM
-I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -DHAVE_CONFIG_H
-g -O2 -Wall -o gearman.la -export-dynamic -avoid-version -prefer-pic -module -rpath
/var/tmp/pear-build-root/gearman-0.6.0/modules php_gearman.lo -lgearman
libtool: link: cc -shared .libs/php_gearman.o /usr/lib/libgearman.so -pthread -Wl,-soname
-Wl,gearman.so -o .libs/gearman.so
/bin/sed: can’t read /usr/lib/libuuid.la: No such file or directory
libtool: link: `/usr/lib/libuuid.la’ is not a valid libtool archive

so now that I have uuid, I’m still getting errors. I found a great blog post that helped me with this error!

After some googling, it turns out that .la files are now gone from many packages, as per this post on debian-devel list. Couldn't really find a good solution for this, so here it is:

Open /usr/lib/libgearman.la as root, and find a line that says:
dependency_libs=' -L/usr/lib /usr/lib/libuuid.la'

Replace it with:
dependency_libs=' -L/usr/lib -luuid'

Now, it should work, right? AAAAAAAAALMOST, but not quite.

sudo pecl install “channel://pecl.php.net/gearman-0.7.0″
————————————————-
running: make
/bin/bash /var/tmp/pear-build-root/gearman-0.7.0/libtool –mode=compile cc -I.
-I/tmp/pear/temp/gearman -DPHP_ATOM_INC -I/var/tmp/pear-build-root/gearman-0.7.0/include
-I/var/tmp/pear-build-root/gearman-0.7.0/main -I/tmp/pear/temp/gearman -I/usr/include/php5
-I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext
-I/usr/include/php5/ext/date/lib -DHAVE_CONFIG_H -g -O2 -Wall -c
/tmp/pear/temp/gearman/php_gearman.c -o php_gearman.lo
libtool: compile: cc -I. -I/tmp/pear/temp/gearman -DPHP_ATOM_INC
-I/var/tmp/pear-build-root/gearman-0.7.0/include -I/var/tmp/pear-build-root/gearman-0.7.0/main
-I/tmp/pear/temp/gearman -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM
-I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -DHAVE_CONFIG_H -g
-O2 -Wall -c /tmp/pear/temp/gearman/php_gearman.c -fPIC -DPIC -o .libs/php_gearman.o
In file included from /tmp/pear/temp/gearman/php_gearman.c:24:
/usr/include/libgearman/gearman.h:28:19: error: event.h: No such file or directory
/tmp/pear/temp/gearman/php_gearman.c: In function ‘zm_startup_gearman’:
/tmp/pear/temp/gearman/php_gearman.c:4467: error: ‘GEARMAN_VERBOSE_NEVER’ undeclared (first use in
this function)
/tmp/pear/temp/gearman/php_gearman.c:4467: error: (Each undeclared identifier is reported only once
/tmp/pear/temp/gearman/php_gearman.c:4467: error: for each function it appears in.)
make: *** [php_gearman.lo] Error 1
ERROR: `make’ failed
————————————————-

Next I found there is some kind of issue with libgearman in debian. You have to install the latest version of gearman directly from the creators to fix this one.

Add the gearman sources to your /etc/sources.list file:
————————————————-
deb http://ppa.launchpad.net/gearman-developers/ppa/ubuntu lucid main
deb-src http://ppa.launchpad.net/gearman-developers/ppa/ubuntu lucid main
————————————————-
Add their key so apt can verify their packages:
sudo apt-key adv –keyserver keyserver.ubuntu.com –recv-keys 1C73E014

update apt and re-install all the gearman packages:
apt-get update
apt-get install gearman-job-server libgearman2 libgearman-dev gearman-tools

Rejoice!!

pecl install “channel://pecl.php.net/gearman-0.7.0″
————————————————-
running: make
/bin/bash /var/tmp/pear-build-root/gearman-0.7.0/libtool –mode=compile cc -I. -I/tmp/pear/temp/gearman -DPHP_ATOM_INC -I/var/tmp/pear-build-root/gearman-0.7.0/include -I/var/tmp/pear-build-root/gearman-0.7.0/main -I/tmp/pear/temp/gearman -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -DHAVE_CONFIG_H -g -O2 -Wall -c /tmp/pear/temp/gearman/php_gearman.c -o php_gearman.lo
libtool: compile: cc -I. -I/tmp/pear/temp/gearman -DPHP_ATOM_INC -I/var/tmp/pear-build-root/gearman-0.7.0/include -I/var/tmp/pear-build-root/gearman-0.7.0/main -I/tmp/pear/temp/gearman -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -DHAVE_CONFIG_H -g -O2 -Wall -c /tmp/pear/temp/gearman/php_gearman.c -fPIC -DPIC -o .libs/php_gearman.o
/bin/bash /var/tmp/pear-build-root/gearman-0.7.0/libtool –mode=link cc -DPHP_ATOM_INC -I/var/tmp/pear-build-root/gearman-0.7.0/include -I/var/tmp/pear-build-root/gearman-0.7.0/main -I/tmp/pear/temp/gearman -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -DHAVE_CONFIG_H -g -O2 -Wall -o gearman.la -export-dynamic -avoid-version -prefer-pic -module -rpath /var/tmp/pear-build-root/gearman-0.7.0/modules php_gearman.lo -lgearman
libtool: link: cc -shared .libs/php_gearman.o /usr/lib/libgearman.so -pthread -Wl,-soname -Wl,gearman.so -o .libs/gearman.so
libtool: link: ( cd “.libs” && rm -f “gearman.la” && ln -s “../gearman.la” “gearman.la” )
/bin/bash /var/tmp/pear-build-root/gearman-0.7.0/libtool –mode=install cp ./gearman.la /var/tmp/pear-build-root/gearman-0.7.0/modules
libtool: install: cp ./.libs/gearman.so /var/tmp/pear-build-root/gearman-0.7.0/modules/gearman.so
libtool: install: cp ./.libs/gearman.lai /var/tmp/pear-build-root/gearman-0.7.0/modules/gearman.la
libtool: finish: PATH=”/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin:/sbin” ldconfig -n /var/tmp/pear-build-root/gearman-0.7.0/modules
———————————————————————-
Libraries have been installed in:
/var/tmp/pear-build-root/gearman-0.7.0/modules

————————————————-

Now you just have to make sure that php.ini contains:

extension=gearman.so

If this saved you some time. Leave me a comment, and I’ll post more of my boring linux adventures!