转载自:https://www.jianshu.com/p/c06051207f6e

Memcached 是高性能的分布式内存缓存服务器,而PHP memcache 和 memcached 都是 Memcached 服务器的 PHP 扩展。其中memcache 比 memcached 早出现,所以一些老的代码可能还在用 memcache 扩展。memcached 后来出现,并且大部分框架都支持 memcached,现在相对较流行。可以根据自己需要,安装一个就可以。这里两个的安装方法都说一下。

安装依赖

首先是 memcached,这个扩展需要 libmemcached 客户端库,否则会出现如下错误

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

可以通过如下方法安装

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

而 memcache 模块使用了函数 zlib 来支持数据压缩,因此安装此模块需要安装 Zlib 模块。否则会出现如下错误:

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

可以如下方法用 yum 来安装:

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

安装 memcached 扩展

尝试用 PECL 安装,memcached 在 PECL 上的地址是:
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]#

提示很明显,PECL 上的 memcached 扩展只支持 PHP 5.2 以上,6.00 以下的版本。还未更新到 PHP7。不过还好的是在 PECL 的 memcached 页面可以找到他们在 github 上的链接:
https://github.com/php-memcached-dev/php-memcached
这上面的代码已经有可以支持到 PHP7 的分支。这里将源码统一下载到 php 源码的 ext 目录:

[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 到 php7 分支:

[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 安装,我的 PHP 是安装在 /usr/local/php7 下

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

接着 make 和 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]#

可以看到 memcached 已经安装完成,并且扩展文件已经放到提示的目录:

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

最后一步在 php.ini 中引入 memcached.so

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

加入:

extension=memcached.so

记得 reload 一下 php-fpm 才能生效

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

打开 phpinfo 页面,已经已经看到 memcached 扩展成功安装了。

 
php7 memcached

安装 memcache 扩展

同样尝试用 PECL 来安装:

[root@lnmp memcached]# pecl install memcache

但同样失败

/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

貌似原因也是 PECL 还不支持在 PHP7 下安装 memcache 扩展,
https://pecl.php.net/package/memcache

2013年以来为更新过。此路不通只能另想办法,同样是到 github 上碰碰运气。搜索 pecl memcache
https://github.com/search?utf8=%E2%9C%93&q=pecl+memcache&type=Repositories&ref=searchresults

其中第一个(https://github.com/websupport-sk/pecl-memcache)就是想要的,并且代码已经支持到 PHP7,立即下载代码编译:

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

用 phpize 安装,步骤和 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]#

类似 memcached , 将 memcache.so 在 php.ini 中引入

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

加入:

extension=memcache.so

最后 reload php-fpm

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

大功告成,可以在 phpinfo 页面看到 memcahce 和 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

PHP7 下安装 memcache 和 memcached 扩展的更多相关文章

  1. php7安装memcache 和 memcached 扩展

    php7安装memcache 和 memcached 扩展 标签(空格分隔): php memcache和memcached区别 memcache:http://pecl.php.net/packag ...

  2. Linux下安装php的memcached扩展(memcache的客户端)

    php的扩展memcache,不支持cas,所以我们要装memcached扩展,memcached扩展是基于libmemcached,所以要先安装libmemcached 一.下载软件 1.libme ...

  3. ubuntu下安装memcache及memcached

    memcache 和 memcached 有什么区别呢? memcache最早是在2004年2月开发的,而memcached最早是在2009年1月开发的.所以memcache的历史比memcached ...

  4. ubuntu 下安装memcache 以及php扩展

    1,下载软件   下载   memcached   http://memcached.org/downloads   下载libevent http://libevent.org/     2,安装  ...

  5. windows下AppServ安装php的memcached扩展

    memcache和memcached的区别  在自己的新程序中打算全面应用memcached技术,这个很容易理解这是memcached是内存缓存,但是怎么还有memcache呢?  其实很简单,mem ...

  6. Linux下的Memcache安装及安装Memcache的PHP扩展安装

    Linux下Memcache服务器端的安装服务器端主要是安装memcache服务器端,目前的最新版本是 memcached-1.3.0 .下载:http://www.danga.com/memcach ...

  7. Linux下的Memcache安装 和 安装Memcache的PHP扩展

    一.首先安装服务端memcached 1.下载libevent与memcache软件包. 下载memcached: wget http://memcached.org/latestwget http: ...

  8. windows下安装redis和memcached

    redis安装: http://www.68idc.cn/help/server/20141128135092.html phpredis下载地址:https://github.com/phpredi ...

  9. Linux下安装memcache

    1.Memcache用到了libevent(这个库用于Socket的处理),需要安装libevent: (1)tar zxvf libevent.tar.gz 后进入解压后的文件夹 (2)./conf ...

随机推荐

  1. 12 saltstack部署OpenStack

    参考源码:https://github.com/unixhot/salt-openstack nova control.sls

  2. Monkey实战测试步骤

    1,adb devices 确保设备在线 2,adb shell pm list packages 查看包名 3,adb shell monkey -p com.xzck.wangcai   --ig ...

  3. triggerHandler(type, [data])

    triggerHandler(type, [data]) 概述 这个特别的方法将会触发指定的事件类型上所有绑定的处理函数.但不会执行浏览器默认动作,也不会产生事件冒泡. 大理石平台价格 这个方法的行为 ...

  4. PHP mysqli_ping() 函数

    定义和用法 mysqli_ping() 函数进行一个服务器连接,如果连接已断开则尝试重新连接. <?php // 假定数据库用户名:root,密码:123456,数据库:RUNOOB $con= ...

  5. java超大文件上传

    上周遇到这样一个问题,客户上传高清视频(1G以上)的时候上传失败. 一开始以为是session过期或者文件大小受系统限制,导致的错误. 查看了系统的配置文件没有看到文件大小限制, web.xml中se ...

  6. Spring Boot中@OneToMany与@ManyToOne几个需要注意的问题

    @OneToMany如果不加@JoinColumn,系统会自动在主从表中增加一个中间表. 主表: @Entity(name = "Post") public class Post  ...

  7. HTTP第八、九章之网关、隧道、web机器人

    网关 网关(gateway): 资源和应用程序之间的粘合剂.应用程序可以(通过HTTP或其它已定义的接口)请求网关来处理某条请求,网关可以提供一条响应.网关可以向数据库发送查询语句,或者生成动态的内容 ...

  8. Yet Another Division Into Teams

    E. Yet Another Division Into Teams 首先要想明白一个东西,就是当一个小组达到六个人的时候,它一定可以拆分成两个更优的小组. 这个题可以用动态规划来写,用一个数组来保存 ...

  9. CodeForces 754C Vladik and chat ——(xjbg)

    虽然是xjbg的题目,但是并不很好做. 题意不难理解.读入有点麻烦.做法是先正着推每段对话的?可能是谁说的,然后反过来选择即可.正推时,其中vis数组表示谁已经被用过了,cnt表示该组当前可以选择几个 ...

  10. TCP报头格式

    1.端口号:用来标识同一台计算机的不同的应用进程.     1)源端口:源端口和IP地址的作用是标识报文的返回地址.     2)目的端口:端口指明接收方计算机上的应用程序接口. TCP报头中的源端口 ...