先去官方下最新版本的memcached(memcached-1.4.22.tar.gz)和依赖包libevent (libevent-2.0.21-stable.tar.gz):
http://www.memcached.org/files/
http://libevent.org/
还有两个PHP的扩展包:
http://pecl.php.net/package/memcache
http://pecl.php.net/package/memcached
我目前下的最新版分别是:memcache-2.2.7.tgz和memcached-2.2.0.tgz
因为php的memcached包要先装装libmemcached下载如下
https://launchpad.net/libmemcached
最新包libmemcached-1.0.18.tar.gz
上述五个包下载好上传到VPS后:
先编译libevent:
tar -zxvf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable.tar.gz
./configure --prefix=/usr/local
make && make install
tar -zxvf memcached-1.4.22.tar.gz
cd memcached-1.4.22
./configure --with-libevent=/usr/local
make && make install
#因为自定义了安装路径所以软链下lib
ln -s /usr/local/lib/libevent* /usr/lib/
#制作启动服务
cd scripts
mv memcached.sysv /etc/init.d/memcached
#记得vi下你的memcached目录
chmod 755 /etc/init.d/memcached
chkconfig --add memcached
chkconfig --level 345 memcached on
chkconfig --list memcached
要修改的服务启动内容,注意实际路径、配置参数和pid文件路径下图所示:
接下来编译PHP的两个扩展:
tar -zxvf memcache-2.2.7.tgz
cd memcache-2.2.7
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir --enable-memcache
make && make install
tar -zxvf libmemcached-1.0.18.tar.gz
cd libmemcached-1.0.18
./configure
make && make install
tar -zxvf memcached-2.2.0.tgz
cd memcached-2.2.0
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
如果执行下来没错误,那我们可以看到终端显示的扩展目录(注意有可能与你的目录不相同)
最后我们编辑php.ini修改extension_dir目录和加入extension=memcache.so和extension=memcached.so
重新启动:
#memcached
service memcached start
#php
service php-fpm restart
后记:验证下memcached有没有启动成功我们可以telnet 127.0.0.1 11211 再输入stats看状态