Friday, May 25, 2012

FreeBSD: Install PHP xcache Opcode Cacher

Q. How do I install and configure xcache under FreeBSD operating systems for Apache, lighttpd or ngnix web server?

A. XCache is a fast, stable php opcode cacher that has been tested and now running on production server under high load.

FreeBSD install xcache

xcache can be installed using FreeBSD ports system or pkg_add command itself. First, update ports tree:
# portsnap fetch update
Install xcache, enter:
# cd /usr/ports/www/xcache
# make install clean

Enable xache

To enable xcahce copy the /usr/local/share/examples/xcache/xcache.ini config file into /usr/local/etc/php/ and modify it to suit your needs, enter:
# cp /usr/local/share/examples/xcache/xcache.ini /usr/local/etc/php/
# cd /usr/local/etc/php/
# vi xcache.ini

Set xcache.size and other parameters as per your requirements. Here is my sample xcache for FreeBSD 7 with quad core CPU and 4GiG RAM:
[xcache-common]
extension = xcache.so
 
[xcache.admin]
xcache.admin.enable_auth = On
xcache.admin.user = "admin"
; xcache.admin.pass = md5($your_password)
xcache.admin.pass = ""
 
[xcache]
; ini only settings, all the values here is default unless explained
 
; select low level shm/allocator scheme implemenation
xcache.shm_scheme = "mmap"
; to disable: xcache.size=0
; to enable : xcache.size=64M etc (any size > 0) and your system mmap allows
xcache.size = 512M
; set to cpu count (cat /proc/cpuinfo |grep -c processor)
xcache.count = 4
; just a hash hints, you can always store count(items) > slots
xcache.slots = 8K
; ttl of the cache item, 0=forever
xcache.ttl = 0
; interval of gc scanning expired items, 0=no scan, other values is in seconds
xcache.gc_interval = 0
 
; same as aboves but for variable cache
xcache.var_size = 128M
xcache.var_count = 1
xcache.var_slots = 8K
; default ttl
xcache.var_ttl = 0
xcache.var_maxttl = 0
xcache.var_gc_interval = 300
 
xcache.test = Off
; N/A for /dev/zero
xcache.readonly_protection = Off
; for *nix, xcache.mmap_path is a file path, not directory.
; Use something like "/tmp/xcache" if you want to turn on ReadonlyProtection
; 2 group of php won't share the same /tmp/xcache
; for win32, xcache.mmap_path=anonymous map name, not file path
xcache.mmap_path = "/dev/zero"
 
; leave it blank(disabled) or "/tmp/phpcore/"
; make sure it's writable by php (without checking open_basedir)
xcache.coredump_directory = ""
 
; per request settings
xcache.cacher = On
xcache.stat = On
xcache.optimizer = Off
 
[xcache.coverager]
; per request settings
; enable coverage data collecting for xcache.coveragedump_directory and xcache_coverager_start/stop/get/clean() functions (will hurt executing performance)
xcache.coverager = Off
 
; ini only settings
; make sure it's readable (care open_basedir) by coverage viewer script
; requires xcache.coverager=On
xcache.coveragedump_directory = ""

Restart web server

Type the following command to restart apache22:
# /usr/local/etc/rc.d/apache22 restart
If you are using nginx web server, enter:
# /usr/local/etc/rc.d/nginx restart
If you are using lighttpd web server, enter:
# /usr/local/etc/rc.d/lighttpd restart

No comments:

Post a Comment