1.安装libevent库,下载地址:
# ./configure && make# make install
2.安装memcache,下载地址: 默认安装到/usr/local/bin/下了
# ./configure --with-libevent=/usr/local/# make# make install
3.安装Memcache的PHP扩展,下载地址
# tar zxvf memcache-2.2.5.tgz# cd memcache-2.2.5 # /usr/local/php5/bin/phpize# ./configure --enable-memcache --with-php-config=/usr/local/php5/bin/php-config --with-zlib-dir# make# make test (出错Build complete.Don't forget to run 'make test'.PHP Warning: PHP Startup: Unable to load dynamic library './php_mysql.dll' - ./php_mysql.dll: cannot open shared object file: No such file or directory in Unknown on line 0)# make installInstalling shared extensions: /usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/
4.整合memcache和php
# vi /usr/local/php5/lib/php.ini修改extension_dir = "./" 为 extension_dir = /usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/添加一行来载入memcache扩展:extension=memcache.so
5.调试
下面运行memcache,有出错信息# memcached -d -m 1000 -u root -l 127.0.0.1 -p 12000 -c 256 -P /tmp/memcached.pidmemcached: error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory我们来进行调试:# LD_DEBUG=libs memcached -v 20139: find library=libevent-1.4.so.2 [0]; searching 20139: search cache=/etc/ld.so.cache 20139: search path=/lib64/tls/x86_64:/lib64/tls:/lib64/x86_64:/lib64:/usr/lib64/tls/x86_64:/usr/lib64/tls:/usr/lib64/x86_64:/usr/lib64 (system search path) 20139: trying file=/lib64/tls/x86_64/libevent-1.4.so.2 20139: trying file=/lib64/tls/libevent-1.4.so.2 20139: trying file=/lib64/x86_64/libevent-1.4.so.2 20139: trying file=/lib64/libevent-1.4.so.2 20139: trying file=/usr/lib64/tls/x86_64/libevent-1.4.so.2 20139: trying file=/usr/lib64/tls/libevent-1.4.so.2 20139: trying file=/usr/lib64/x86_64/libevent-1.4.so.2 20139: trying file=/usr/lib64/libevent-1.4.so.2 20139:memcached: error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory可能是由于64位的操作系统搜索路径问题,现在的lib是在/usr/local/lib/下面,我们做个软连接:# ln -s /usr/local/lib/libevent-1.4.so.2 /usr/lib64/libevent-1.4.so.2# memcached -d -m 1000 -u root -l 127.0.0.1 -p 12000 -c 256 -P /tmp/memcached.pid
6.运行memcache
# memcached -d -m 1000 -u root -l 127.0.0.1 -p 11211 -c 1024 -P /tmp/memcached.pid -d选项是启动一个守护进程。-m是分配给Memcache使用的内存数量,单位是MB。-u是运行Memcache的用户,这里是root。-l是监听的服务器IP地址,如果有多个地址的话,我这里指定了服务器的IP地址127.0.0.1。-p是设置Memcache监听的端口,我这里设置了12000,最好是1024以上的端口。-c选项是最大运行的并发连接数,默认是1024,按照你服务器的负载量来设定。-P是设置保存Memcache的pid文件,这里是保存在 /tmp/memcached.pid。