Linux下安装memcached和编译PHP扩展
作者: DH 日期: 2009-09-16 10:40
1. 安装memcached (服务器版本1.2.6)
服务器OS是RHEL5(Red Hat Linux Enterprise 5),之前已经装好LAMP环境,这是我们的一台测试服务器,LAMP均位于/opt/lamp下。准备将memcached安装在/opt/cache/memcached目录下。
memcached需要libevent(http://monkey.org/~provos/libevent/)的支持,所以需要先安装libevent,安装目录位于/opt/cache/libevent,下载最新版本的libevent(此例中为1.4.8),解压后进入源代码目录,进行配置和安装。
./configure --prefix=/opt/cache/libevent
make
make install
接着安装memcached,使用的版本是1.2.6,进入解压后的源代码目录,
./configure --prefix=/opt/cache/memcached --with-libevent=/opt/cache/libevent
–with-libevent指令指定libevent的目录
make
make install
安装完成,试着使用
/opt/cache/memcached/bin/memcached -d -m 16 -p 33333 -u memcached -l 127.0.0.1
启动memcached服务器,但会报错,
error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory
意思是memcached无法找到libevent-1.4.so.2这个文件,但明明是指定了libevent的安装目录,为什么找不到呢?
memcached其实是到/usr/lib/目录下去找libevent的so文件,但我在安装时指定的libevent是位于/opt/cache/libevent,所以解决办法是在/usr/lib目录下创建一个文件链接(不知道算不算一个bug)
ln -s /opt/cache/libevent/lib/libevent-1.4.so.2 /usr/lib/libevent-1.4.so.2
再次启动memcached,一切正常。
2. 编译PHP的memcache扩展 (扩展版本2.2.4)
PHP的memcache是PECL下的一个包,下载地址位于http://pecl.php.net/package/memcache,因为这台服务器之前已经装好了PHP环境,所以我们直接将下载的tar包解压到PHP源代码目录下的ext目录中,进入memcache-2.2.4目录,使用phpize生成configure等配置文件
/opt/lamp/php/bin/phpize
配置
./configure --with-php-config=/opt/lamp/php/bin/php-config --enable-shared --enable-static
但此处会报错,提示找不到php_session.h头文件,该文件位于PHP源文件目录下的ext/session下,可以通过修改 configure文件,设置正确的session_inc_path变量,指向PHP源文件目录/opt/lamp/php-5.2.5即可,重新 configure即可通过。
接着调用make,会在module目录下生成memcache.so文件,将此文件拷贝到PHP的extension目录,再修改php.ini,重启httpd就完成了memcache扩展的配置。
值得注意的是,在编译扩展时,并不需要使用make install命令。
评论: 0 |
引用: 0 |
阅读: 106
发表评论
订阅
上一篇
返回
下一篇
标签:

linux awk用法小结 (2010-07-05 11:48)
dell R610 硬盘测速 (2010-07-03 17:20)
linux中用shell获取昨天、明天或多天前的日期 (2010-06-18 12:06)
centos 修改IP地址,网关,DNS (2010-02-04 21:46)
php 二分法 (2009-12-03 13:08)
实例(Smarty+FCKeditor新闻系统) (2009-10-13 22:42)
PHP对MYSQL数据库进行事务处理及表锁定 (2009-09-16 09:31)
PHP截取字符串 包函HTML标志的也可截取 (2009-06-25 13:48)
PHP中二维数组的排序 (2009-05-22 10:51)