这篇文章主要介绍了centos系统为php安装memcached扩展的步骤,大家参考使用吧
1.通过yum安装
yum -y install memcached
#安装完成后执行:
memcached -h
#出现memcached帮助信息说明安装成功
2.加入启动服务
chkconfig –level 2345 memcached on
3.配置Memcached
vim /etc/sysconfig/memcached
#文件中内容如下,按需要修改:
1 | PORT="11211" #端口 |
4.安装libmemached
wget https://launchpad.net/libmemcached/1.0/1.0.16/+download/libmemcached-1.0.16.tar.gz
tar -zxvf libmemcached-1.0.16.tar.gz
cd libmemcached-1.0.16
./configure -prefix=/usr/local/libmemcached -with-memcached
make && make install
注意:这里容易报错,
编译错误:
libmemcached/auto.cc: In function ‘memcached_return_t text_incr_decr(memcached_server_st, bool, const char, size_t, uint64_t, bool)’:
libmemcached/auto.cc:73: error: expected `)’ before ‘PRIu64’
In file included from ./libmemcached/common.h:72,
from ./libmemcached/csl/common.h:40,
from libmemcached/csl/context.cc:38:
./libmemcached-1.0/memcached.h:46:27: error: tr1/cinttypes: No such file or directory
原因是gcc版本过低了
对策:libmemcached-1.0.2 版本以上升级编译器版本
# yum install gcc44 gcc44-c++ libstdc++44-devel
# export CC=/usr/bin/gcc44
# export CXX=/usr/bin/g++44
# ./configure
如果升级gcc版本出现连接源的问题不能下载,可以换用163的yum源,参考文章
https://zhizhi123.com/2015/08/25/centos-yum-163-source/
5.安装php-devel
yum install php-devel
6.安装PHP Memcached扩展
wget http://pecl.php.net/get/memcached-2.1.0.tgz
tar -zxvf memcached-2.1.0.tgz
cd memcached-2.1.0
/usr/local/php/bin/phpize
./configure -enable-memcached -with-php-config=/usr/local/php/bin/php-config -with-zlib-dir -with-libmemcached-dir=/usr/local/libmemcached -prefix=/usr/local/phpmemcached
make && make install
-------------本文结束,感谢您的阅读-------------