|
我的PHP-memcache安装过程如下:
http://www.linuxsir.cn/main/?q=node/184
tonyvicky兄的贴子操作的,我贴出来。
一、环境需求
安装Memcached需要libevent库的支持,所以请在安装Memcached之前检查有没有安装libevent。测试环境还需要PHP的支持,本文假设PHP已经安装到/usr/local/php目录下,也就是在编译PHP的时候使用perfix参数指定目录(--prefix=/usr/local/php)
二、下载相关软件
Memcached下载地址:http://www.danga.com/memcached/
memcache PHP模块下载地址: http://pecl.php.net/package/memcache 推荐使用1.5版
libevent 下载地址: http://www.monkey.org/~provos/libevent/
本文不再讲述如何安装libevent
三、安装和配置
1、安装Memcached
root@tonyvicky:# tar vxzf memcached-1.1.12.tar.gz
root@tonyvicky:# cd memcached-1.1.12
root@tonyvicky:# ./configure --prefix=/usr/local/memcached
root@tonyvicky:# make
root@tonyvicky:# make install
安装完之后要启动服务
root@tonyvicky:# cd /usr/local/memcached/bin
root@tonyvicky:# ./memcached -d -m 50 -p 11211 -u root
参数说明 -m 指定使用多少兆的缓存空间;-p 指定要监听的端口; -u 指定以哪个用户来运行
2、安装memcache PHP模块
root@tonyvicky:# tar vxzf memcache-1.5.tgz
root@tonyvicky:# cd memcache-1.5
root@tonyvicky:# /usr/local/php/bin/phpize
root@tonyvicky:# ./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir
root@tonyvicky:# make
root@tonyvicky:# make install
安装完后会有类似这样的提示:
Installing shared extensions: /usr/local/php//lib/php/extensions/no-debug-non-zts-20060613
把这个记住,然后修改php.ini,把
extension_dir = "./"
修改为
extension_dir = "/usr/local/php//lib/php/extensions/no-debug-non-zts-20060613"
并添加一行
extension=memcache.so
3、测试脚本
自己写一个PHP程序测试一下吧
<?php
$memcache = new Memcache; //创建一个memcache对象
$memcache->connect('localhost', 11211) or die ("Could not connect"); //连接Memcached服务器
$memcache->set('key', 'test'); //设置一个变量到内存中,名称是key 值是test
$get_value = $memcache->get('key'); //从内存中取出key的值
echo $get_value;
?>
IE中提示:
Fatal error: Class 'Memcache' not found in /usr/local/apache2/htdocs/test12.php on line 2
我估计是memcache没有安装好。PHP模块里也没有看到。
我的系统是AS5和RH9
在二个系统的PHP安装目录下分别执行:
[root@server3 root]# cd php-5.2.4
[root@server3 php-5.2.4]# ./configure --help |grep memcache
无任何提示,我更换了版本和系统都不行。重新装也不行。
我在公司里已安装好memcache的服务器上:
[root@server3 root]# cd php-5.2.4
[root@server3 php-5.2.4]# ./configure --help |grep memcache
--enable-memcache Enable memcache support
--disable-memcache-session Disable memcache session handler support
--with-zlib-dir=DIR memcache: Set the path to ZLIB install prefix.
却能看到相关的信息。这是为什么?
我的PHP编译参数为:
./configure --prefix=/usr/local/php/ --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql/ --with-gd --with-jpeg-dir=/usr/local/jpeg6/ --with-png-dir=/usr/local --enable-mbstring --with-libxml-dir=/usr/local/libxml2 --enable-memcache
。。。。
。。。。
。。。。
Thank you for using PHP.
Notice: Following unknown configure options were used:
--enable-memcache
--enable-apc
Check './configure --help' for available options
结果就成这样子了。实在是想不到办法了。上来求救! |
|