Debian|Centos安装memcached和php5-memcache模块

AndyYang| 阅读:1739 发表时间:2015-10-10 17:13:45 linux缓存
摘要:12年在长沙工作的时候,一直和同事叫debian大便,还吃饭的时候说的,都有点不好意思。一下过去几年,真快!今天发现公司的系统也是debian,而且没有memcache模块,于是安装了下,非编译安装。

一、Debian系列

1、安装memcached服务及php扩展
apt-get install memcached php5-memcached php5-memcache

2、查看是否安装好memcached服务
ps aux | grep memcached
可以发现安装完memcached是自动启动了的。也可以如下命令查看:
netstat -tap | grep 'memcached'

3、如需修改配置文件
请前往:/etc/memcached.conf
修改完重启
pkill memcached
/usr/bin/memcached restart -p 11211 -u nobody -l 127.0.0.1
最好在网上找个shell脚本,可以直接memcache start

4、最后web server重启下,apache或者nginx的fast-cgi
/etc/init.d/apache2 restart

最后来个简单的例子吧:

$mem = new Memcache;
$mem->connect("localhost", 11211);
$mem->set('test','hello world',0,60);
echo $mem->get('test');

如果能看到hello word,就真的ok了。

二、centos就简单说下

yum install memcached
#默认安装完没启动,需要 /etc/init.d/memcached start 启动(注意路径)
yum install php-pecl-memcache
#有可能这个php的memcache扩展没用,至少我的是。
#然后在php的bin目录,这样安装的扩展可行
pecl install memcache 

开机启动:chkconfig memcached on
默认是2345,也可以chkconfig --level 2345 memcached on
查看chkconfig --list

本文为AndyYang原创,转载请注明出处!
如果您觉得好,可以打赏作者:
如果您觉得累了,是否想看点美女养养眼:猛戳>>朋友帮
如果您觉得皮了,是否想来点神吐槽:猛戳>>iPhone查询中

已有1条评论

昵称:
邮箱:

  • 最新评论

青霉素2015-10-16 20:57:11
鉴定可用,楼主英明!
iPhone查询中 - bbs.ipcxz.com 朋友帮 - www.pengyb.cn iPhone查询中 - bbs.ipcxz.com
反馈
微信订阅号