CentOS环境PHP下安装memcache扩展

分类:CentOS教程 阅读:30013 次

1、安装libmemcached库

yum install libmemcached

2、下载并解压memcache文件

wget http://pecl.php.net/get/memcache-3.0.8.tgz

tar xzvf memcache-3.0.8.tgz

cd memcache-3.0.8

3、执行phpize扩展安装程序,假设phpzie的路径为/usr/local/php/bin/phpize,具体的路径得根据自己的环境修改。

[root@naginx memcache-3.0.8]# /usr/local/php/bin/phpize

Configuring for:

PHP Api Version: 20100412

Zend Module Api No: 20100525

Zend Extension Api No: 220100525

4、开始安装扩展memcache

[root@naginx memcache-3.0.8]# ./configure --enable-memcache \

--with-php-config=/usr/local/php/bin/php-config --with-zlib-dir \

make && make install

安装完成后,提示

Build complete.

Don't forget to run 'make test'.

Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/

5、最后修改php.ini文件,在zend之前加入如下代码。

vim /usr/local/php/lib/php.ini

extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/memcache.so

6、重新启动php-fpm

kill -QUIT pid

/usr/local/php/sbin/php-fpm

7、通过phpinfo()可以查看memcached信息

 CentOS环境PHP下安装memcache扩展

8、启动memecached

./memcached -d -m 100 -l 192.168.1.120 -p 11211 -u root

9、测试

附php的memcache测试代码:

<?php

$mem = new Memcache;

$mem->connect("192.168.1.120", 11211) or die("Could not connect");

$version = $mem->getVersion();

echo "Server's version: ".$version."<br/>\n";

$mem->set('hellokey', 'Hello World', 0, 600) or die("Failed to save data at the memcached server");

echo "Store data in the cache (data will expire in 600 seconds)<br/>\n";

$get_result = $mem->get('hellokey');

echo "$get_result is from memcached server.";

?>

 CentOS环境PHP下安装memcache扩展

查看命中结果

telnet 192.168.1.120 11211

输入命令:status

 CentOS环境PHP下安装memcache扩展