一、安装memcached

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

wget http://memcached.org/latest 
tar zxvf memcache1.5.7.tar.gz
cd memcached-1.5.7
./configure --prefix=/usr/local/memcache --with-libevent=/usr/local/libevent
make && make install

#启动
./memcached -m 128-p 11211 -u nobody -c 2000 -d

二、安装依赖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 
make && make install

三、安装php memcached

wget http://pecl.php.net/get/memcached-3.0.3.tgz
tar zxvf memcached-3.0.3.tgz
cd memcached-3.0.3/
/usr/local/php/bin/phpize

#如果phpize出现Cannot find autoconf错误
yum install m4
yum install autoconf

./configure --with-php-config=/usr/local/php/bin/php-config --disable-memcached-sasl
make && make install

###执行结果会出现类似下列信息
###Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-zts-20170718/

四、PHP加载memcached扩展

vi php.ini
extension=/usr/local/php/lib/php/extensions/no-debug-zts-20170718/memcached.so

五、平滑重启php-fpm

kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`