Memcached memcache and lower mounting extension PHP7

Reprinted from: https://www.jianshu.com/p/c06051207f6e

Memcached is a high-performance distributed memory caching server, PHP memcache and memcached Memcached servers are PHP extensions. Memcache which predates than memcached, so some of the old code could still use memcache extension. Then came memcached, and most frameworks support memcached, now relatively popular. According to their own needs, you can install one. Here are two installation methods say it.

Installation depends

First, memcached, this extension requires libmemcached client library, otherwise you will receive an error

checking for libmemcached location... configure: error: memcached support requires libmemcached. Use --with-libmemcached-dir=<DIR> to specify the prefix where libmemcached headers and library are located
ERROR: `/var/tmp/memcached/configure --with-libmemcached-dir=no' failed

Can be installed by the following method

[root@lnmp lnmp.cn]# yum install libmemcached libmemcached-devel

And function module uses memcache zlib to support data compression, this module needs to be installed so Zlib module. Otherwise, the following error occurs:

checking for the location of zlib... configure: error: memcache support requires ZLIB. Use --with-zlib-dir=<DIR> to specify prefix where ZLIB include and library are located
ERROR: `/var/tmp/memcache/configure --enable-memcache-session=No' failed

A method can be used to install yum:

[root@lnmp lnmp.cn]# yum install zlib zlib-devel

Install memcached extension

Try to install a PECL, memcached on PECL's address is:
https://pecl.php.net/package/memcached

[root@lnmp lnmp.cn]# pecl install memcached
pecl/memcached requires PHP (version >= 5.2.0, version <= 6.0.0, excluded versions: 6.0.0), installed version is 7.0.8
No valid packages found
install failed
[root@localhost vagrant]#

Tips Obviously, memcached PECL extension on only supports PHP 5.2 or higher, version 6.00 or less. It has not been updated to PHP7. Fortunately, however, it is that they can find a link on github at the PECL memcached page of:
https://github.com/php-memcached-dev/php-memcached
this above code has to be supported by the branch PHP7. Here to download the source code to source php ext directory:

[root@lnmp lnmp.cn]# cd /usr/local/src/php-7.0.8/ext/
[root@lnmp ext]# git clone https://github.com/php-memcached-dev/php-memcached memcached
[root@lnmp ext]# cd memcached/

checkout to php7 branches:

[root@lnmp memcached]# git checkout php7
Branch php7 set up to track remote branch php7 from origin.
Switched to a new branch 'php7'
[root@lnmp memcached]#

Phpize installed with my PHP is installed in / usr / local / php7 down

[root@lnmp memcached]# /usr/local/php7/bin/phpize
[root@lnmp memcached]# ./configure --with-php-config=/usr/local/php7/bin/php-config

Then make and make install

[root@lnmp memcached]# make

[root@lnmp memcached]# make install
Installing shared extensions: /usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/
[root@lnmp memcached]#

We can see memcached installation has been completed, and prompts the directory file extension has been put:

[root@lnmp memcached]# ls /usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/
memcached.so opcache.a opcache.so
[root@lnmp memcached]#

The final step in the introduction of memcached.so in php.ini

[root@lnmp memcached]# vim /usr/local/php7/lib/php.ini

Joined:

extension=memcached.so

Remember reload at php-fpm to take effect

[root@lnmp memcached]# systemctl reload php-fpm

Open phpinfo page has been seen memcached extension successfully installed.

 
php7 memcached

 

Install memcache extension

Also try to use PECL to install:

[root@lnmp memcached]# pecl install memcache

But again failed

/tmp/pear/temp/memcache/memcache.c:40:40: fatal error: ext/standard/php_smart_str.h: No such file or directory

include "ext/standard/php_smart_str.h"

                                                                            ^

compilation terminated.
make: *** [memcache.lo] Error 1
ERROR: `make' failed

The reason is seemingly not support install memcache PECL extension under PHP7,
https://pecl.php.net/package/memcache

Since 2013 it is updated. That being the case can only think of other ways, the same is to take a chance on github. Search memcache PECL
https://github.com/search?utf8=%E2%9C%93&q=pecl+memcache&type=Repositories&ref=searchresults

The first of which ( https://github.com/websupport-sk/pecl-memcache ) is wanted, and the code has been support to PHP7, immediately download the code to compile:

[root@lnmp memcached]# cd ../
[root@lnmp ext]# git clone https://github.com/websupport-sk/pecl-memcache memcache
[root@lnmp ext]# cd memcache

Installation with phpize, exactly the same steps and memcached

[root@lnmp memcache]# /usr/local/php7/bin/phpize
[root@lnmp memcache]# ./configure --with-php-config=/usr/local/php7/bin/php-config
[root@lnmp memcache]# make
[root@lnmp memcache]# make install
Installing shared extensions: /usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/
[root@lnmp memcache]#

Similarly memcached, will be introduced in php.ini memcache.so

[root@lnmp memcache]# vim /usr/local/php7/lib/php.ini

Joined:

extension=memcache.so

Finally reload php-fpm

[root@lnmp memcache]# systemctl reload php-fpm

You're done, you can see the phpinfo page memcahce have been successfully installed and memchaced

 
php7 memcache

安装 Memcached 内存缓存服务器

Centos 下可以用 yum 进行安装

[root@lnmp memcache]# yum install memcached

再启动 Memcached 就可以测试 PHP 扩展了

[root@lnmp memcache]# systemctl start memcached

默认端口是 11211
转自: 我不是鱼
-- 感谢大佬
原文连接: http://www.lnmp.cn/install-memcache-and-memcached-extends-under-php7.html

Guess you like

Origin www.cnblogs.com/maidongdong/p/11527926.html
Recommended