1.第一步需要安装编译工具
2.将memcache安装到/usr/local/src目录
yum install wget make gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel kernel keyutils patch perl
2.将memcache安装到/usr/local/src目录
cd /usr/local/src
wget http://pecl.php.net/get/memcache-2.2.6.tgz #下载
tar zxvf memcache-2.2.6.tgz #解压
cd memcache-2.2.6 #进入安装目录
/usr/bin/phpize #用phpize生成configure配置文件
注:如果 /usr/bin/phpize 这个命令执行失败可以是用whereis phpize 查找phpize的路径
Can’t find PHP headers in /usr/include/php
The php-devel package is required for use of this command.
如果安装报类似上面的错误,
是因为没有安装php-devel插件,直接使用yum安装。
yum install php-devel
会提示下载几个依赖包,选择Y安装即可。
3.进行配置
./configure --with-php-config=/usr/bin/php-config
在进行上面的命令前,不妨使用whereis php-config 查看php-config路径
make #编译
make install #安装
当看到下面的输出内容,证明编译安装成功了!
Installing shared extensions: /usr/lib64/php/modules/
4.php.ini
添加一行来载入memcache扩展
extension="memcache.so"
5.
重启apache服务
systemctl restart httpd.service
6.
测试 memcache 安装是否完成
vi /var/www/html/info.php
<?php
phpinfo();
?>
7.开启memcached服务
#首先查看一下memcached服务路径
[root@localhost src]# whereis memcached
memcached: /usr/bin/memcached /usr/share/man/man1/memcached.1.gz
#进入目录,开启服务
memcached -d -u root
8.执行php代码,测试
$mem = new Memcache();
$mem ->connect('127.0.0.1',11211);
$mem->set('key','gentry',0,0);
echo $mem->get('key');
页面能够输出gentry,证明php开启memcache扩展成功啦!!!