Compiling XCache from Source
For those of you that are not running RPM-based distros, you’re probably feeling a bit left out. Up until now, all of my tutorials have dealt with upgrading RPM-based distros. Well, that ends here. I’m going to walk through the fairly simple process of compiling and installing XCache for httpd from the original source.
The current stable release of XCache is 1.0.3. The “Unstable” release, made for PHP 5.1 & 5.2, is 1.2.0. Despite the label, I have not found anything “unstable” about the 1.2.0 version. That said, there have been a few issues reported on the vBulletin forums for users of PHP 4. If you are running PHP 4, I’d recommend that you use 1.0.3, just to be safe. Now, down to the work.
Assuming that you already have a full development environment on your system (gcc, gcc-c++, make, php-devel, etc.), the first thing you’ll need to do is to download the source tarball to your computer. Pick the version you want and then continue to the next step.
XCache 1.0.3 - PHP 4.x
XCache 1.2.0 - PHP 5.1 & 5.2
Once you’ve downloaded the source pacakge to your server, unpack it and then enter the “xcache” directory that was just created. At this point, you’ll want to run the following commands. Even a slow system should be done within 1 or 2 minutes, so don’t go anywhere.
* phpize
* ./configure –enable-xcache –enable-xcache-optimizer
* make
* make install
The output of “make install” is very important as it lets you know where the compiled module was installed. Make sure that you remember or write down that string.
Now that the xcache.so module is installed, you’ll need to configure it. If your install of PHP parses the /etc/php.d/ folder then you should create a file in that folder called “xcache.ini”. If not, just open your php.ini file and paste in the following:
[xcache-common]
zend_extension = /usr/lib/php4/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.size = 32M
xcache.count = 1
xcache.slots = 8K
xcache.mmap_path = “/dev/zero”
xcache.cacher = On
xcache.optimizer = On
Based on your configuration, you may want to make a few changes. If “/usr/lib/php4″ was not where “make install” claimed to have installed the xcache.so module, change it. Likewise, if your system has multiple processors (count logical cores from Hyper-Threading), change the value of “xcache.count”. Finally, if you plan to use the web admin interface, you’ll need to fill in “xcache.admin.pass”. This value should be a MD5 of the password you want to use (if you need an MD5 generator, try this one).
If you filled in the password, you should also copy the contents of the “admin” folder from the “xcache” source folder to somewhere web-accessible. No changes need to be made and the “config.php.example” file should be left as-is.
At this point, all that’s left is to restart httpd and you should be good. Check your phpinfo() once you’ve restarted httpd to make sure that xcache is listed.