Traffic on my VPS jumped over the past few weeks and I needed a better caching solution so I installed W3 Total Cache. It provided you the option of caching pages, databases queries, features an object cache and even allows you to configure a CDN to serve your files. Trouble is, my server only had eaccelerator installed and it wasn’t compiled to use object-caching. Instead of upgrading recompiling eaccelerator, I opted to install XCache on my CPanel-enabled VPS.

Here’s a complete guide on installing Xcache on Cpanel.

First get the latest sources for XCache. As of publishing this guide, it’s 1.3.1

cd /usr/src/

After which, unarchive the source and cd into the directory

tar -xzvf xcache-1.3.1.tar.gz
cd xcache-1.3.1

Time to configure the sources for the current PHP environment

[root@host xcache-1.3.1]# phpize
Configuring for:
PHP Api Version:         20041225
Zend Module Api No:      20060613
Zend Extension Api No:   220060519

Once you see the message above, XCache is ready to install.

./configure && make && make install

This will check for errors and run the installation script. Once complete, you should see this line:

Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20060613/

If like me, you have a different OPCode cache installed like eaccelerator, you need to comment any instances of these from your php.ini file. In my case it was

After that copy these into the php.ini. Note that these are the settings on my server. Tweak them as you need or please.

xcache.admin.auth = off
xcache.admin.enable_auth = off

; admin installation:
xcache.admin.user = "admin username" ;if you're going to use this
xcache.admin.pass = "md5 hash of your password" ;change accordingly

xcache.shm_scheme = "mmap"
; to disable: xcache.size=0
; to enable : xcache.size=64M etc (any size > 0) and your system mmap allows
xcache.size = 128M
; set to cpu count (cat /proc/cpuinfo |grep -c processor)
xcache.count = 4
; just a hash hints, you can always store count(items) > slots
xcache.slots = 8K
; ttl of the cache item, 0=forever
xcache.ttl = 13300
xcache.cacher = On
; interval of gc scanning expired items, 0=no scan, other values is in seconds
xcache.gc_interval = 0

; same as aboves but for variable cache
xcache.var_size = 2M
xcache.var_count = 2
xcache.var_slots = 1K
; default ttl
xcache.var_ttl = 3600
xcache.var_maxttl = 7200
xcache.var_gc_interval = 300

xcache.test = Off
; N/A for /dev/zero
xcache.readonly_protection = Off
; for *nix, xcache.mmap_path is a file path, not directory.
; Use something like "/tmp/xcache" if you want to turn on ReadonlyProtection
; 2 group of php won't share the same /tmp/xcache
; for win32, xcache.mmap_path=anonymous map name, not file path
xcache.mmap_path = "/dev/zero"

; leave it blank(disabled) or "/tmp/phpcore/"
; make sure it's writable by php (without checking open_basedir)
xcache.coredump_directory = ""

; per request settings
xcache.cacher = On
xcache.stat = On
xcache.optimizer = Off

; per request settings
; enable coverage data collecting for xcache.coveragedump_directory and xcache_coverager_start/stop/get/clean() functions (will hurt executing performance)
xcache.coverager = Off

After editing your PHP ini, type:

 php -v

to check if things loaded properly. This is the output from my server:

[root@host xcache-1.3.1]# php -v
PHP 5.2.11 (cli) (built: Oct 27 2009 16:43:13) 
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
    with XCache v1.3.1, Copyright (c) 2005-2010, by mOo
    with the ionCube PHP Loader v3.3.20, Copyright (c) 2002-2010, by ionCube Ltd., and
    with Zend Extension Manager v1.2.2, Copyright (c) 2003-2007, by Zend Technologies
    with Zend Optimizer v3.3.3, Copyright (c) 1998-2007, by Zend Technologies

And you’re done. After which i simply set W3 Total Cache to use XCache for Database and Object Caching, flushed all existing caches and voila!