Jim Westergren
A blog about me, my projects, SEO, Web Development and Personal Development.
"If we did all the things we are capable of, we would literally astound ourselves." - Thomas A. Edison

Installing Apache Cassandra with PHP 7 on Ubuntu 16.04

I spent a lot of time and paid for some help (thanks David Donari!) to figure out how to install Apache Cassandra with PHP 7 and the Datastax PHP Driver. I needed additional Cassandra servers with PHP and had to find a solution to this.

Following the official installation instructions ... will not work. It will end up with the same errors as this guy and the solution proposed there won't work anymore. Or you get the same errors as these guys. In addition you need Apache Cassandra version 3.10 otherwise it won't work with the new version of Python, so forget about these instructions. And nobody tells you that you have to use PHP 7.0 and not 7.1 as that won't work as well.

This works as of 15th of may 2017.

I start with a fresh install of Ubuntu 16.04 LTS.

Enter a temp directory (something I normally do):

cd /
mkdir temp
cd temp

Update and upgrade the system:

apt-get update
apt-get upgrade

Install Java:

apt-get install default-jre
apt-get install default-jdk

Install Apache Cassandra version 3.10:

echo "deb http://www.apache.org/dist/cassandra/debian 310x main" | tee -a /etc/apt/sources.list.d/cassandra.sources.list
curl https://www.apache.org/dist/cassandra/KEYS | apt-key add -
apt-get update
apt-get install cassandra

Start Cassandra with service cassandra restart or cassandra -R and then check nodetool status to make sure all is well.

Install PHP 7, Nginx and dependencies:

apt-get install g++ make cmake libuv-dev libssl-dev libgmp-dev openssl libpcre3-dev git php-pear php7.0-dev nginx php-fpm

Configure Nginx:

nano /etc/nginx/nginx.conf

Something super simple would be:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html;
    index index.php index.html;

    server_name 12.34.455.565;

    location / {
        try_files $uri $uri/ =404;

    location ~ .php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;

Restart Nginx:

service nginx restart

Remove old conflicting version of libuv-dev (surprise!!):

apt-get remove libuv0.10-dev

Download and install latest versions of libuv and the Cassandra C++ driver (Datastax has files in both in directory dependencies and dependenices just to confuse you more):

wget http://downloads.datastax.com/cpp-driver/ubuntu/16.04/dependencies/libuv/v1.11.0/libuv_1.11.0-1_amd64.deb
wget http://downloads.datastax.com/cpp-driver/ubuntu/16.04/dependencies/libuv/v1.11.0/libuv-dev_1.11.0-1_amd64.deb
wget http://downloads.datastax.com/cpp-driver/ubuntu/16.04/cassandra/v2.6.0/cassandra-cpp-driver-dev_2.6.0-1_amd64.deb
wget http://downloads.datastax.com/cpp-driver/ubuntu/16.04/cassandra/v2.6.0/cassandra-cpp-driver_2.6.0-1_amd64.deb

dpkg -i libuv_1.11.0-1_amd64.deb
dpkg -i libuv-dev_1.11.0-1_amd64.deb
dpkg -i cassandra-cpp-driver_2.6.0-1_amd64.deb
dpkg -i cassandra-cpp-driver-dev_2.6.0-1_amd64.deb

Install the driver:

pecl install cassandra

Add extension=cassandra.so to the php.ini:

nano /etc/php/7.0/fpm/php.ini

Restart PHP:

service php7.0-fpm restart

You also need to configure Cassandra of course:

nano /etc/cassandra/cassandra.yaml

I hope this is of help to somebody else out there.



15 May 2017

About the Author Jim Westergren Jim Westergren is a Swedish web entrepreneur. He is happily married and has three lovely children. Some of his interests are web development, SEO and writing. He is the Founder of DomainStats and N.nu. Read his .

Design, text and CMS (N.nu) by myself.