目录

下载

jm:~/package$ wget https://pecl.php.net/get/yar-2.2.0.tgz

解压

jm:~/package$ tar xvf yar-2.2.0.tgz 
jm:~/package$ cd yar-2.2.0/

phpize准备PHP扩展库的编译环境

jm:~/package/yar-2.2.0$ whereis phpize
phpize: /usr/bin/phpize /usr/bin/phpize7.1 /usr/share/man/man1/phpize.1.gz

jm:~/package/yar-2.2.0$ /usr/bin/phpize
Configuring for:
PHP Api Version:         20160303
Zend Module Api No:      20160303
Zend Extension Api No:   320160303

php-config配置

jm:~/package/yar-2.2.0$ whereis php-config
php-config: /usr/bin/php-config /usr/bin/php-config7.1 /usr/share/man/man1/php-config.1.gz

jm:~/package/yar-2.2.0$ ./configure --with-php-config=/usr/bin/php-config
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
...
...
configure: creating ./config.status
config.status: creating config.h
config.status: executing libtool commands

编译安装扩展

jm:~/package/yar-2.2.0$ make
...
...

jm:~/package/yar-2.2.0$ sudo make install
...
...
Installing shared extensions:     /usr/lib/php/20160303/

调整php.ini

成功的安装将创建 extname.so 并放置于 PHP 的扩展库目录中。需要调整 php.ini,加入 extension=extname.so 这一行之后才能使用此扩展库。

$ sudo vim /etc/php/7.1/fpm/php.ini

;amqp rabbitMQ扩展
extension=/usr/lib/php/20160303/amqp.so
;seaslog 扩展
extension=seaslog.so
;yar rpc
extension=yar.so

确认

注意fpm与cli模式的php.ini的配置可能在不同文件,如果是不同ini文件,需要两个ini文件都要配置。

fpm通过php_info()查看:

yar
yar support	enabled
Version	2.2.0

cli模式通过命令查看:

php -m |grep yar