Sunday, April 27, 2008

Install Xcache for PHP5

XCache is a open-source opcode cacher, it accelerates/optimizes the performance of PHP on servers by removing the compilation time of PHP scripts by caching the compiled state of PHP scripts into the shm (RAM) and uses the compiled version straight from the RAM. This will increase the rate of page generation time by up to 5 times as it also optimizes many other aspects of php scripts and reduce serverload.

# Download latest stable release:
# wget http://xcache.lighttpd.net/pub/Releases/1.2.1/xcache-1.2.1.tar.gz

# Compile and install. Use phpize to prepare xcache as a PHP extension for compiling:
# phpize
# ./configure --enable-xcache
# make
# make install

# Default xcache.so install location

  • 64 bit PHP module installed at /usr/lib64/php/modules/xcache.so
  • 32 bit PHP module installed at /usr/lib/php/modules/xcache.so

# Create xcache.ini

Under RHEL / CentOS, php modules configuration are stored at /etc/php.d/:
# cd /etc/php.d/
# vi xcahce.ini #Append configuration directives:

[xcache-common]
; change me - 64 bit php => /usr/lib64/php/modules/xcache.so
; 32 bit php => /usr/lib/php/modules/xcache.so
zend_extension = /usr/lib64/php/modules/xcache.so

[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 = 32M
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 = 0M
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

Alternatively, you can also copy default xcache.ini to /etc/php.d/
# cp xcache.ini /etc/php.d/
# vi /etc/php.d/xcache.ini

# service httpd restart
# service lighttpd restart

# Make sure xcache is working

$ php -v

You should see line "XCache v1.2.1, Copyright (c) 2005-2007, by mOo"

No comments: