Linux下为PHP扩展安装Memcache模块

安装环境
RHEL 4
PHP 5.2.6


所需软件
libevent-1.4.6-stable.tar.gz (~provos/libevent/)
memcache-2.2.3.tgz ()
memcached-1.2.6.tar.gz (最新版已经是memcached-1.4.5.tar.gz) ()


安装配置

1. 安装libevent
# tar zxf libevent-1.4.6-stable.tar.gz
# cd libevent-1.4.6-stable
# ./configure --prefix=/usr/local/servers/libevent
# make && make install

2. 安装memcached
# tar zxvf memcached-1.2.6.tar.gz
# cd memcached-1.2.6
# ./configure --prefix=/usr/local/servers/memcached --with-libevent=/usr/local/servers/libevent
# make && make install

3. 运行memcached
# /usr/local/servers/memcached -d -m 128 -l localhost -p 11211 -u root

-d 以守护程序(daemon)方式运行 memcached;
-m 设置 memcached 可以使用的内存大小,单位为 M;
-l 设置监听的 IP 地址,如果是本机的话,通常可以不设置此参数;
-p 设置监听的端口,默认为 11211,所以也可以不设置此参数;
-u 指定用户;

如果遇到运行memcached时遇到问题,错误提示如下:

/usr/local/servers/memcached/bin/memcached: error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory

则运行 LD_DUBUG=libs 就可以知道memcached启动时库的加载路径。具体如下:

# LD_DEBUG=libs /usr/local/servers/memcached/bin/memcached -v
     10929:     find library=libevent-1.4.so.2 [0]; searching
     10929:      search cache=/etc/ld.so.cache
     10929:      search path=/lib/tls/i686/sse2:/lib/tls/i686:/lib/tls/sse2:/lib/tls:/lib/i686/sse2:/lib/i686:/lib/sse2:/lib:/usr/lib/tls/i686/sse2:/usr/lib/tls/i686:/usr/lib/tls/sse2:/usr/lib/tls:/usr/lib/i686/sse2:/usr/lib/i686:/usr/lib/sse2:/usr/lib          (system search path)
     10929:       trying file=/lib/tls/i686/sse2/libevent-1.4.so.2
     10929:       trying file=/lib/tls/i686/libevent-1.4.so.2
     10929:       trying file=/lib/tls/sse2/libevent-1.4.so.2
     10929:       trying file=/lib/tls/libevent-1.4.so.2
     10929:       trying file=/lib/i686/sse2/libevent-1.4.so.2
     10929:       trying file=/lib/i686/libevent-1.4.so.2
     10929:       trying file=/lib/sse2/libevent-1.4.so.2
     10929:       trying file=/lib/libevent-1.4.so.2
     10929:       trying file=/usr/lib/tls/i686/sse2/libevent-1.4.so.2
     10929:       trying file=/usr/lib/tls/i686/libevent-1.4.so.2
     10929:       trying file=/usr/lib/tls/sse2/libevent-1.4.so.2
     10929:       trying file=/usr/lib/tls/libevent-1.4.so.2
     10929:       trying file=/usr/lib/i686/sse2/libevent-1.4.so.2
     10929:       trying file=/usr/lib/i686/libevent-1.4.so.2
     10929:       trying file=/usr/lib/sse2/libevent-1.4.so.2
     10929:       trying file=/usr/lib/libevent-1.4.so.2
     10929:

然后给libevent-1.4.so.2建立一个链接后再运行memcached:
# ln -s /usr/local/servers/libevent/lib/libevent-1.4.so.2 /lib/libevent-1.4.so.2

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wydwps.html