23 May 2012
Installing the XCache Extension in PHP
This should work in 5.2.x, 5.3.x and now even 5.4.x.
I’ll try to make this one easy since I’m assuming you’ve installed an extension before (Read my eAccelerator article if you haven’t).
First, you’ll want to make sure you’re not running eAccelerator or APC already. If you are, make sure they’re disabled before continuing.
Next, you need to grab the sources for XCache and build them.
wget http://insert.actual.url.here/xcache-x.x.x.tar.gz tar zxvf xcache-x.x.x.tar.gz cd xcache phpize ./configure ; make ; make install
It builds cleanly on any machine I’ve tested, so you shouldn’t get any errors. Once you’ve ensured no errors were shown, you can proceed to configuration. You’ll need to copy the contents of xcache.ini either into php.ini (append, don’t overwrite!) or just copy xcache.ini into /etc/php.d or your distribution’s equivalent directory.
To properly configure it, there are a few sections of XCache configuration to edit (I’ll explain after):
We’ll start from the top:
extension - This is the same format as any other extension line, and is the most important.
xcache.admin.enable_auth - Set this to On. Trust me you’ll love it. The next two options are self explanatory. The first being the user to authenticate to the admin page with, and the second is an md5sum of your desired password.
xcache.size - This is the maximum size of available SHM space for XCache. The default max SHM size for most Linux distros is 32M. Set a higher value to kernel.shmmax to increase this.
xcache.ttl - This is the “time-to-live” and determines the maximum age of a cached object.
xcache.gc_interval - This defines the garbage collection interval (how often cache is cleaned).
xcache.var_* - Most of these settings should remain the same. You can increase the var size if you have a very heavy PHP site, but don’t increase the GC interval unless you know what you’re doing.
xcache.cacher - Enable the opcode cacher. Do it.
xcache.optimizer - Enable the optimizer. Do this also!
Now you want to test and make sure it’s properly configured. Usually, you can just run ‘php -v’ to show the version and you’ll see an XCache version appended to the bottom, but it depends on the implementation of PHP you’re running.
The final step is to place the admin directory in a public folder somewhere under your DocumentRoot. Assuming you’re still sitting in the source directory for XCache, and your site (example.com) is hosted inside /var/www/example.com, you can do that like this:
cp -a admin/ /var/www/example.com/XCacheAdmin
Perhaps also adjust permissions accordingly..
Now you just need to restart your PHP interpreter (Apache or Spawn-FCGI or PHP-FPM, for example). When you visit www.example.com/XCacheAdmin , you will be presented with a login prompt, into which you enter the user/pass combo you chose before. This will show you statistics and usage of the cache.
Yet another crap post by:
Salvatore LaMendola at 22:53