Whether you're pressed for resources on a virtual/dedicated server, or simply looking for ways to improve web application performance, XCache is guaranteed to produce the desired result. Within minutes of installing XCache: page load times were cut in half, PHP/MySQL RAM consumption was under control, and overall PHP rendering/output performance dramatically improved. In this post I'll go over the process of installing, configuring, and enabling XCache in a php5-cgi+Lighttpd chroot jail on a Debian Lenny web server.
What is XCache?
Hopefully you're already aware, but just in case... :
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 under Windows, for thread-safe and non-thread-safe versions of PHP. This relatively new opcode caching software has been developed by mOo, one of developers of Lighttpd, to overcome some of the limitations of the existing solutions at that time; such as being able to use it with new PHP versions as they arrive.
Assumptions / Conditions
This tutorial assumes Lighttpd (>= 1.4.23-3+b2) is already setup and running in a chroot environment with php5/fastcgi enabled and working. Also assumes a minimum of 64 megabytes of RAM is available. If you're looking for a Lighttpd chroot setup guide, I highly recommend this one.
Install XCache
Login to your Debian server and obtain root (sudo, su, whatever) and run the following:
[184][vps ~]:# aptitude install php5-xcache
Put XCache in the Lighttpd chroot:
[185][vps ~]:# cp -avr /usr/share/xcache /chroot/usr/share/ [186][vps ~]:# cp -avr /usr/lib/php5/20060613+lfs/xcache.so /chroot/usr/lib/php5/20060613+lfs/ [187][vps ~]:# l2chroot /usr/lib/php5/20060613+lfs/xcache.so [188][vps ~]:# cat /etc/php5/conf.d/xcache.ini > /chroot/etc/php5/conf.d/xcache.ini [189][vps ~]:# vi /etc/lighttpd/lighttpd.conf
Create an alias to access the XCache Administration pages:
$HTTP["host"] =~ "some-domain.tld" {
alias.url = ( "/xcache-admin/" => "/usr/share/xcache/admin/" )
}
Save changes to lighttpd.conf and quit (:wq!). See this page for the l2chroot script.
Setup XCache
Generate a password using the "md5sum" command and create/edit xcache.ini settings file.
[190][vps ~]:# echo -n "your_desired_password" | md5sum c889e0b89df36eaa47f3a71675d1e9f4 [191][vps ~]:# vi /chroot/etc/php5/conf.d/xcache.ini
The following settings work for my purposes. You may need to consult the XCache docs and adjust according to your environment. Plenty of information out there - use the goog.
[xcache-common] extension = xcache.so [xcache.admin] xcache.admin.enable_auth = On xcache.admin.user = "xcadmin" xcache.admin.pass = "c889e0b89df36eaa47f3a71675d1e9f4" [xcache] xcache.shm_scheme = "mmap" xcache.size = 96M xcache.count = 8 xcache.slots = 8K xcache.ttl = 0 xcache.gc_interval = 0 xcache.var_size = 16M xcache.var_count = 1 xcache.var_slots = 8K xcache.var_ttl = 0 xcache.var_maxttl = 0 xcache.var_gc_interval = 300 xcache.test = Off xcache.readonly_protection = Off xcache.mmap_path = "/dev/zero" xcache.coredump_directory = "" xcache.cacher = On xcache.stat = On xcache.optimizer = Off [xcache.coverager] xcache.coverager = Off xcache.coveragedump_directory = ""
Finalize & Test
If a /chroot/dev/zero special device doesn't exist, go ahead and create one, now. Finally, restart Lighttpd and visit the XCache Administration page (the alias created above).
[192][vps ~]:# mknod /chroot/dev/zero c 3 4 [193][vps ~]:# /etc/inti.d/lighttpd restart
A page resembling the screen-shot below should appear after logging in (click for full-size).
The Lighttpd wiki suggests setting 1 "max-procs" and several "PHP_FCGI_CHILDREN" in 10-fastcgi.conf. For some reason that particular setup only lasts 20 to 30 minutes before crashing. Here's the setup used at the time the screen-shot above was taken which happens to work for me (so-far).
server.modules += ( "mod_fastcgi" ) fastcgi.server = ( ".php" => (( "bin-path" => "/usr/bin/php5-cgi", "socket" => "/var/tmp/lighttpd/php5-cgi.socket", "max-procs" => 2, "idle-timeout" => 20, "bin-environment" => ( "PHP_FCGI_CHILDREN" => "5", "PHP_FCGI_MAX_REQUESTS" => "5000" ), "bin-copy-environment" => ( "PATH", "SHELL", "USER" ), "broken-scriptfilename" => "enable" )) )
Result is 2 parent php5-cgi processes with 5 children each:
/usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf \_ /usr/bin/php5-cgi \_ /usr/bin/php5-cgi \_ /usr/bin/php5-cgi \_ /usr/bin/php5-cgi \_ /usr/bin/php5-cgi \_ /usr/bin/php5-cgi \_ /usr/bin/php5-cgi \_ /usr/bin/php5-cgi \_ /usr/bin/php5-cgi \_ /usr/bin/php5-cgi \_ /usr/bin/php5-cgi \_ /usr/bin/php5-cgi
Enjoy! Comments are open...
Word Count: 904
Tags: chroot, Debian, howto, http, Httpd, Lighttpd, Linux, php




1 Comment
[ RSS feed | Trackback URI | Leave a Comment ]
Xcache is definetely worth instaling because it is very good for improving web aplication performance. The page load time is cut into half and it is usefull if you are a very busy person
Leave a Comment
Trackback Responses to This Post: