Initial setup
- Download and extract the Thrift tarball
- Download and extract the Cassandra tarball
Building the PHP client
- Change to the thrift directory
- Install build dependencies.
- On Ubuntu:
sudo apt-get install libboost-dev automake libtool flex bison pkg-config g++
- On RHEL 5 or CentOS 5:
sudo yum install automake libtool flex bison pkgconfig gcc-c++ boost-devel libevent-devel zlib-devel python-devel ruby-devel
- On Ubuntu:
- Configure and build Thrift:
./configure make
- Build the PHP Thrift interface for Cassandra:
./compiler/cpp/thrift -gen php ../PATH-TO-CASSANDRA/interface/cassandra.thrift
- Copy the include files to a useful place (per the Cassandra "Getting Started" guide):
sudo mkdir -p /usr/share/php/Thrift sudo cp -R gen-php/ /usr/share/php/Thrift/packages/ sudo cp -R lib/php/src/* /usr/share/php/Thrift/
Building and installing the native PHP extension
Installing and using the native PHP extension provides approximately a ten-fold performance boost on writing data.
- Change to
PATH-TO-THRIFT/lib/php/src/ext/thrift_protocol
. - Install support for building PHP extensions:
- On Ubuntu:
sudo apt-get install php5-dev
- On CentOS:
sudo yum install php-devel
- On Ubuntu:
- Build the extension:
phpize ./configure --enable-thrift_protocol make
- Copy the extension's
.so
to the extensions directory.- On Ubuntu:
sudo cp modules/thrift_protocol.so /usr/lib/php5/20060613/
- On 64-bit CentOS:
sudo cp modules/thrift_protocol.so /usr/lib64/php/modules/
- On Ubuntu:
- Enable the module.
- On Ubuntu:
/etc/php5/conf.d/thrift_protocol.ini
extension=thrift_protocol.so
- On CentOS:
/etc/php.d/thrift_protocol.ini
extension=thrift_protocol.so
- On Ubuntu:
- Verify installation:
php -i | grep -v "PWD" | grep "thrift_protocol"
- Restart Apache.
- On Ubuntu:
sudo /etc/init.d/apache2 restart
- On CentOS:
sudo /etc/init.d/httpd restart
- On Ubuntu:
- Ensure that the PHP is using
TBinaryProtocolAccelerated
and notTBinaryProtocol
as the protocol.
Starting the server for development use
- Change to the Cassandra directory.
- Install the Sun Java runtime.
- Give Cassandra the permissions it needs:
WHOAMI=`whoami` sudo mkdir /var/log/cassandra/ sudo chown $WHOAMI /var/log/cassandra/ sudo mkdir /var/lib/cassandra sudo chown $WHOAMI /var/lib/cassandra/
- Start Cassandra in the foreground:
./bin/cassandra -f
Checking the connection
- Copy in the PHP from the Cassandra client examples page to
/var/www/cassandra-test.php
. - Visit
http://localhost/cassandra-test.php
in the browser. - On the first load, the array output should be empty. On the second, there should be content.