当前使用Centos6.x系统,php使用7.1版本,wlnmp一键包已支持该扩展
php7安装memcached扩展(基于Centos7.x)参考:https://blog.whsir.com/post-4841.html
memcached扩展包地址:https://pecl.php.net/package/memcached
与Centos7不同的是,在Centos6.x环境下默认yum安装libmemcached版本过低,需要手动编译libmemcached
1、安装所需依赖,如果在编译时还提示缺少其他依赖,请自行安装
yum install autoconf gcc gcc-c++
|---|----------------------------------| | 1 | yum install autoconf gcc gcc-c++ |
2、编译libmemcached
wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz tar xf libmemcached-1.0.18.tar.gz cd libmemcached-1.0.18 ./configure make
|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 | wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz tar xf libmemcached-1.0.18.tar.gz cd libmemcached-1.0.18 ./configure make |
3、下载memcached最新稳定版
wget https://pecl.php.net/get/memcached-3.1.3.tgz tar xf memcached-3.1.3.tgz cd memcached-3.1.3 /usr/local/php/bin/phpize
|---------|---------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 | wget https://pecl.php.net/get/memcached-3.1.3.tgz tar xf memcached-3.1.3.tgz cd memcached-3.1.3 /usr/local/php/bin/phpize |
根据自己phpize的位置来运行即可(不知道phpize在哪的直接find / -name phpize查找),运行完提示下面信息,然后编译
Configuring for:
PHP Api Version: 20160303
Zend Module Api No: 20160303
Zend Extension Api No: 320160303
4、编译扩展模块
./configure --with-php-config=/usr/local/php/bin/php-config --disable-memcached-sasl make make install
|-------|--------------------------------------------------------------------------------------------------------| | 1 2 3 | ./configure --with-php-config=/usr/local/php/bin/php-config --disable-memcached-sasl make make install |
执行完成后会显示扩展模块编译到的目录/usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/
5、修改php.ini添加扩展
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/" extension=memcached.so
|-----|-------------------------------------------------------------------------------------------------------| | 1 2 | extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/" extension=memcached.so |
注意:如果之前配置过extension_dir路径了,则只需要配置extension=memcached.so即可
保存退出,重启php
通过phpinfo可看到,扩展已生效