Install Gearman Job Server with Postgres

1.Add repository:
vim /etc/apt/sources.list

2.Add line in the end off file:
deb http://ppa.launchpad.net/gearman-developers/ppa/ubuntu raring main

3.Update ubuntu repository:
sudo apt-get update

4.Add key for new repo:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys NUMBER

5.Install gearman:
sudo apt-get install gearman-job-server libgearman-dev gearman-tools -y

6.Edit file */etc/default/gearman-job-server *:
sudo vim /etc/default/gearman-job-server

7.Add this in the file:
export PGHOST=127.0.0.1 export PGPORT=5432
export PGUSER=gearman
export PGPASSWORD=gearman
export PGDATABASE=gearman
PARAMS="--listen=localhost -q Postgres --libpq-table=gearmanqueue"

8.Save and stop the server:
sudo service gearman-job-server stop

9.Install php gearman extension:
cd /tmp/ git clone https://github.com/wcgallego/pecl-gearman.git
cd pecl-gearman/
sudo phpize7.0
sudo ./configure
sudo make
sudo make install

10.Add "extension=gearman.so" in the end of file:
sudo vim /etc/php/7.0/fpm/php.ini

11.Restart fpm:
sudo service php7.0-fpm restart

12.Create db and user in postgres for gearman:
sudo su - postgres psql
CREATE DATABASE gearman;
CREATE USER gearman with password 'gearman';
GRANT ALL PRIVILEGES ON DATABASE gearman to gearman;
\q

13.Create table for gearman queue:
psql -h localhost -U gearman -d gearman

CREATE TABLE gearmanqueue ( unique_key VARCHAR(255), function_name VARCHAR(255), priority INTEGER, data BYTEA, when_to_run INTEGER, UNIQUE (unique_key, function_name));

14.Restart job server:
sudo /etc/init.d/gearman-job-server restart

Enjoy