Linux下安装php的memcached扩展(memcache的客户端)
php的扩展memcache,不支持cas,所以我们要装memcached扩展,memcached扩展是基于libmemcached,所以要先安装libmemcached
一、下载软件
1、libmemcached下载地址:https://launchpad.net/libmemcached/+download
(https://launchpadlibrarian.net/165454254/libmemcached-1.0.18.tar.gz)
文件:libmemcached-1.0.18.tar.gz
2、php-memcached下载地址:http://pecl.php.net/package/memcached
(http://pecl.php.net/get/memcached-2.2.0.tgz)
文件:memcached-2.2.0.tgz
二、安装libmemcached
[root@localhost src]# tar zxvf libmemcached-1.0.18.tar.gz
[root@localhost src]# cd libmemcached-1.0.18
[root@localhost libmemcached-1.0.18]# ./configure --prefix=/usr/local/libmemcached --with-memcached
[root@localhost libmemcached-1.0.18]# make
[root@localhost libmemcached-1.0.18]# make install
三、安装php-memcached(php扩展编译的通用办法,以memcached为例)
[root@localhost src]# tar zxvf memcached-2.2.0.tgz
[root@localhost src]# cd memcached-2.2.0
[root@localhost memcached-2.2.0]# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version: 20131106
Zend Module Api No: 20131226
Zend Extension Api No: 220131226
[root@localhost memcached-2.2.0]# ./configure --enable-memcached --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached --disable-memcached
【编译时可能会出错'configure: error: no, sasl.h is not available'--------解决方法:需要安装libsasl2 ubuntu下用sudo apt-get install libsasl2-dev
也有可能需要在编译参数中添加--disable-memcached-sasl
】
[root@localhost memcached-2.2.0]# make
[root@localhost memcached-2.2.0]# make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20131226/
[root@localhost memcached-2.2.0]# ll /usr/local/php/lib/php/extensions/no-debug-zts-20131226/
total 2140
-rwxr-xr-x. 1 root root 325608 Dec 30 15:59 memcached.so
-rwxr-xr-x. 1 root root 540834 Dec 19 15:38 opcache.so
[root@localhost memcached-2.2.0]#cp -p /usr/local/src/php-5.6.30/php.ini-development ./php.ini 【因为此时/usr/local/php/lib/下不存在php.ini】
[root@localhost memcached-2.2.0]# vim /usr/local/php/lib/php.ini
加上extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/memcached.so
重启apache
[root@localhost memcached-2.2.0]#/usr/local/httpd/bin/apachectl restart
查看phpinfo可以看到支持了,说明memcached扩展已成功安装!
寻找PHP加载php.ini文件目录的技巧:
1.可以使用phpinfo()函数打印并查看(Configuration File (php.ini) Path)信息
2.如果此目录下没有php.ini配置文件,可以到php安装包中复制一份到此目录下(安装包php配置文件的命名是php.ini-development)