XCache is one of the most respected php cachers around, so here’s a little how to guide that I wrote up as a reference for myself a while back. Hope you find it useful…
- Ssh telnet into your server as root user
- Grab XCache by typing:
wget http://xcache.lighttpd.net/pub/Releases/1.2.2/xcache-1.2.2.tar.gz
Wait for package to download
- find phpize and php-config paths, type:
whereis php-config
outputs looks like:
phpize: /usr/bin/phpize /usr/local/bin/phpize and
php-config: /usr/bin/php-config /usr/local/bin/php-config
Next we’ll extract files, change directories and install, by referencing the file paths we were given above:
cd xcache-1.2.2
/usr/bin/phpize
./configure --enable-xcache
make
make install
Take note of where it copies xcache.so file i.e.
/usr/lib/php/extensions/no-debug-non-zts-20020616/xcache.so
Now locate php.ini, type:
output looks like:
php: /usr/bin/php /usr/lib/php /usr/lib/php.ini /usr/local/lib/php.ini /usr/include/php /usr/man/man1/php.1
Edit php.ini using pico, vi or nano text editors (in linux) and scroll to the section like:
;Note that MySQL and ODBC support is now built in, so no dll is needed for it.
;
;extension=php_bz2.dll
Above that add the following, but edit accordingly (see proceeding notes)
[xcache-common]
zend_extension = /usr/lib/php/extensions/no-debug-non-zts-20020616/xcache.so
; required for >=php5.1 if you turn XCache on
auto_globals_jit = Off
[xcache.admin]
xcache.admin.user = "admin"
; paste the output of md5("password") below
xcache.admin.pass = ""
[xcache]
xcache.shm_scheme = "mmap"
xcache.size = 32M
xcache.count = 1
xcache.slots = 8K
xcache.ttl = 7200
xcache.gc_interval = 300
xcache.var_size = 32M
xcache.var_count = 1
xcache.var_slots = 8K
xcache.var_ttl = 7200
xcache.var_maxttl = 14400
xcache.var_gc_interval = 300
xcache.test = Off
xcache.readonly_protection = Off
xcache.mmap_path = "/dev/zero"
xcache.coredump_directory = ""
xcache.cacher = On
xcache.stat = On
xcache.optimizer = On
[xcache.coverager]
xcache.coverager = Off
xcache.coveragedump_directory = ""
Note: xcache.count refers to the number of processors
Note: You may want to set ‘xcache.size’ and ‘xcache.var_size’ to 64 if you have over 1GB of ram.
Save php.ini file and restart Apache for XCache to load:
- /etc/rc.d/init.d/httpd stop
- /etc/rc.d/init.d/httpd start
Finally, check phpinfo.php for XCache section
Disclaimer & Credits
As usual, this guide is provided with no warranties or guarantees – use at your own risk.
Thanks to George (eva2000 at vbulletin) for the basic template and Teck for the settings.