Jim Westergren
About me, my projects, SEO, Web Development and Personal Development since 2005
"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. Update: 7.1 now works but not 7.2.

This works as of 15th of may 2017 (and 11th of October 2018, article updated).

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
apt-get dist-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.1, Nginx and dependencies:

First we add the ondrej/php PPA:


apt-get install software-properties-common python-software-properties

add-apt-repository ppa:ondrej/php
add-apt-repository ppa:ondrej/nginx-mainline
apt-get update
apt-get install g++ make cmake libuv-dev libssl-dev libgmp-dev openssl libpcre3-dev git nginx php7.1 php7.1-common php7.1-curl php7.1-mbstring php7.1-intl php7.1-dev php7.1-fpm php7.1-mysql php7.1-xml php7.1-apcu redis-server

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.1-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.23.0/libuv1_1.23.0-1_amd64.deb
wget http://downloads.datastax.com/cpp-driver/ubuntu/16.04/dependencies/libuv/v1.23.0/libuv1-dev_1.23.0-1_amd64.deb
wget http://downloads.datastax.com/cpp-driver/ubuntu/16.04/cassandra/v2.10.0/cassandra-cpp-driver-dev_2.10.0-1_amd64.deb
wget http://downloads.datastax.com/cpp-driver/ubuntu/16.04/cassandra/v2.10.0/cassandra-cpp-driver_2.10.0-1_amd64.deb

dpkg -i libuv1_1.23.0-1_amd64.deb
dpkg -i libuv1-dev_1.23.0-1_amd64.deb
dpkg -i cassandra-cpp-driver_2.10.0-1_amd64.deb
dpkg -i cassandra-cpp-driver-dev_2.10.0-1_amd64.deb

Install the driver:

pecl install cassandra

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

nano /etc/php/7.1/fpm/php.ini

Restart PHP:

service php7.1-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 currently living in Spain. 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 .