MacOS 上的 Cassandra php 驱动程序 - Class 'Cassandra\SimpleStatement' 未找到

Cassandra php driver on MacOS - Class 'Cassandra\SimpleStatement' not found

大家好。

通常我只是在 *nix OS

中使用这个 Official Docs

但现在我使用的是 MacO,此说明无法正常工作。

pecl install cassandra 的情况下,我收到了这条消息:

checking for supported DataStax C/C++ driver version... awk: can't open file /include/cassandra.h
 source line number 1
configure: error: not supported. Driver version 2.4.2+ required (found )
ERROR: `/private/tmp/pear/install/cassandra/configure --with-php-config=/usr/bin/php-config' failed

我的逻辑告诉我,在这种情况下,我需要自己制作 DataStax C/C++ 驱动程序。在文件夹 php-driver\lib 中,我删除 cpp-driver 并使用 this instruction 制作新的 C/C++ 驱动程序,没有错误。

所以在官方文档中说:

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 phpize, ./configure and make install.

但是当我尝试从 php-drive/ext 运行 ./configure 时,我得到了几乎相同的错误:

checking for supported DataStax C/C++ driver version... awk: can't open file /include/cassandra.h
 source line number 1
configure: error: not supported. Driver version 2.4.2+ required (found )

即使我继续并在那个错误之后 运行 make install 它给了我那个日志:

/bin/sh /Users/antvirgeo/php-driver/ext/libtool --mode=install cp ./cassandra.la /Users/antvirgeo/php-driver/ext/modules
cp ./.libs/cassandra.so /Users/antvirgeo/php-driver/ext/modules/cassandra.so
cp ./.libs/cassandra.lai /Users/antvirgeo/php-driver/ext/modules/cassandra.la
----------------------------------------------------------------------
Libraries have been installed in:
   /Users/antvirgeo/php-driver/ext/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `DYLD_LIBRARY_PATH' environment variable
     during execution

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
Installing shared extensions:     /usr/lib/php/extensions/no-debug-non-zts-20121212/
cp: /usr/lib/php/extensions/no-debug-non-zts-20121212/#INST@24727#: Operation not permitted
make: *** [install-modules] Error 1

Libraries have been installed in:
/Users/antvirgeo/php-driver/ext/modules

即使我将带有该路径的 cassandra 扩展添加到 php.ini,我的项目中仍然出现错误 Class 'Cassandra\SimpleStatement' not found

php -d="extension=modules/cassandra.so" -m 显示 PHP 模块列表中的 cassandra

我做错了什么?

PS:我在 Parallels 中有 ubuntu OS 与此项目一起使用 DataStax php 驱动程序安装,此说明工作正常。

____upd: 在没有 ANY ERRORS 的 @Fero 的所有指令之后,命令 /usr/local/bin/php -i | grep -A 10 "^cassandra$" 向我展示了这个:

cassandra

Cassandra support => enabled
C/C++ driver version => 2.4.2
Persistent Clusters => 0
Persistent Sessions => 0

Directive => Local Value => Master Value
cassandra.log => cassandra.log => cassandra.log
cassandra.log_level => ERROR => ERROR

仍然是同样的错误 - Class 'Cassandra\SimpleStatement' not found

______________UPDATED 最后:

啊啊啊,它正在工作!我在我的项目中写了输出 phpinfo(); 并意识到 apache 使用其他 php 版本和 php.ini,根本没有 extension=cassandra.so

您需要安装 DataStax C/C++ 驱动程序,它是 PHP 驱动程序的依赖项。使用 these instructions followed by make install after the driver has been successfully built will ensure this dependency is available when building the PHP driver. Using the PHP driver build instructions 您需要确保 GMP 和 PHP 开发库在 运行 pecl install cassandra.

之前也可用

编辑:

由于您使用的是 El Capitan,因此您 运行 遇到了 System Integrity Protection and you will need to disable it in order to copy files into /usr. The better and recommended option is to install PHP using Homebrew; however you can also use MacPorts 的问题(如果愿意的话)。

以下是用于在已安装 Xcode 和 Homebrew 的干净 OSX El Capitan 映像上重现 PHP 驱动程序安装的步骤:

brew install autoconf cmake libuv gmp openssl pcre homebrew/php/php55
brew link homebrew/php/php55
mkdir code
pushd code
git clone https://github.com/datastax/php-driver.git
pushd php-driver
git submodule update --init --recursive
pushd lib/cpp-driver
mkdir build
pushd build
cmake -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl ..
make -j$(sysctl -n hw.ncpu)
sudo make install
popd
popd
mkdir build
pushd ext
/usr/local/bin/phpize
popd
pushd build
../ext/configure --with-php-config=/usr/local/bin/php-config
make -j$(sysctl -n hw.ncpu)
sudo make install
popd
popd
sudo sh -c 'echo "extension=cassandra.so" >> /usr/local/etc/php/5.5/php.ini'

然后您可以使用以下命令验证安装:

/usr/local/bin/php -i | grep -A 10 "^cassandra$"

注意:PHP上面使用了 v5.5,因为这是 El Capitan 附带的默认版本; PHP v5.6 和 v7.0 也可以代替。

如果您需要在 MacOS 上安装 Cassandra PHP 扩展,只需通过 PECL 安装即可,无需打开或关闭系统完整性保护。我写了一篇博客 post,其中包含简单的分步说明。它还包括 link 从 Homebrew 安装 PHP 因为他们在今年 4 月删除了 Homebrew/php tap。

它还会传递 DataStax 网站上给出的错误说明。简而言之...

安装依赖项(我 运行 这些命令一次一个,以便轻松查看任何消息):

$ brew install autoconf
$ brew install cmake
$ brew install automake
$ brew install libtool
$ brew install gmp
$ brew install libuv
$ brew install openssl

检索并构建 C++ 驱动程序,然后在 cpp-driver 文件夹中创建一个构建目录:

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

通过对 OpenSSL 的合格调用制作和构建驱动程序:

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

现在您可以使用 PECL 安装 Cassandra PHP 扩展库了:

$ pecl install cassandra

检查以确保 Cassandra 扩展程序已添加到您的 PHP.ini 文件中。如果不加。

[cassandra]
extension="cassandra.so"

重新启动 Apache,您将关闭 运行 Cassandra PHP。

如果您想了解上述说明中发生的事情的更多详细信息,请在此处参阅我的博客 post:

https://medium.com/@crmcmullen/how-to-install-the-cassandra-php-driver-on-macos-10-13-high-sierra-and-10-14-mojave-c18263831ccb