Cassandra DataStax PHP Extension Setup

General Docs
DataStax PHP Driver

DataStax Driver PHP Docs

Native Linux
Follow DataStax linux installation steps (after installing dependencies). It works if you have conventional setup. You will need to install a lot of c++ development libraries for the compilation to work. Running a package manager install for a popular application build-tools should give you everything you need. I used…

sudo apt-get install build-essential
apt-get build-dep nginx
apt-get install php5-dev

Make sure to add cassandra to php.ini
; DataStax PHP Driver
extension=cassandra.so

 

OSX w/ MAMP:
For MAMP we need to hack the extension compilation scripts to point to the correct¬†php directories. If you don’t you’ll get an an error when php starts up (enable startup error displays in php.ini) like this…

MacBook-Pro:code User$ php -v

Warning: PHP Startup: cassandra: Unable to initialize module
Module compiled with module API=20100525
PHP    compiled with module API=20131226
These options need to match
 in Unknown on line 0
PHP 5.6.2 (cli) (built: Oct 20 2014 16:21:27) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies

This is bcs we’re trying to use php that’s linked in MAMP (/Applications/MAMP/bin/php), but the module was compiled using the OSX php installation (/usr/bin/php).. and they’re different versions.

The fix is to download the correct php version source and make sure the module compilation uses the correct version’s source.
This link outlines compiling cassandra php extensions with correct source.

I also made sym-links for php, php-config, and phpize like this example.
This is some general background information on compiling php extensions on alternative configurations.

I also edit the ext/install.sh script with the following code…

echo "Compiling and installing the extension..."
phpdir=/Applications/MAMP/bin/php/php5.6.2 {{put in your correct php version directory}}
$phpdir/bin/phpize

`$phpsizecommand`

echo ./configure --with-php-config=$phpdir/bin/php-config --with-cassandra=$builddir --with-libdir=lib
LIBS="-lssl -lz -luv -lm -lstdc++" LDFLAGS="-L$builddir/lib" ./configure --with-cassandra=$builddir --with-libdir=lib --with-php-config=$phpdir/bin/php-config
make
make install

rm -Rf /tmp/php-driver-installation

Also don’t forget to do a clean between code changes

make clean

Leave a Reply

Your email address will not be published. Required fields are marked *

57 − = 55

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>