Home >Backend Development >PHP Problem >How to install php zookeeper extension

How to install php zookeeper extension

青灯夜游
青灯夜游Original
2021-09-27 20:04:492247browse

Installation method: 1. Install and start the zookeeper server; 2. Download the zookeeper extension and extract it to the ext directory of the PHP installation directory; 3. In the PHP installation directory, execute the command to generate configure and makefile; 4 , Use the make command to compile and install.

How to install php zookeeper extension

The operating environment of this tutorial: centos6.4 system, PHP5.5.10 version, DELL G3 computer

ZooKeeper is a distributed, open The source code distributed application coordination service is an open source implementation of Google's Chubby and an important component of Hadoop and Hbase. It is a software that provides consistent services for distributed applications. The functions provided include: configuration maintenance, domain name services, distributed synchronization, group services, etc.

The goal of ZooKeeper is to encapsulate complex and error-prone key services and provide users with simple and easy-to-use interfaces and a system with efficient performance and stable functions.

To use zookeeper in php, you must first install the php zookeeper extension. To install the php zookeeper extension, you must first install zookeeper

How to install the php zookeeper extension

Environment:

centos : 6.4

zookeeper : 3.4.5

php : 5.5.10

nginx : 1.5

php zookeeper extension: 0.2.2

If nginx is not installed, install nginx first; make sure to configure nginx first before proceeding

If php is not installed, install php first (first configure nginx’s php support, and then install the zookeeper extension)

Install zookeeper

Download

wget http://mirrors.hust.edu.cn/apache/zookeeper/zookeeper-3.4.5/zookeeper-3.4.5.tar.gz

Unzip (whichever directory you put it in, just remember it)

tar zxfv zookeeper-3.4.5.tar.gz

Start the zookeeper server

cd zookeeper-3.4.5/conf
cp zoo_sample.cfg zoo.cfg
cd ../bin
./zkServer.sh start

The most important thing here To confirm whether you expect success, ./zkServer.sh status

I have a single server here, so the result is:

[root@localhost bin]# ./zkServer.sh status
JMX enabled by default
Using config: /root/zookeeper-3.4.5/bin/../conf/zoo.cfg
Mode: standalone

Compile the zookeeper library for PHP

cd ../src/c
./configure --prefix=/usr/local/zookeeperlib
make && make install

Install the zookeeper extension for php

##Download

wget http://pecl.php.net/get/zookeeper-0.2.2.tgz

Unzip(Don’t worry about the unzipped package.xml)

tar zxvf zookeeper-0.2.2.tgz

Put it in /root/php-5.5.10/ext

mv zookeeper-0.2.2 /root/php-5.5.10/ext/
cd /root/php-5.5.10/ext/

Change directory Name

mv zookeeper-0.2.2 zookeeper

Go back to the php-5.5.10 directory

cd ..
./buildconf --force
./configure -h|grep zookeeper

Check whether configure already supports zookeeper

--enable-zookeeper               Enable zookeeper support
--disable-zookeeper-session      Disable zookeeper session handler support
--with-libzookeeper-dir=DIR   Set the path to libzookeeper install prefix.

If it is displayed as above, The description is already supported, continue below

cd ext/zookeeper

Generate configure

/usr/local/php5.5.10/bin/phpize

Generate makefile

./configure --with-php-config=/usr/local/php5.5.10/bin/php-config  --with-libzookeeper-dir=/usr/local/zookeeperlib
注意上面的路径:
--with-php-config是php安装的路径
--with-libzookeeper-dir是第一步中install zookeeper库的路径

Compile and install

make && make install

The result is, the next configuration of this result will be used

Installing shared extensions:     /usr/local/php5.5.10/lib/php/extensions/no-debug-non-zts-20121212/

Add the ext path and file name

vim /usr/local/php5.5.10/etc/php.ini
 
extension_dir="/usr/local/php5.5.10/lib/php/extensions/no-debug-non-zts-20121212/"
extension=zookeeper.so

Recompile php

Enter the source code folder of Php, don’t enter it by mistake. My source code folder is /root/php-5.5.10, and the installation directory is /usr/local/php5.5.10

cd /root/php-5.5.10
rm -rf autom4te.cache/ configure
./buildconf --force
./configure -h|grep zookeeper

Check if configure already supports zookeeper

If it already supports it , continue down

./configure --prefix=/usr/local/php5.5.10 --with-config-file-path=/usr/local/php5.5.10/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-zookeeper --with-libzookeeper-dir=/usr/local/zookeeperlib --enable-sockets
 make && make install

Here, the support has been installed, let’s test whether it is normal

In zookeeper-0.2.2.tgz (that is, the zookeeper extension of Php), there is examples/Zookeeper_Example.php file can be used to test

cp /root/php-5.5.10/ext/zookeeper/examples/Zookeeper_Example.php /usr/local/nginx/html/
/usr/local/php5.5.10/bin/php /usr/local/nginx/html/Zookeeper_Example.php

to see if the following results can be printed

string(0) ""
array(1) {
  [0]=>
  string(9) "zookeeper"
}
NULL
string(3) "abc"
array(2) {
  [0]=>
  string(7) "test123"
  [1]=>
  string(9) "zookeeper"
}
NULL
NULL
array(2) {
  [0]=>
  string(3) "001"
  [1]=>
  string(3) "002"
}

Restart php-fpm


killall php-fpm
/usr/local/php5.5.10/sbin/php-fpm

You can now pass The browser accesses PHP that supports zookeeper extension

If there are other problems, please check:

1, iptables

2, selinux

recommended Study: "

PHP Video Tutorial"

The above is the detailed content of How to install php zookeeper extension. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn