(ve):Configure XCache with php5 and lighttpd
- This page was last modified on December 16, 2010, at 11:09.
From (mt) Community Wiki
Contents |
"XCache is a fast, stable PHP opcode cacher that has been tested and is now running on production servers under high load. It is tested (on linux) and supported on all of the latest PHP cvs branches such as PHP_4_3 PHP_4_4 PHP_5_0 PHP_5_1 PHP_5_2 HEAD(6.x). ThreadSafe/Windows is also supported. It overcomes a lot of problems that has been with other competing opcachers such as being able to be used with new PHP versions."
Notice: This article is targeted at Debian 5.0 distro, you may need to adapt a few things to suite your choice of OS.
Requirements
In order to install XCache your first going to need a working installation of the Lighttpd web server and php5, You can follow this guide for setting up Lighttpd and for php5 its just a matter of installing packages and adding an fcgi config to lighttpd, doc on that here.
Installation
First off install XCache by running the following:
apt-get install php5-xcache
Now the problem is by default xcache will try to access the swap which wont work on the (ve) and you will see an error like this:
php-cgi -v /dev/zero: No space left on device Failed creating file mappping PHP Fatal error: Failed creating file mappping in Unknown on line 0 PHP Fatal error: XCache: Cannot create shm in Unknown on line 0 PHP 5.2.6-3ubuntu4.1 with Suhosin-Patch 0.9.6.2 (cgi-fcgi) (built: Apr 23 2009 14:30:49) Copyright (c) 1997-2008 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies with XCache v1.2.2, Copyright (c) 2005-2007, by mOo Segmentation fault
To correct this open up the xcache config file and make the following changes:
nano /etc/php5/conf.d/xcache.ini Find: xcache.mmap_path = "" Replace with: xcache.mmap_path = "/tmp/xcache"
Now stop Lighttpd:
/etc/init.d/lighttpd stop
Kill off the remaining fcgi interface(simply restarting lighttpd is not enough in some cases):
pidof php5-cgi kill xxx xxx xxx xxx
Now restart Lighttpd:
/etc/init.d/lighttpd start
If all is well create or locate a file with the phpinfo() function and check that the xcache extension is loaded. Thats it.
Additional Configuration
By default there is a limited amount of memory alocated for xcache. Adding more will allow XCache to cache larger scripts(including images generated with GD) and we will also cover how to take full advantage of the (ve)'s CPU.
First open the xcache config:
nano /etc/php5/conf.d/xcache.ini
Now locate the variable called xcache.size, increase the value to "64M" or higher(less then half your total ram for safety) and then change the var xcache.count to 16. What this dose is spreads the total space we allocate over all 16 cores available to the (ve) server, this allows a more evenly balanced load and faster access time.
Now save and exit nano and restart Lighttpd:
/etc/init.d/lighttpd restart