You are here: Home / Debian GNU/Linux / Servers / PHP / Install the XCache PHP extension on Debian

Install the XCache PHP extension on Debian

by Pierre-Yves Landuré last modified Nov 11, 2017 09:30

XCache is a op-code cache speeding up PHP code execution. It is a good alternative to APC. This guide helps to install it on Debian GNU/Linux.

This how-to is tested on:

  • Debian 6.0 Squeeze
  • Debian 7.0 Wheezy
  • Ubuntu 10.04 Lucid Lynx
  • Ubuntu 10.10 Maverick Meercat
  • Ubuntu 11.04 Natty Narwal

Warning

This post is incompatible with these how-to:

Prerequisites

This how-to needs :

Installation from Debian repository

Install the software:

command apt-get -y install php5-xdebug

Reload the configuration:

test -e '/etc/init.d/php5-fpm' && command service 'php5-fpm' 'restart'
test -e '/etc/init.d/apache2' && command service 'apache2' 'force-reload'

Configuration

Detect PHP extension configuration path:

MODS_CONF_PATH='/etc/php5/conf.d'
test -d '/etc/php5/mods-available' \
  && MODS_CONF_PATH='/etc/php5/mods-available'

Set up the quantity of memory available for the cache:

echo "; Local configuration for php XCache module
; priority=50
xcache.size = 60M
xcache.var_size = 4M" \
> "${MODS_CONF_PATH}/xcache-config.ini"
test -n "$(command -v php5enmod)" && command php5enmod 'xcache-config/50'

To use XCache with the Symfony framework 1.0, disable the admin authentication in order to enable the Symfony code to use the xcache_count function (dangerous):

# command echo -e "; Disable cache admin auth for Symfony 1.0\nxcache.admin.enable_auth = Off" >> "${MODS_CONF_PATH}/xcache-config.ini"

Reload the configuration:

test -e '/etc/init.d/php5-fpm' && command service 'php5-fpm' 'restart'
test -e '/etc/init.d/apache2' && command service 'apache2' 'force-reload'

Manual installation

If the Debian package is not available, install the extension manually.

Detect PHP extension configuration path:

MODS_CONF_PATH='/etc/php5/conf.d'
test -d '/etc/php5/mods-available' \
  && MODS_CONF_PATH='/etc/php5/mods-available'

Detect the extension lastest version number:

VERSION=$(command wget 'http://xcache.lighttpd.net/pub/Releases/' \
--quiet  --output-document=- \
| command grep "href=" \
| command egrep -v "(-rc|-beta)" \
| command sed -e 's|^.*href="\([^/]*\)/".*$|\1|' \
| command sort \
| command tail -n 1)

Environment preparation

Install needed software:

command apt-get install php5-dev make

Software installation

Download the sources:

command wget "http://xcache.lighttpd.net/pub/Releases/${VERSION}/xcache-${VERSION}.tar.gz" \
--output-document="/tmp/xcache-${VERSION}.tar.gz"

Extract the archive:

command tar --directory='/tmp' -xzf "/tmp/xcache-${VERSION}.tar.gz"

Build and install the extension:

command pushd "/tmp/xcache-${VERSION}"
command phpize --clean
command phpize
./configure --enable-xcache
command make
command make install
command popd

Enable the extension:

echo "; configuration for php XCache module
; priority=20
extension=xcache.so" > "${MODS_CONF_PATH}/xcache.ini"
test -n "$(command -v php5enmod)" && command php5enmod 'xcache'

Reload the configuration:

test -e '/etc/init.d/php5-fpm' && command service 'php5-fpm' 'restart'
test -e '/etc/init.d/apache2' && command service 'apache2' 'force-reload'

You can now configure XCache.

Thanks