Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ilarioengler's avatar

PHP-Driver DataStax Cassandra DB - How to use?

I've done the installation process as following:

System

PHP 7.0.5-1~dotdeb+8.1 (cli) ( NTS )

Debian 8

Nginx 1.8.1

Laravel 5.2

Java Installation

mkdir -p /usr/lib/jvm
wget URL to Oraclesite
mv mv jdk-8u77-linux-x64.tar.gz\?... jdk-8u77-linux-x64.tar.gz
tar xzf jdk-8u77-linux-x64.tar.gz
rm jdk-8u77-linux-x64.tar.gz
update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0_version/bin/java" 1
update-alternatives --set java /usr/lib/jvm/jdk1.8.0_version/bin/java

Install needed packages

apt install cmake automake libtool git php7.0-dev libgmp-dev libssl-dev

Libuv Installation

cd /tmp
wget http://dist.libuv.org/dist/v1.7.5/libuv-v1.7.5.tar.gz
tar xzf libuv-v1.7.5.tar.gz
rm libuv-v1.9.0.tar.gz
cd libuv-v1.7.5
sh autogen.sh
./configure
make
make install
ldconfig

Installation Cassandra Datatrax

echo "deb http://debian.datastax.com/community stable main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
curl -L http://debian.datastax.com/debian/repo_key | sudo apt-key add -
apt install cassandra dsc30

Check services

service cassandra status

cassandra.service - LSB: distributed storage system for structured data Loaded: loaded (/etc/init.d/cassandra) Active: active (running) since Mon 2016-04-11 01:11:04 CEST; 19min ago Process: 506 ExecStart=/etc/init.d/cassandra start (code=exited, status=0/SUCCESS) CGroup: /system.slice/cassandra.service

nodetool status

Datacenter: datacenter1 ======================= Status=Up/Down |/ State=Normal/Leaving/Joining/Moving -- Address Load Tokens Owns (effective) Host ID Rack UN 127.0.0.1 139.06 KB 256 100.0%
1ab0e99a-41a5-4007-b9ca-de58dc88e318 rack1

cqlsh

Connected to Test Cluster at 127.0.0.1:9042. [cqlsh 5.0.1 | Cassandra 3.0.4 | CQL spec 3.4.0 | Native protocol v4] Use HELP for help.

Installation php-driver (PECL Installation isn't working. I think it's because of only php7 setup)

git clone https://github.com/datastax/php-driver.git
cd php-driver
git submodule update --init
cd ext
./install.sh
make test -> all tests passed

Add Driver to PHP Extensions

echo -e "; DataStax PHP Driver\nextension=cassandra.so" >> /etc/php/7.0/cli/php.ini

Restart nginx

service nginx restart

Question:

If I wanna use the following code it says me class Cassandra not found. But which Class do I have to import? I can't find anything here -> https://github.com/datastax/php-driver#datastax-php-driver-for-apache-cassandra

$cluster = Cassandra::cluster()->build();

Thank you for helping.

0 likes
5 replies
saleh_mir's avatar

Is this for using Cassandra database in Laravel 5.2? Cuz I've been looking for such thing for months. Please somebody answer, as it is also my question.

It'll be great if Jeffrey could make a such video for Cassandra, I will subscribe for life if he does!

halink0803's avatar

After installing php-driver for cassandra, you need to check if it was enabled correctly:

    php -m | grep cassandra

if it's good (print cassandra),

    cassandra

then you just need to add 'use Cassandra' to your controller where you connect to cassandra database.

Hope it helps,

ptcarino's avatar

@halink0803

encountered an error: "Undefined property: Cassandra\Cluster\Builder::$build"

i got cassandra installed as well as the datastax php driver and i added use Cassandra on my controller.

Yarik's avatar

Hi, I have installed cassandra on my server Debian GNU/Linux 8.7 (jessie) I have installed php7.1 and me need been installed php-driver(for cassandra) nextly commands: git clone https://github.com/datastax/php-driver.git /usr/src/datastax-php-driver cd /usr/src/datastax-php-driver git submodule update --init cd ext ./install.sh

vim /etc/php/7.1/mods-available/cassandra.ini extension=cassandra.so

phpenmod cassandra

php -i | grep cassandra /etc/php/7.1/cli/conf.d/20-cassandra.ini, cassandra cassandra.log => cassandra.log => cassandra.log cassandra.log_level => ERROR => ERROR

Well, that's ok, but

When, I have tried running test connect(php) to cassandra, I had error.

php cass.php PHP Fatal error: Uncaught Cassandra\Exception\LogicException: Not implemented in /root/cass.php:3 Stack trace: #0 /root/cass.php(3): Cassandra\Cluster\Builder->build() #1 {main} thrown in /root/cass.php on line 3

cat cass.php

Please or to participate in this conversation.