一、安装Xcache
# wget http://xcache.lighttpd.net/pub/Releases/1.3.0/xcache-1.3.0.tar.gz
# tar zxvf xcache-1.3.0.tar.gz
# cd xcache-1.3.0
# /usr/local/php/bin/phpize
# ./configure --enable-xcache--enable-xcache-coverager --enable-xcache-optimizer--with-php-config=/usr/local/php/bin/php-config
# make && make install
# tar zxvf xcache-1.3.0.tar.gz
# cd xcache-1.3.0
# /usr/local/php/bin/phpize
# ./configure --enable-xcache--enable-xcache-coverager --enable-xcache-optimizer--with-php-config=/usr/local/php/bin/php-config
# make && make install
注:
--enable-xcache 表示启用Xcache支持;
--enable-xcache-coverager 表示包含用于测量加速器功效的附加特性;
--enable-xcache-optimizer表示启用操作码优化
安装完毕后系统会提示xcache.so模块生成路径,本次生成路径为/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/,然后把xcache.so移动到/usr/local/php/include/php/ext目录下。
二、配置管理Xcache
1、修改php配置文件
配置时我们可以参考xcache的配置模板xcache.ini,此文件位于Xcache安装程序中
# vi /usr/local/php/lib/php.ini
然后添加如下内容
extension_dir=/usr/local/php/include/php/ext
[xcache-common]
extension = xcache.so
[xcache.admin]
xcache.admin.enable_auth = On
xcache.admin.user = "xcache"
xcache.admin.pass = ""
[xcache]
xcache.shm_scheme ="mmap"
xcache.size=60M
xcache.count =1
xcache.slots =8K
xcache.ttl=0
xcache.gc_interval =0
xcache.var_size=4M
xcache.var_count =1
xcache.var_slots =8K
xcache.var_ttl=0
xcache.var_maxttl=0
xcache.var_gc_interval =300
xcache.test =Off
xcache.readonly_protection = On
xcache.mmap_path ="/tmp/xcache"
xcache.coredump_directory =""
xcache.cacher =On
xcache.stat=On
xcache.optimizer =Off
[xcache.coverager]
xcache.coverager =On
xcache.coveragedump_directory =""
[xcache-common]
extension = xcache.so
[xcache.admin]
xcache.admin.enable_auth = On
xcache.admin.user = "xcache"
xcache.admin.pass = ""
[xcache]
xcache.shm_scheme ="mmap"
xcache.size=60M
xcache.count =1
xcache.slots =8K
xcache.ttl=0
xcache.gc_interval =0
xcache.var_size=4M
xcache.var_count =1
xcache.var_slots =8K
xcache.var_ttl=0
xcache.var_maxttl=0
xcache.var_gc_interval =300
xcache.test =Off
xcache.readonly_protection = On
xcache.mmap_path ="/tmp/xcache"
xcache.coredump_directory =""
xcache.cacher =On
xcache.stat=On
xcache.optimizer =Off
[xcache.coverager]
xcache.coverager =On
xcache.coveragedump_directory =""
2、生成Xcache缓存文件
# touch /tmp/xcache
# chmod 777 /tmp/xcache
3、生成Xcache管理员的秘密(MD5密文)
# echo -n "123456" | md5sum
e10adc3949ba59abbe56e057f20f883e
然后将上述生成的MD5密文粘贴到php.ini文件中xcache.admin.pass = ""选项,xcache.admin.pass= "e10adc3949ba59abbe56e057f20f883e"
4、拷贝Xcache管理程序到网站根目录下
# cp -a /tmp/xcache-1.3.0/admin/ /usr/local/nginx/html/
然后重新启动PHP,然后访问http://localhost/admin ,用户名为xcache 密码为123456;另外,还可以通过phpinfo来验证PHP是否支持Xcache