1.安装包准备
a.memcache的服务端
libevent : memcache服务安装需要的库
https://github.com/libevent/libevent/releases/download/release-2.1.8-stable/libevent-2.1.8-stable.tar.gz
memcached : memcache服务安装源码(注意后面有'd')
http://memcached.org/
b.memcahe的php扩展
libmemcached : 扩展库
http://libmemcached.org/libMemcached.html
memcached : php连接memcache的扩展安装源码(在http://pecl.php.net/中有3种php-memcache扩展,我们选择一直在维护的memcached,要注意版本选择,不能盲目选择最新的版本,要根据自己php的版本进行选择。我的php版本时5.6.9,所以选择了2.1.0版的memcached)
http://pecl.php.net/package-search.php?pkg_name=memcache&bool=AND&submit=Search
2.安装
a.安装libevent
tar xvf libevent-xxx
cd libevent-xxx
./configure --prefix=/usr/local/libevent
make
make install
b.安装memcached服务
tar xvf memcached-xxx
cd memcached-xxx
./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent
make
make install
启动memcached:/usr/local/memcached/bin/memcached -d -m 50 -u root -p 12000 -c 256 -P /tmp/memcached.pid
注:
-d选项是启动一个守护进程,
-m是分配给Memcache使用的内存数量,单位是MB.
-u是运行Memcache的用户.
-l是监听的服务器IP地址,我这里没有填.
-p是设置Memcache监听的端口.
-c选项是最大运行的并发连接数,默认是1024,按照你服务器的负载量来设定.
-P是设置保存Memcache的pid文件.
检查memcache是否启动成功:ps aux | grep memcached
c.安装libmemcached库
tar xvf libmemcached-xxx
cd libmemcached-xxx
./configure --prefix=/usr/local/libmemcached --with-memcached=/usr/local/memcached/bin/memcached
make
make install
d.安装php的memcached扩展
tar xvf memcached-xxx
cd memcached-xxx
/usr/local/php/bin/phpize
:你的php安装目录下的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
重启php服务
查看扩展是否安装成功:php -m | grep memcache