How to Install the Cassandra PHP Extension on macOS 10.13 High Sierra and 10.14 Mojave

An easy step-by-step guide to get Cassandra working with PHP on a Mac.

Casey McMullen
4 min readSep 30, 2018

I recently experienced the frustration of trying to get the Cassandra PHP extension installed and working on my MacBook Pro running High Sierra. DataStax offers some instructions on their web site, but the Mac OS instructions from their site do not work with 10.13 High Sierra or 10.14 Mojave. You get to the point where you’re trying to build the C++ driver (a dependency for the PHP driver) and it fails. There’s no troubleshooting instructions and ultimately I was able to cobble something together from other articles and forums to finally get it working.

This guide is merely a place for me to document my installation steps and hopefully they’ll help someone else along the way. These steps are a combination of what is provided on the DataStax site along with things I’ve learned from other sites and forums.

Let’s get started!

Install PHP and PECL

The DataStax instructions to install PHP do not work because they do not take into account that on April 1, 2018, Homebrew deprecated the “Homebrew/php” tap in favor of a new “Homebrew/core” approach. In addition, although some critical extensions are still supported (e.g. MySQLi), most PHP extensions are no longer distributed through Homebrew at all (e.g. php71-xdebug, php71-redis, etc.) and require installation through PECL (PHP Extension Community Library).

If you don’t have PHP and PECL installed and working on your MacOS setup you can refer to my article How to Install PHP on macOS 10.13 High Sierra and 10.14 Mojave using Homebrew and PECL.

Install Dependencies

I prefer to run these commands one at a time so I can easily see errors or warnings. Run all of these commands, you will discover that some of these dependencies may already be installed on your Mac, but it doesn’t hurt to run them and be sure.

$ brew install autoconf
$ brew install cmake
$ brew install automake
$ brew install libtool

Install GNU Multiple Precision Arithmetic (GMP)

Again, you may discover this is already installed and that’s ok.

$ brew install gmp

Install libuv

$ brew install libuv

Install OpenSSL

As before, this is probably already installed on your Mac, but we’re going to make sure.

$ brew install openssl

The DataStax instructions page then makes a note that if you’re running Mac OS X 10.11 (El Capitan) or Mac OS 10.12 (Sierra), a link needs to be created in order to make OpenSSL available to the building libraries. Therefore you’ll need to run the command “brew link --force openssl”.

I can tell you that command will not work on 10.13 High Sierra or 10.14 Mojave. We’re going to run a command later that will accomplish everything we need to have happen, and you don’t need to worry about that command no matter what version you’re running.

Install Git

If you don’t already have Git installed (it actually comes pre-installed on High Sierra and Mojave) then you should install it.

$ brew install git

Retrieve and Build the C/C++ Driver

This is where we depart from the instructions provided by DataStax. The steps they outline just do not work for later macOS installs at this point.

Clone the driver source from GitHub into a folder on your Mac. It will create a folder called cpp-driver.

$ git clone https://github.com/datastax/cpp-driver.git --depth=1

Create a build directory in your new folder and then navigate into it.

$ mkdir cpp-driver/build$ cd cpp-driver/build

Build the C/C++ driver with a qualified reference to OpenSSL.
(**Note: the first line is a single line command that has wrapped. Make sure to copy and paste the entire line).

$ cmake -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl/ -DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib ..$ make$ make install

Install the Cassandra PHP extension

Now you’re good to install the Cassandra PHP extension using PECL.

$ pecl install cassandra

Enable the PHP extension

It’s likely that the PECL install will add the extension automatically to your php.ini file. However you’ll need to go check.

The following command to open your php.ini file assumes you’ve followed my instructions for installing PHP on your Mac found here. Otherwise you’ll need to open the file in whatever location it resides in your install.

Open your php.ini file for editing:

$ open -e /usr/local/etc/php/7.1/php.ini

Search for the extension name “cassandra.so” in your file. If you don’t find an entry, you can add the following lines to your file (I recommend at the bottom).

[cassandra]
extension="cassandra.so"

Now all you need to do is restart Apache (or your web server of choice) to have the extension loaded with PHP.

$ sudo apachectl -k restart

And that’s it! You should be ready to start using Cassandra in your PHP files. You can refer back to the examples found here on DataStax to get you going.

I hope this helped you!

There’s more!

Make sure to check out my other articles here to learn more about setting up your PHP development environment on your Mac and other coding tips and examples.

--

--

Casey McMullen

Co-Founder & CEO at Another™ : Web Developer : Tech Geek : Guitar Player