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
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
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.2.2, Copyright (c) 2005-2007, by mOo
php -v
PHP 5.2.6 (cli) (built: Oct 12 2008 03:54:55) 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 with Zend Extension Manager v1.2.2, Copyright (c) 2003-2007, by Zend Technologies with Suhosin v0.9.27, Copyright (c) 2007, by SektionEins GmbH with Zend Optimizer v3.3.3, Copyright (c) 1998-2007, by Zend Technologies
This tutorial is based on -> Redhat / CentOS / Fedora Linux Install XCache for PHP 5 Update (Aug 24, 09): XCache 1.3.0 can use the same steps. Also, configuration file is updated to match the one got from XCache 1.3.0 - "xcache.size = 60M" vs "xcache.size = 32M" - "xcache.var_size = 4M" vs "xcache.var_size = 0M"
========================================
Update (Jan 28, 2010) : XCache 1.3.0 with PHP 5.3.1. There is mainly a change on Directory. ========================================
Step 1 : Get XCache and uncompress it
cd /tmp wget http://xcache.lighttpd.net/pub/Releases/1.3.0/xcache-1.3.0.tar.gz tar -xvf xcache-1.3.0.tar.gz
Step 2 : Use phpize command to prepare xcache as a PHP extension for compiling:
cd xcache-1.3.0 phpize
Configuring for: PHP Api Version: 20090626 Zend Module Api No: 20090626 Zend Extension Api No: 220090626
Step 3 : Configure, compile and install XCache
./configure --enable-xcache make make install
Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20090626/
Notice that the location of file extension is : /usr/local/lib/php/extensions/no-debug-non-zts-20090626/ 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-20090626/xcache.so zend_extension_ts = /usr/local/lib/php/extensions/no-debug-non-zts-20090626/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
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
========================================
Note (Jul 2, 2011) : 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
========================================
Note (Nov 5, 2012) : Compile XCache with DirectAdmin + Custombuild 2.0
========================================
In Custombuild 2.0, the extension path has change to /usr/local/php53/lib/php/extensions/no-debug-non-zts-20090626/ for PHP 5.3.x. To compile XCache, you can do the following : (Tested with XCache 3.0.0)
cd xcache-3.0.0 /usr/local/php53/bin/phpize53 ./configure --enable-xcache --with-php-config=/usr/local/php53/bin/php-config53 make make install
With PHP 5.4, the extension path is /usr/local/php54/lib/php/extensions/no-debug-non-zts-20100525/ The steps to compile it is below :
cd xcache-3.0.0 /usr/local/php54/bin/phpize54 ./configure --enable-xcache --with-php-config=/usr/local/php54/bin/php-config54 make make install
you are a hero!
Thank You
xcache.var_size
Just checked configuration