PHP驱动程序DataStax Cassandra DB - 如何使用? [英] PHP-Driver DataStax Cassandra DB - How to use?
问题描述
我已按照以下步骤完成安装过程:
系统
PHP 7.0.5-1〜dotdeb + 8.1(cli)(NTS)
Debian 8
Nginx 1.8.1
Laravel 5.2
Java安装
mkdir -p / usr / lib / jvm
wget URL到Oraclesite
mv mv jdk-8u77-linux-x64。 tar.gz\?... jdk-8u77-linux-x64.tar.gz
tar xzf jdk-8u77-linux-x64.tar.gz
rm jdk-8u77-linux-x64。 tar.gz
update-alternatives --install/ usr / bin / javajava/usr/lib/jvm/jdk1.8.0_version/bin/java1
update-alternatives - -set java /usr/lib/jvm/jdk1.8.0_version/bin/java
安装所需的软件包
apt install cmake automake libtool git php7.0-dev libgmp-dev libssl-dev
Libuv安装
cd / tmp
wget http://dist.libuv.org/dist/v1.7.5/libuv-v1.7.5.tar.gz
tar xzf libuv-v1.7.5.tar.gz
rm libuv -v1.9.0.tar.gz
cd libuv-v1.7.5
sh autogen.sh
./configure
make
make install
ldconfig
安装Cassandra Datatrax
echodeb http://debian.datastax.com/community stable main| sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
curl -L http://debian.datastax.com/debian/repo_key | sudo apt-key add -
apt install cassandra dsc30
检查服务
服务cassandra状态
cassandra.service - LSB:用于结构化
数据的分布式存储系统加载:loaded(/etc/init.d/cassandra)活动:active
-04-11 01:11:04 CEST; 19分钟前进程:506
ExecStart = / etc / init.d / cassandra start(code = exited,status = 0 / SUCCESS)
CGroup:/system.slice/cassandra.service
nodetool status
数据中心:datacenter1
=======================状态=上/下| / State = Normal / Leaving / Joining / Moving
- 地址加载令牌所有者(有效)主机ID机架UN 127.0.0.1 139.06 KB 256 100.0%
1ab0e99a-41a5-4007-b9ca -de58dc88e318 rack1
cqlsh
已连接到测试集群127.0.0.1:9042。 [cqlsh 5.0.1 | Cassandra
3.0.4 | CQL spec 3.4.0 |原生协议v4]
使用HELP进行帮助。
安装php驱动程序
我认为这是因为只有php7设置)
git clone https://github.com/datastax/php-driver .git
cd php-driver
git submodule update --init
cd ext
./install.sh
make test - >所有测试通过
向PHP扩展添加驱动程序
echo -e; DataStax PHP Driver\\\
extension = cassandra.so>> /etc/php/7.0/cli/php.ini
// UPDATE - 为fpm / php.ini文件添加的扩展名。
echo -e; DataStax PHP Driver\\\
extension = cassandra.so>> /etc/php/7.0/fpm/php.ini
重新启动nginx和php7.0-fpm
service nginx restart
pre>
service php7.0-fpm restart
问题:
如果我想使用下面的代码, Cassandra类找不到。
页面: https://github.com / datastax / php-driver#datastax-php-driver-for-apache-cassandra$ cluster = Cassandra :: cluster() - > build();
感谢您的帮助。
解决方案由于您尝试使用nginx + fpm执行您的PHP脚本,您需要更新适当的php.ini文件(例如
/ etc / php7 / fpm / php。
<$ p $ p>echo -e; DataStax PHP Driver\\\
extension = cassandra.so>> /etc/php/7.0/fpm/php.7.0/fpm/php.ini
要确保驱动程序正确加载通过CLI可以执行以下操作:
php -m | grep cassandra
或
php -i | grep -A 10^ cassandra $
php -m
将打印PHP能够加载的所有扩展/模块,而 php -i
将显示有关您的PHP安装配置的更详细的信息。
I've done the installation process as following:
System
PHP 7.0.5-1~dotdeb+8.1 (cli) ( NTS )
Debian 8
Nginx 1.8.1
Laravel 5.2
Java Installation
mkdir -p /usr/lib/jvm
wget URL to Oraclesite
mv mv jdk-8u77-linux-x64.tar.gz\?... jdk-8u77-linux-x64.tar.gz
tar xzf jdk-8u77-linux-x64.tar.gz
rm jdk-8u77-linux-x64.tar.gz
update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0_version/bin/java" 1
update-alternatives --set java /usr/lib/jvm/jdk1.8.0_version/bin/java
Install needed packages
apt install cmake automake libtool git php7.0-dev libgmp-dev libssl-dev
Libuv Installation
cd /tmp
wget http://dist.libuv.org/dist/v1.7.5/libuv-v1.7.5.tar.gz
tar xzf libuv-v1.7.5.tar.gz
rm libuv-v1.9.0.tar.gz
cd libuv-v1.7.5
sh autogen.sh
./configure
make
make install
ldconfig
Installation Cassandra Datatrax
echo "deb http://debian.datastax.com/community stable main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
curl -L http://debian.datastax.com/debian/repo_key | sudo apt-key add -
apt install cassandra dsc30
Check services
service cassandra status
cassandra.service - LSB: distributed storage system for structured data Loaded: loaded (/etc/init.d/cassandra) Active: active (running) since Mon 2016-04-11 01:11:04 CEST; 19min ago Process: 506 ExecStart=/etc/init.d/cassandra start (code=exited, status=0/SUCCESS) CGroup: /system.slice/cassandra.service
nodetool status
Datacenter: datacenter1 ======================= Status=Up/Down |/ State=Normal/Leaving/Joining/Moving -- Address Load Tokens Owns (effective) Host ID Rack UN 127.0.0.1 139.06 KB 256 100.0%
1ab0e99a-41a5-4007-b9ca-de58dc88e318 rack1
cqlsh
Connected to Test Cluster at 127.0.0.1:9042. [cqlsh 5.0.1 | Cassandra 3.0.4 | CQL spec 3.4.0 | Native protocol v4] Use HELP for help.
Installation php-driver (PECL Installation isn't working. I think it's because of only php7 setup)
git clone https://github.com/datastax/php-driver.git
cd php-driver
git submodule update --init
cd ext
./install.sh
make test -> all tests passed
Add Driver to PHP Extensions
echo -e "; DataStax PHP Driver\nextension=cassandra.so" >> /etc/php/7.0/cli/php.ini
// UPDATE - added extension to fpm/php.ini file.
echo -e "; DataStax PHP Driver\nextension=cassandra.so" >> /etc/php/7.0/fpm/php.ini
Restart nginx and php7.0-fpm
service nginx restart
service php7.0-fpm restart
Question:
If I wanna use the following code it says me class Cassandra not found. Webpage: https://github.com/datastax/php-driver#datastax-php-driver-for-apache-cassandra
$cluster = Cassandra::cluster()->build();
Thank you for helping.
Since you are trying to execute your PHP script using nginx+fpm you will need to update the appropriate php.ini file (e.g. /etc/php7/fpm/php.ini
).
Add the driver module to your nginx+fpm installation
echo -e "; DataStax PHP Driver\nextension=cassandra.so" >> /etc/php/7.0/fpm/php.ini
To ensure the the driver is being properly loaded via CLI you can execute the following:
php -m | grep cassandra
or
php -i | grep -A 10 "^cassandra$"
php -m
will print out all the extension/modules that PHP was able to load whereas php -i
will display more verbose information about your PHP installation configuration.
这篇关于PHP驱动程序DataStax Cassandra DB - 如何使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!