Memcache系列(二)PHP安装memcache扩展

来源:互联网 发布:四川大学网络教育官网 编辑:程序博客网 时间:2024/06/08 14:07

在系列一中写了linux安装memcached服务;

现在写下php中如何使用

首先要给php添加memcache扩展模块

下载memcache扩展包,可以到官网进行下载,我这里下载的是memcache-3.0.8.tgz的

1. 解压tar zxvf memcache-3.0.8.tgz

2. cd memcache-3.0.8进入到解压的文件目录中

3.  whereis phpize查找phpize路径;我的是在/usr/bin/phpize

执行第三步的时候报错

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile

解决方案:

vi /etc/yum/pluginconf.d/fastestmirror.conf
enabled=1改成0

还有就是没有安装php-devel    安装  yum install php-devel

但是在安装php-devel中还是报错,如下图

 执行 yum --enablerepo=remi,remi-php54 install php-devel  安装成功

然后就可以执行/usr/bin/phpize

4.  ./configure --enable-memcache --with-php-config=/usr/bin/php-config

5. make

6. make install

安装成功后会有类似提示(这里是我安装成功的提示)

 Installing shared extensions: /usr/lib64/php/modules/

然后改php.ini配置文件

在php.ini中加入以下信息

[memcache]
extension_dir = "/usr/lib64/php/modules/"
extension=memcache.so

最后重启nginx  service nginx restart

重启 php-fpm  service php-fpm restart


然后输出下phpinfo();就有memcache模块了

就可以在项目中使用memcache了




btw


由于一个个安装容易出错,想省事的话


 yum --enablerepo=remi install memcached  //安装memcached
service memcached start     //启动
chkconfig memcached on   //自动启动,防止以后重启服务器了它还要再手动启动

yum --enablerepo=remi install php-pecl-memcache   //安装php的memcache扩展包

然后重启   nginx     php-fpm  即可


0 0
原创粉丝点击