Integrating XCache Into PHP5 (OpenSUSE 10.3 & Apache2)

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Tue, 2008-04-08 11:43. :: SuSE | Apache | PHP

Integrating XCache Into PHP5 (OpenSUSE 10.3 & Apache2)

Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>
Last edited 03/27/2008

This guide explains how to integrate XCache into PHP5 on an OpenSUSE 10.3 system (with Apache2). From the XCache project page: "XCache is a fast, stable PHP opcode cacher that has been tested and is now running on production servers under high load." It's similar to other PHP opcode cachers, such as eAccelerator and APC.

I do not issue any guarantee that this will work for you!

 

1 Preliminary Note

I have tested this on an OpenSUSE 10.3 server with the IP address 192.168.0.100 where Apache2 and PHP5 are already installed and working. I'll use Apache's default document root /srv/www/htdocs in this tutorial for demonstration purposes. Of course, you can use any other vhost as well, but you might have to adjust the path to the info.php file that I'm using in this tutorial.

 

2 Checking PHP5's Current State

First, before we install XCache, let's find out about our PHP5 installation. To do this, we create the file info.php in our document root /srv/www/htdocs:

vi /srv/www/htdocs/info.php

<?php
phpinfo();
?>

Afterwards, we call that file in a browser: http://192.168.0.100/info.php

As you see, we have PHP 5.2.5 installed...

... but XCache isn't mentioned anywhere on the page:

 

3 Installing XCache

Unfortunately XCache isn't available as an rpm package for OpenSUSE 10.3, therefore we have to build it from the sources. First we install all packages that we need to build XCache:

yast2 -i gcc flex wget gcc-c++ make php5-devel

Next we download and uncompress the latest XCache version:

cd /tmp
wget http://xcache.lighttpd.net/pub/Releases/1.2.2/xcache-1.2.2.tar.gz
tar xvfz xcache-1.2.2.tar.gz

Then we go to the new XCache source directory...

cd xcache-1.2.2

... and build XCache as follows:

phpize
./configure --enable-xcache
make
make install

Next we copy xcache.ini to the /etc/php5/conf.d directory:

cp xcache.ini /etc/php5/conf.d

Now we must configure XCache. The configuration options are explained here: http://xcache.lighttpd.net/wiki/XcacheIni. The least you should do is enable extension = xcache.so and disable all zend_extension lines; furthermore, set xcache.size to a size (in MB) > 0 to enable XCache:

vi /etc/php5/conf.d/xcache.ini

[xcache-common]
;; install as zend extension (recommended), normally "$extension_dir/xcache.so"
;zend_extension = /usr/local/lib/php/extensions/non-debug-non-zts-xxx/xcache.so
; zend_extension_ts = /usr/local/lib/php/extensions/non-debug-zts-xxx/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.size  =                32M
[...]

That's it. Restart Apache, and you're done:

/etc/init.d/apache2 restart

Afterwards, open info.php again in a browser: http://192.168.0.100/info.php

You should now see XCache mentioned on the page which means it has successfully been integrated and is working as expected:

 

4 Links


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by RoyBellingan (registered user) on Fri, 2008-05-16 20:36.

Grazie (italian for  tank you), but you forget to move also xcache.so into /usr/lib/php5/extensions

just type

cp modules/xcache.so /usr/lib/php5/extensions

Bye
Submitted by stephen.knight (registered user) on Sun, 2008-04-13 22:28.

Hi,

 I was just reading your very helpful article on integrating Xcache into PHP5, great job. I would just like to point out however that you can get the RPM for it from the opensuse build service. (I use the site almost daily)

Later