How to install Beanstalkd and Pheanstalk on Ubuntu

      Comments

1). Install Ubuntu Desktop or Server using a Virtual Machine.

I used Oracle VM VirtualBox for this example.

Make sure that a Bridged Network Connection has been set.

Set a username and a password when asked to.

I used:

username: william
password: 123456

2). Start Ubuntu and Login

3). Login as Super User

use: sudo su
and enter the super user password when requested ( mine is: 123456 );

4). Install Open SSH and access the Ubuntu virtual machine via Putty.

docs: https://help.ubuntu.com/10.04/serverguide/openssh-server.html

use: apt-get install openssh-client

to install the client and then

use: apt-get install openssh-server

to install the server;

5). Install Apache2 web server

use: apt-get install apache2

now type the following in a browser:

http://localhost
and
your virtual machine ip ( mine was 192.168.1.104 )

6). Install MySQL

use: apt-get install mysql-server php5-mysql

set password for MySQL root user: 123456
repeat password: 123456

7). Install PHP5

use: apt-get install php5 libapache2-mod-php5 php5-mcrypt

8). Install cURL

use: apt-get install curl

9). Install Composer

official website: https://getcomposer.org/
docs: https://getcomposer.org/doc/00-intro.md ( Getting Started )

use: curl -s http://getcomposer.org/installer | php
or
use: curl -sS https://getcomposer.org/installer | php
now, composer.phar must be moved and converted

use: mv composer.phar /usr/bin/composer

Why to use Composer?

Just imagine this:

A team is developing a project.
The project uses third party software and/or scripts;
These third party requirements can reach 1GB, 10GB, …

You don’t want to commit in GIT the vendor files.

So, each project will use a composer.json file that stores all the vendor apps information and settings. ( apps, modules, scripts, etc … )

When a new member/developer joins the team, he will clone the project, he will download only the project files and then run: composer update

After the download/update is finished, all the vendor files will be available and the new team member can use the project;

10). Install Beanstalkd

use: apt-get install beanstalkd

now, let’s make sure that beanstalkd persistent mode is active
ps ax

ps ax | grep beans

locate beanstalkd.conf

updatedb

locate beanstalkd.conf

nano /etc/default/beanstalkd

uncomment last line in order to save persistent mode to active

11). Install Pheanstalk

docs: https://github.com/pda/pheanstalk

change directory
use: cd /var/www/html

create a new directory: /var/www/html/pheanstalk_test
use: mkdir pheanstalk_test

change directory to the new created directory
use: cd pheanstalk_test

create a composer.json file under this new directory
use: nano composer.json

write the following data in the file:
{
„require”:{
„pda/pheanstalk”:”v3.0.0″
}
}

and save the file ( push Ctrl+X keys, push Y key, push ENTER key )

use: composer update

now, the vendor folder data should begin to download

or use: git clone https://github.com/pda/pheanstalk.git

examples:
how to put data on tube/s

<?php
include ‘vendor/autoload.php’;
use Pheanstalk\Pheanstalk;
$pheanstalk = new Pheanstalk(‘127.0.0.1’);
while(true){
$tube_id=rand(1,9);
$r1=rand(1,10000000);
$r2=rand(1,10000000);
$pheanstalk->useTube(‘testtube’.$tube_id)->put(‘{‘.$r1.’:’.$r2.’}’);
}
?>

use: php put.php
and a put process will start
info! the more instances open, the more data gets put on the tube/s

how to get data from tube/s

<?php
include ‘vendor/autoload.php’;
use Pheanstalk\Pheanstalk;
$pheanstalk = new Pheanstalk(‘127.0.0.1’);
while(true){
$tube_id=rand(1,9);
$job=$pheanstalk->watch(‘testtube’.$tube_id)->ignore(‘default’)->reserve();
if($job){
echo $job->getdata();
$pheanstalk->delete($job);
}
}
?>

use: php get.php
and a get process will start
info! the more instances open, the more data gets processed;
12). Install Beanstalk Console

docs: https://github.com/ptrofimov/beanstalk_console

change directory

use: cd /var/www/html

create a new folder

use: mkdir beanstalk_console

use: git clone https://github.com/ptrofimov/beanstalk_console.git

change the rights for the file: storage.json
chmod 777 storage.json

13). This is it!