Installing Cassandra PHP Extension
The Cassandra PHP Extension depends on the following libraries:
brew install libuv cmake gmp git
sudo apt-get install g++ make cmake libuv-dev libssl-dev libgmp-dev php5 php5-dev openssl libpcre3-dev git
sudo yum install automake cmake gcc gcc-c++ git libtool openssl-devel wget gmp gmp-devel boost php-devel pcre-devel git pushd /tmp wget http://libuv.org/dist/v1.4.2/libuv-v1.4.2.tar.gz tar xzf libuv-v1.4.2.tar.gz pushd libuv-v1.4.2 sh autogen.sh ./configure sudo make install popd popd
Refer to the official documentation for the DataStax C/C++ Driver for Apache Cassandra in case you’re having issues installing any of its dependencies.
Install the PHP extension
Installing with pecl
The PHP driver is published to the official PECL repository, in order to install it, you have to first install the 2.0 version of the C/C++ driver and then run the following command.
pecl install cassandra
You can also use PECL to install the driver from source by specifying the
provided package.xml file path as the argument to
pecl install command.
git clone https://github.com/datastax/php-driver.git cd php-driver pecl install ext/package.xml
Installing with submoduled, statically compiled version of the C/C++ driver
git clone https://github.com/datastax/php-driver.git cd php-driver git submodule update --init cd ext ./install.sh
Note The install.sh script will also compile and
statically link into the extension a submoduled version of the DataStax C/C++
driver for Apache Cassandra. To use a version of cpp driver that you already
have on your system, run
Don’t forget to enable the PHP extension after running install.sh:
echo -e "; DataStax PHP Driver\nextension=cassandra.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
We provide a self-contained batch script for building the PHP driver and all of its dependencies. In order to run it, you have to install the build dependencies and clone the repository with the DataStax PHP Driver for Apache Cassandra.
Obtaining Build Dependencies
- Download and install Bison.
- Make sure Bison is in your system PATH and not installed in a directory with
- Make sure Bison is in your system PATH and not installed in a directory with spaces (e.g.
- Download and install CMake.
- Make sure to select the option “Add CMake to the system PATH for all users” or “Add CMake to the system PATH for current user”.
- Download and install Git
- Make sure to select the option “Use Git from Windows Command Prompt” or manually add the git executable to the system PATH.
- Download and install ActiveState Perl
- Make sure to select the option “Add Perl to PATH environment variable”.
- Download and install Python v2.7.x
- Make sure to select/install the feature “Add python.exe to Path”
Building the Driver
The batch script detects installed versions of Visual Studio to simplify the build process on Windows. If you have more than one version of Visual Studio installed you will be prompted to which version to use when compiling the driver.
First you will need to open a “Command Prompt” to execute the batch script. Running the batch script without any arguments will build the driver for PHP v5.6 with Zend thread safety (ZTS) and for the current system architecture (e.g. x64).
To perform advanced build configuration, execute the batch script with the
--HELP argument to display the options available.
Usage: VC_BUILD.BAT [OPTION...] --DEBUG Enable debug build --RELEASE Enable release build (default) --DISABLE-CLEAN Disable clean build --DISABLE-THREAD-SAFETY Disable thread safety --ENABLE-PACKAGES [version] Enable package generation (5.5 and 5.6) (*) --ENABLE-TEST-CONFIGURATION Enable test configuration build --PHP-VERSION [version] PHP version 5.3, 5.4, 5.5, or 5.6 (**) --X86 Target 32-bit build (***) --X64 Target 64-bit build (***) C/C++ Driver Options --USE-BOOST-ATOMIC Use Boost atomic --HELP Display this message * Minimum supported officially released PHP binary installations ** Defaults to PHP v5.6 if --PHP-VERSION is not used *** Default target architecture is determined based on system architecture
Manual/PHP Step-by-Step Windows Build
The PHP driver extension can also be built using the
Build your own PHP on Windows
instructions followed by the
Building PECL extensions
instruction where the driver can be statically linked into the PHP executable
or as an import (DLL) library. This process requires that the binary
dependencies of the PHP driver extension be included in the
phpdev\vc##\x##\deps directory along with the standard PHP library
--enable-cassandra to built library into the PHP executable
--enable-cassandra=shared for import (DLL) library.
The PHP driver extension dependencies that are not included with the standard PHP library can be download here.
Note The binary libraries downloaded/used must be compatible with the MSVC++ compiler and the PHP driver extension.
Ensure the driver is built with –ENABLE-TEST-CONFIGURATION in order to execute the Behat test suite and PHPUnit unit tests. You will also need to install CCM; detailed instructions can be found in this blog post.