Install XCache PHP Accelerator in Linux by Compiling from Source
XCache is an alternative yet fast and stable PHP accelerator and opcode cacher that is similar to the famous eAccelerator and APC (Alternative PHP Cache). XCache extension works by caching the compiled bytecode (opcode or intermediate code) form of PHP scripts to avoid the overhead to parse and compile PHP source code on every page request, and thus reduces server loads, boosts the performance of PHP scripts and increases the speed of PHP code from 2-10 times.
XCache supports all of the latest PHP cvs branches such as PHP 4.3, PHP 4.4, PHP 5.1 and PHP 5.2 on Linux server including CentOS which common used on cPanel and Plesk based web hosting server, and ThreadSafe/Windows web server. XCache overcomes a lot of problems that exist on opcachers or accelerators such as unable to work with new PHP versions. Beside, XCache also been benchmarked to be faster than other opcode cachers.
This is a simple tutorial and guide on how to install XCache PHP cacher by manually compiling from source code package. If you’re using Wordpress or using XCache to speed up and improve Wordpress blog performance, you should first ensure that PHP is upgraded to latest version (PHP 5.2.1), as PHP 4 may cause some instability issue such as unable to post comment, partial page loading and etc. Anyway, PHP5 is always recommended if possible. And as with all PHP accelerator, XCache won’t work with PHP suEXEC turns on. PHP suEXEC must be disabled for XCache to work properly.
Currently, XCache maintains 2 branches, i.e. version 1.0.3 and version 1.2.0. Both version is now stable release, with version 1.0.x recommended for PHP 4.3.x and 4.4.x, and version 1.2.x recommended for most version of PHP including 5.1.x and 5.2.x, except PHP 5.0.x series. If you’re using PHP4, try both version of XCache to pick the one most suitable for your application. To check which version of PHP you’re usinng, issue command php -v or setup a PHP file with the following content, then call the file from web browser:
<?php
phpinfo();
?>
- Change to user local source directory such as /usr/local/src by using following command:
cd /usr/local/src
- Retrieve and download the source package of the version of XCache you choose to install.
wget http://210.51.190.228/pub/XCache/Releases/xcache-1.0.3.tar.gz (for XCache 1.0.3)
or
wget http://210.51.190.228/pub/XCache/Releases/xcache-1.2.0.tar.gz (for XCache 1.2.0)
- Untar, unzip, unpack or extract the archive with one of the following commands:
tar -zxf xcache-*.tar.gz
gzip -dc xcache-*.tar.gz | tar -x - Go into the xcache directory with source content:
cd xcache
- Trigger PHP building environment:
phpize
- Optional but recommended practice is to build XCache outside of source directory:
mkdir ../xcache-build
cd ../xcache-build - Run the configure with the option that you want, the basic is as below which will enable the XCache by default:
../xcache/configure –enable-xcache
You can list out all available options by using ../xcache/configure –help command, which will display the following:
–enable-xcache Include XCACHE support.
–enable-xcache-optimizer XCACHE: (N/A)
–enable-xcache-coverager XCACHE: Enable code coverage dumper
–enable-xcache-assembler XCACHE: (N/A)
–enable-xcache-disassembler XCACHE: Enable opcode to php variable dumper
–enable-xcache-encoder XCACHE: (N/A)
–enable-xcache-decoder XCACHE: (N/A)
–enable-xcache-test XCACHE: Enable self test – FOR DEVELOPERS ONLY!! - Compile the source with following command:
make
Ensure that no error occurred.
- If you haven’t already using root account, su to root user.
- Install XCache binary with the following command:
make install
Ensure that no error occurred, and note down the extension installation path of the xcache.so.
- Next, XCache need to be configured and enabled in PHP.INI file. Locate the correct location of php.ini configuration file by using phpinfo() function (see sample listed above to check version of PHP). In web hosting environment, normally it’s located in /etc or /usr/local/lib. If the install of PHP parses the /etc/php.d/ folder, then simply create a file in that folder named “xcache.ini” or copy over the sample xcache.ini came with source package.
Change back to xcache source unpack directory, and run the following command with root user:
cat xcache.ini >> /etc/php.ini
$EDITOR /etc/php.iniNote: change to the path of php.ini accordingly
This will append the default XCache configuration to the end of php.ini. Alternatively, you can copy and paste the following text into the php.ini file yourself too:
[xcache-common]
;; install as zend extension (recommended)
zend_extension = /usr/local/lib/php/extensions/no-debug-non-zts-xxx/xcache.so
;; install as zend extension with thread-safe
; zend_extension_ts = /usr/local/lib/php/extensions/non-debug-zts-xxx/xcache.so
;; install as PHP extension (extension_dir must be set to the full path to xcache.so)
; extension = xcache.so[xcache.admin]
xcache.admin.user = "admin"
xcache.admin.pass = md5($your_password)[xcache]
xcache.shm_scheme = "mmap"
xcache.size = 16M
xcache.count = 1
xcache.slots = 8K
xcache.ttl = 0
xcache.gc_interval = 0xcache.var_size = 0M
xcache.var_count = 1
xcache.var_slots = 8K
xcache.var_ttl = 0
xcache.var_maxttl = 0
xcache.var_gc_interval = 300xcache.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 = ""
- You can configure XCache to your preference. One setting that must be changed is under the [xcache-common], where you must specify the correct installation path of the XCache extension module. You can also opt to run XCache as PHP extension instead of extension for Zend module. In this case, comment and uncomment the line accordingly. Other important options include “xcache.size” which specify amount the memory allocated to XCache, “xcache.count” to take advantage of multi-core processors or multiple processors. And if you plan to use XCache web administration interface, input the “xcache.admin.user” and md5 checksum value of “xcache.admin.pass”. Try MD5 tools to generate the correct value, or use the following command to generate the MD5 for your password:
echo -n “password” | md5sum
Note: Explanation and definition of all XCache INI settings can be found here.
- Restart the Apache httpd web server. The following commands should work:
/etc/init.d/apache* restart
or
/etc/init.d/httpd* restart
- Ensure the XCache is running by calling PHP file with phpinfo() (see sample above). You should see a new XCache Support block with opcode cache enabled.
- If you wish to set up XCache administration page, configure an alias in httpd.conf of Apache to point to the admin subdirectory within XCache. To do so, add the following line to httpd.conf (assuming your xcache source is extracted at /usr/local/src/, and you want to access admin page from /xcache-admin/ URL):
Alias /xcache-admin/ /usr/local/src/xcache/admin/
Then restart Apache web server. For lighttpd, add the following line instead:
alias.url += (”/xcache-admin/” => “/usr/share/xcache/admin/”)
Alternatively, you can also copy the whole “admin” directory from the “xcache” source folder to web document-root or sub-directory of your domain which is web accessible. However, this method is not recommended as you may forget to update the admin page when XCache package is updated.
Note: Ensure that open_basedir protection, if enabled, is excluded for the directory contains admin-page.
Related Articles
- Proper Way to Generate MD5 Hash for XCache Administration Password with md5sum or PHP
- Get Ready for Linux Genuine Advantage (LGA) – with Source and Crack
- Run WordPress at Top Fast Speed by Putting Objects and Variables into XCache or eAccelerator Cache Memory (Plugin)
- Open, Extract and Convert DAA, ISO and BIN Files in Linux with Free PowerISO for Linux
- How to Make or Create Symbolic Link in Unix or Linux
- Windows Vista Security Guide Reviewed by NSA and NIST with Solution Accelerator
- Refresh Linux or Unix Path Environmental Variables with rehash
- Install phpBB 2 in Windows XP running on Apache 2, PHP 5 and MySQL 4
- How to Calculate and Generate MD5 Hash Value in Linux and Unix with md5sum
- Preview C#, Visual Basic, and C++ Source Code files Direct in Attachments Without Opening









































