profile image
by elventails
on 23/5/14
I like this button6 people like this

Installing gearman + php extension on debian wheezy with PHP 5.4.x

#php 5.4.x #gearman #howto

Note:
Upgrading to PHP 5.4.x can give you the following gearman errors
(PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php5/20100525/gearman.so’ – /usr/lib/php5/20100525/gearman.so: undefined symbol: gearman_job_error in Unknown on line 0).

You can fix that by manually upgrading to the latest gearmand server, these steps worked for me:


1. Remove any previous apt installations of gearman, e.g.

# apt-get remove gearman gearman-job-server


2. Grab the latest tarball from Launchpad:
# wget https://launchpad.net/gearmand/1.2/1.1.12/+download/gearmand-1.1.12.tar.gz

3. Install dependencies
# apt-get install libboost-program-options-dev libboost-all-dev libevent-dev cloog-ppl gperf uuid-dev

4. Build it!
./configure
./make
./make install

5. Add gearman user (limited priv) and start gearman server and check the version
# mkdir /var/log/gearman-job-server
# ldconfig
# gearman -d
# gearadmin --server-version

6. Add the init script

#!/bin/sh

# Gearman server and library
# Copyright (C) 2008 Brian Aker, Eric Day
# All rights reserved.
#
# Use and distribution licensed under the BSD license. See
# the COPYING file in this directory for full text.

### BEGIN INIT INFO
# Provides: gearman-job-server
# Required-Start: $network $remote_fs $syslog
# Required-Stop: $network $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable gearman job server
### END INIT INFO

prefix=/usr/local
exec_prefix=${prefix}
NAME=gearmand
DAEMON=${exec_prefix}/sbin/gearmand
PIDDIR=/var/run/gearman
PIDFILE=${PIDDIR}/gearmand.pid
GEARMANUSER="root"
PARAMS=""

test -x ${DAEMON} || exit 0

. /lib/lsb/init-functions

test -f /etc/default/gearman-job-server && . /etc/default/gearman-job-server

start()
{
log_daemon_msg "Starting Gearman Server" "gearmand"
if ! test -d ${PIDDIR}
then
mkdir ${PIDDIR}
chown ${GEARMANUSER} ${PIDDIR}
fi
if start-stop-daemon \
--start \
--exec $DAEMON \
-- --pid-file=$PIDFILE \
--user=$GEARMANUSER \
--daemon \
--log-file=/var/log/gearman-job-server/gearman.log \
$PARAMS
then
log_end_msg 0
else
log_end_msg 1
log_warning_msg "Please take a look at the syslog"
exit 1
fi
}

stop()
{
log_daemon_msg "Stopping Gearman Server" "gearmand"
if start-stop-daemon \
--stop \
--oknodo \
--exec $DAEMON \
--pidfile $PIDFILE
then
log_end_msg 0
else
log_end_msg 1
exit 1
fi
}

status()
{
status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $?
}

case "$1" in

start)
start
;;

stop)
stop
;;

status)
status
;;

restart|force-reload)
stop
start
;;

*)
echo "Usage: $0 {start|stop|restart|force-reload|status}"
;;

esac


Extras:
6. Grab the PHP extension from PECL (don't forget to add extension=gearman.so in your php.ini)
# pecl install gearman