Compiling Cassandra DataStax PHP Driver on MAMP

DataStax PHP Driver

DataStax Driver PHP Docs

OSX w/ MAMP:
Following installation tutorial
Installed dependencies using brew …

brew install libuv cmake gmp

Had to add MAMP php bin to PATH …

export PATH="$PATH:/Applications/MAMP/bin/php/php5.6.2/bin/"

I added that to my ~./bash_profile.

Had to install autoconf …

brew install autoconf

Had to install pcre …

brew install pcre

In the end the full make install failed bcs it was trying to use native php paths instead of the MAMP ones….

+ make install
Installing shared extensions:     /usr/lib/php/extensions/no-debug-non-zts-20100525/
cp: /usr/lib/php/extensions/no-debug-non-zts-20100525/#INST@51524#: Permission denied
make: *** [install-modules] Error 1

I just manually copied the php module to the right place. i.e…

cp php-driver/ext/modules/cassandra.so /Applications/MAMP/bin/php/php5.6.2/modules/.

Then added the extension=cassandra.so to my php.ini

UPDATE:
The above compilation didn’t work. I got an error when php starts up (enable startup error displays in php.ini) that says module isn’t compiled right…

MacBook-Pro:code User$ php -v

Warning: PHP Startup: cassandra: Unable to initialize module
Module compiled with module API=20100525
PHP    compiled with module API=20131226
These options need to match
 in Unknown on line 0
PHP 5.6.2 (cli) (built: Oct 20 2014 16:21:27) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies

This is bcs we’re trying to use php that’s linked in MAMP (/Applications/MAMP/bin/php), but the module was compiled using the OSX php installation (/usr/bin/php).. and they’re different versions.
The fix is to download the correct php version source and make sure the module compilation uses the correct version’s source.
This link outlines compiling cassandra php extensions with correct source.
I also made sym-links for php, php-config, and phpize like this example.
This is some general background information on compiling php extensions on alternative configurations.
I also edit the ext/install.sh script with the following code…

echo "Compiling and installing the extension..."
phpdir=/Applications/MAMP/bin/php/php5.6.2
$phpdir/bin/phpize

`$phpsizecommand`

echo ./configure --with-php-config=$phpdir/bin/php-config --with-cassandra=$builddir --with-libdir=lib
LIBS="-lssl -lz -luv -lm -lstdc++" LDFLAGS="-L$builddir/lib" ./configure --with-cassandra=$builddir --with-libdir=lib --with-php-config=$phpdir/bin/php-config
make
make install

rm -Rf /tmp/php-driver-installation

Also don’t forget to do a clean between code changes

make clean

General Docs
DataStax PHP Driver

DataStax Driver PHP Docs

Native Linux
Follow DataStax linux installation steps (after installing dependencies). It works if you have conventional setup. You will need to install a lot of c++ development libraries for the compilation to work. Running a package manager install for a popular application build-tools should give you everything you need. I used…

sudo apt-get install build-essential
apt-get build-dep nginx
apt-get install php5-dev

Make sure to add cassandra to php.ini
; DataStax PHP Driver
extension=cassandra.so
OSX w/ MAMP:
For MAMP we need to hack the extension compilation scripts to point to the correct php directories. If you don’t you’ll get an an error when php starts up (enable startup error displays in php.ini) like this…

MacBook-Pro:code User$ php -v

Warning: PHP Startup: cassandra: Unable to initialize module
Module compiled with module API=20100525
PHP    compiled with module API=20131226
These options need to match
 in Unknown on line 0
PHP 5.6.2 (cli) (built: Oct 20 2014 16:21:27) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies

This is bcs we’re trying to use php that’s linked in MAMP (/Applications/MAMP/bin/php), but the module was compiled using the OSX php installation (/usr/bin/php).. and they’re different versions.

The fix is to download the correct php version source and make sure the module compilation uses the correct version’s source.
This link outlines compiling cassandra php extensions with correct source.

I also made sym-links for php, php-config, and phpize like this example.
This is some general background information on compiling php extensions on alternative configurations.

I also edit the ext/install.sh script with the following code…

echo "Compiling and installing the extension..."
phpdir=/Applications/MAMP/bin/php/php5.6.2 {{put in your correct php version directory}}
$phpdir/bin/phpize

`$phpsizecommand`

echo ./configure --with-php-config=$phpdir/bin/php-config --with-cassandra=$builddir --with-libdir=lib
LIBS="-lssl -lz -luv -lm -lstdc++" LDFLAGS="-L$builddir/lib" ./configure --with-cassandra=$builddir --with-libdir=lib --with-php-config=$phpdir/bin/php-config
make
make install

rm -Rf /tmp/php-driver-installation

Also don’t forget to do a clean between code changes

make clean

Cassandra DataStax PHP Extension Setup

General Docs
DataStax PHP Driver

DataStax Driver PHP Docs

Native Linux
Follow DataStax linux installation steps (after installing dependencies). It works if you have conventional setup. You will need to install a lot of c++ development libraries for the compilation to work. Running a package manager install for a popular application build-tools should give you everything you need. I used…

sudo apt-get install build-essential
apt-get build-dep nginx
apt-get install php5-dev

Make sure to add cassandra to php.ini
; DataStax PHP Driver
extension=cassandra.so

 

OSX w/ MAMP:
For MAMP we need to hack the extension compilation scripts to point to the correct php directories. If you don’t you’ll get an an error when php starts up (enable startup error displays in php.ini) like this…

MacBook-Pro:code User$ php -v

Warning: PHP Startup: cassandra: Unable to initialize module
Module compiled with module API=20100525
PHP    compiled with module API=20131226
These options need to match
 in Unknown on line 0
PHP 5.6.2 (cli) (built: Oct 20 2014 16:21:27) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies

This is bcs we’re trying to use php that’s linked in MAMP (/Applications/MAMP/bin/php), but the module was compiled using the OSX php installation (/usr/bin/php).. and they’re different versions.

The fix is to download the correct php version source and make sure the module compilation uses the correct version’s source.
This link outlines compiling cassandra php extensions with correct source.

I also made sym-links for php, php-config, and phpize like this example.
This is some general background information on compiling php extensions on alternative configurations.

I also edit the ext/install.sh script with the following code…

echo "Compiling and installing the extension..."
phpdir=/Applications/MAMP/bin/php/php5.6.2 {{put in your correct php version directory}}
$phpdir/bin/phpize

`$phpsizecommand`

echo ./configure --with-php-config=$phpdir/bin/php-config --with-cassandra=$builddir --with-libdir=lib
LIBS="-lssl -lz -luv -lm -lstdc++" LDFLAGS="-L$builddir/lib" ./configure --with-cassandra=$builddir --with-libdir=lib --with-php-config=$phpdir/bin/php-config
make
make install

rm -Rf /tmp/php-driver-installation

Also don’t forget to do a clean between code changes

make clean

Jetty’s Server in Spark Stack

Spark has a web accessible monitoring interface, as well as, several other mechanisms like remoting, and file-serving that use http protocols. Spark uses the Jetty web server, client and java servlet container for these functionalities.

The web UI is started from within the SparkContext class by instantiated a SparkUI class, which is sub-class of the WebUI class. WebUI uses Spark utility and Jetty utility functions to spin up the web server and attach handlers to server web content.

Java on Mac OS X

Current version of Java

$> java -version

What java executable is command line using

$> ls -al /usr/bin/java

What versions of java exist on system

$> /usr/libexec/java_home -v version.xx

… i.e. if you execute..

$> /usr/libexec/java_home -v 1.7

… it’ll output the runtime lib directory. If you you use a version number that’s not installed it’ll just tell you that it can’t find a directory. In which case you need to install it.
You can also list the java frameworks library directory, but I’ve found this to be inconsistent with new java versions I install…

$> ls /System/Library/Frameworks/JavaVM.framework/Versions/

Installing JDK
To update the command line java we need to download the jdk, not just the jre that the default “google java download” prompts you to. We then need to make sure our env vars (ie JAVA_HOME) are set in .bash_profile.
JDK 8 Installation for OS X (oracle docs)
OS X Platform Install FAQ
Java SE Development Kit 8 Downloads

Sometimes it’s necessary to have multiple jdk versions on your system depending on what you’re running/compiling. Search for “java archive” (it’s at the bottom) to list previous java versions on downloads page…
Java SE Downloads

If we want to switch between java versions we can use the JAVA_HOME env var..

$> export JAVA_HOME=`/usr/libexec/java_home -v version.xx`

Add New WordPress User using only database

INSERT INTO `wp_users` (`user_login`, `user_pass`, `user_nicename`, `user_email`, `user_status`)
VALUES ('newadmin', MD5('pass123'), 'firstname lastname', 'email@example.com', '0');

INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) 
VALUES (NULL, (Select max(id) FROM wp_users), 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');

INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) 
VALUES (NULL, (Select max(id) FROM wp_users), 'wp_user_level', '10');

How to Add an Admin account in WordPress via MySQL