lnmp centos7 memcache服务器端 和 memcache memcached扩展的安装

在项目开发的时候有用到memcache,自己在本地需要搭建一个memcache环境,用于开发和测试;

 

wget http://www.memcached.org/files/memcached-1.5.10.tar.gz

tar zxvf memcached-1.5.10.tar.gz

./configure --prefix=/usr/local/libevent

make && make install

./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent

 https://blog.csdn.net/happyrabbit456/article/details/44680597

https://blog.csdn.net/21aspnet/article/details/6827316

http://pecl.php.net/package/memcache

https://launchpad.net/libmemcached/+download

https://blog.csdn.net/u011547570/article/details/78325556

 1.memcache服务器端的安装

学习源头:https://blog.csdn.net/21aspnet/article/details/6827316

服务器端主要是安装memcache服务器端,目前的最新版本是 memcached-1.5.10

官网地址:http://memcached.org/

这是官方给的安装方法:可以参考一下

Debian/Ubuntu: apt-get install libevent-dev Redhat/Centos: yum install libevent-devel

wget http://memcached.org/latest
tar -zxvf memcached-1.x.x.tar.gz
cd memcached-1.x.x
./configure && make && make test && sudo make install

但是在安装memcache的时候,需要先安装libevent

1.先安装libevent

官网地址:http://libevent.org/

先去下载压缩包:

wget https://github.com/libevent/libevent/releases/download/release-2.1.8-stable/libevent-2.1.8-stable.tar.gz

tar zxvf libevent-2.1.8-stable.tar.gz

cd libevent-2.1.8-stable

./configure --prefix=/usr/local/libevent

make && make install

2.安装memcache

官网地址:http://memcached.org/

先去下载压缩包:

wget http://www.memcached.org/files/memcached-1.5.10.tar.gz

tar -zxvf memcached-1.5.10.tar.gz

cd memcached-1.5.10

./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent

make && make install

如果中间出现报错,请仔细检查错误信息,按照错误信息来配置或者增加相应的库或者路径。
安装完成后会把memcached放到 /usr/local/bin/memcached ,

测试是否成功安装memcached:
ps -ef |grep memcached

或者pgrep memcached

2.php memcache扩展的安装

学习源头:https://blog.csdn.net/u011547570/article/details/78325556

pecl官方网站:http://pecl.php.net/package/memcache

由于好像memcache很久没有更新了,不支持php7(没有实测)

在安装memcache的时候,就直接去github上找的代码

https://github.com/php-memcached-dev/php-memcached

php7分支的(我们要的) https://github.com/php-memcached-dev/php-memcached/tree/php7

下载下来以后 进入目录

/usr/local/php-fpm/bin/phpize

./configure –with-php-config=/usr/local/php-fpm/bin/php-config

make && make install

 

可以看到 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 扩展成功安装了。

 

3.安装memcached

1.在安装memcached扩展的时候,需依赖于libmemcached

官方网站:https://launchpad.net/libmemcached/+download

这个是新版的客户端基于libmemcached,所以必须要安装libmemcached
先安装libmemcached

wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz

tar zxvf libmemcached-1.0.18.tar.gz

cd libmemcached-1.0.18

./configure --prefix=/usr/local/libmemcached/ --with-libmemcached-dir=/usr/local/libmemcached/

make && make install

2.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 目录:

wget https://github.com/php-memcached-dev/php-memcached.git

进入主目录

/usr/local/php-fpm/bin/phpize

 

./configure --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached/

make && make install

修改php.ini添加extension = "memcached.so"就可以

4.检测是否安装成功呢?

要重启php

 

关闭php-fpm

 

ps -ef|gerp php-fpm

 

killall php-fpm

 

/usr/local/php-fpm/sbin/php-fpm

 

然后再试一下 应该就可以了

 

php -m 查看

是否有安装扩展

 

posted @ 2018-08-13 11:34  段佳伟  阅读(285)  评论(0编辑  收藏  举报