If you have 40-50 large clients running dynamic website on php on a single server, or you have a high-traffic php-based website serving thousands of pages a day. Performance will hit a serious speed bump. One of the many things you can do, apart from expanding your server, is to use php-opcode cacher like x-cache. There are alternatives to xcache, like apc, eaccelerator, phpa and mmcache to name a few; but according to most benchmark tests (benchmark1 Results, benchmark2) xcache is superior of them all in terms of performance and reliability. And of course it is actively developed and upgraded. However there are others who disagree, but I will not get into fanboy arguments on this.
You can learn more about xcache from it’s website, but here is an excerpt:
“XCache is a open-source opcode cacher, which means that it accelerates the performance of PHP on servers. It optimizes performance by removing the compilation time of PHP scripts by caching the compiled state of PHP scripts into the shm (RAM) and uses the compiled version straight from the RAM. This will increase the rate of page generation time by up to 5 times as it also optimizes many other aspects of php scripts and reduce serverload.“
Installing from Repository
For Debian and Fedora based systems installing from a repository is a piece of cake.
Debian-based system: sudo apt-get install php5-xcache
Make sure you have php5-cli installed too, and to check if xcache is installed properly, type in php -v on the terminal.
In Fedora based system, yum install php-xcache should do the trick.
Installing from Source
1) First we will download the latest source to a folder, extract it and visit the extracted folder. You can get the latest release, 1.2.2 (as of this writing) from here: http://xcache.lighttpd.net/wiki/Release-1.2.2
2) Before you go ahead with compiling from the source, make sure you have php5-dev package is installed. In Debian that would be sudo apt-get install php5-dev, than on the terminal run phpize.
Enter the following commands as shown on the picture, here we are building xcache outside the source directory. You will see a long output (blurred out in the image).
Than type in “make”, will follow more long output. After that type in “sudo make install”
3) In this step we will modify php.ini (default location in /etc/, but it may vary, look it up with find).
Go to your source directory: cd ~/src/xcache-1.2.2, Login as root and than copy the content of xcache.ini to php.ini, cat xcache.ini >> /etc/php.ini
Restart apache, and you should be set up for good. Check php -v to make sure it’s running.
4) In the last step we will setup an admin page for debugging and administration purpose. You skip this part, if you want to, xcache is already installed. For this we will need an md5, I used this web utility for mine: http://www.adamek.biz/md5-generator.php. Ofcourse you can use whatever md5 generator you like. I created an md5 string for my log in name “pavs”.
We will have to edit php.ini to enter user and password manually, this is very easy. You need to be root for this. I use nano to edit my php.ini. nano /etc/php.ini
Save it. Copy “admin” folder from your xcache src to your webserver root folder. My case would be: cp -a /home/pavs/src/xcache-1.2.2/admin /var/www now browse to your admin page from browser and you should have an authorization prompt.
XCache configuration under php.ini is extensibly customizable, explaining every single element of the options will take couple of pages. It is a good idea to look at the official ini setting manual http://xcache.lighttpd.net/wiki/XcacheIni, to customize for the need of your server.
I hope you like this tutorial, if you do please share it with other, by Saving it on your del.icio.us, digging it and stumble it.
I will be working on some more advanced topics at the end of this month, when I get myself settled into regular blogging.