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 https://scripts.programster.org/scripts/21?output=raw | 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 'extension=aerospike.so
aerospike.udf.lua_system_path=/usr/local/aerospike/lua
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...

<?php
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.

References

Last updated: 16th September 2021
First published: 16th August 2018

This blog is created by Stuart Page

I'm a freelance web developer and technology consultant based in Surrey, UK, with over 10 years experience in web development, DevOps, Linux Administration, and IT solutions.

Need support with your infrastructure or web services?

Get in touch