Programster's Blog

Tutorials focusing on Linux, programming, and open source

Debian 8 - Setting up PHP For Aerospike

This tutorial will show you what you need to need to do in order to start interfacing with an Aerospike database with PHP scripts.

If you haven't done so already, install PHP and composer.

sudo apt-get install php5-cli

# Install composer
curl -s | bash

Now we need to build the Aerospike extension and configure PHP to use it.

sudo apt-get install build-essential autoconf libssl-dev liblua5.1-dev
sudo apt-get install php5-dev php-pear 

composer require aerospike/aerospike-client-php
cd vendor/aerospike/aerospike-client-php/
find src/aerospike -name "*.sh" -exec chmod +x {} \;
sudo composer run-script post-install-cmd

cd src/aerospike
sudo make install 

sudo echo '
aerospike.udf.lua_user_path=/usr/local/aerospike/usr-lua' | sudo tee /etc/php5/cli/conf.d/aerospike.ini

A Basic Script

Now lets create a basic project that will run an Aerospike benchmark. The script below will need to be executed on the server itself.

cd $HOME
mkdir my-project
cd my-project
composer require aerospike/aerospike-client-php

Now create a script with the following contents and execute it...

require_once(__DIR__ . '/vendor/autoload.php');

print "Running write benchmark..." . PHP_EOL;
require_once(__DIR__ . '/vendor/aerospike/aerospike-client-php/examples/performance/write.php');

Reading the examples in the package are a great way to learn how to write code that interfaces with the database.