Installing PHP XCache on CentOS 5

XCache is a PHP opcode cacher, which basically means that it will cache the compiled code the first time a PHP page/script is executed thus avoiding the compilation step on subsequent executions.

I used the 1.2.2. release of XCache and followed the quick guide instructions to install from source.

The installation requires that the php-devel package is installed. This is required to compile PHP extensions (the comand phpize is required for this installation).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[root@testserver xcache-1.2.2]# yum install php-devel
Dependencies Resolved
=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 php-devel               i386       5.1.6-20.el5_2.1  updates           512 k
Updating for dependencies:
 php                     i386       5.1.6-20.el5_2.1  updates           1.1 M
 php-cli                 i386       5.1.6-20.el5_2.1  updates           2.1 M
 php-common              i386       5.1.6-20.el5_2.1  updates           154 k
 php-gd                  i386       5.1.6-20.el5_2.1  updates           113 k
 php-ldap                i386       5.1.6-20.el5_2.1  updates            35 k
 php-mbstring            i386       5.1.6-20.el5_2.1  updates           969 k
 php-mysql               i386       5.1.6-20.el5_2.1  updates            84 k
 php-pdo                 i386       5.1.6-20.el5_2.1  updates            62 k
 php-xml                 i386       5.1.6-20.el5_2.1  updates            94 k
Transaction Summary
=============================================================================
Install      1 Package(s)
Update       9 Package(s)
Remove       0 Package(s)
Total download size: 5.2 M
Is this ok [y/N]:

It appears that this will also update the core PHP package and dependancies, so care should be taken. Try this on a test server and not your production server!

Here are the steps I took to install XCache:

1
2
3
4
5
6
7
8
[root@testserver ~]# tar -zxf xcache-1.2.2.tar.gz
[root@testserver ~]# cd xcache-1.2.2
[root@testserver xcache-1.2.2]# phpize
[root@testserver xcache-1.2.2]# ./configure --enable-xcache
[root@testserver xcache-1.2.2]# make
[root@testserver xcache-1.2.2]# make install
[root@testserver xcache-1.2.2]# cp /etc/php.ini /etc/php.ini.bk
[root@testserver xcache-1.2.2]# cat xcache.ini >> /etc/php.ini

In my configuration the xcache.ini and resulting php.ini had the wrong path to the module that has been installed. The module was installed in /usr/lib/php/modules/ but the configuration was looking in /usr/local/lib/php/extensions/non-debug-non-zts-xxx/.

All that was needed was a simple change to the configuration file to comment out the fully qualified path and tell it to use the extensions directory:

1
2
3
4
5
6
7
8
9
10
[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

Then just check it’s installed:

1
2
3
4
5
[root@testserver xcache-1.2.2]# php -v
PHP 5.1.6 (cli) (built: Jul 16 2008 19:53:00)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
    with XCache v1.2.2, Copyright (c) 2005-2007, by mOo

Success! However Apache must be restarted in order for this to work with PHP web pages.

1
service httpd restart

Now if you access a page containing the phpinfo(); function you should be able to search for XCache and find it.

XCache is now installed and running.

I did not see the need to install the php-devel package on our live servers and I know that our live servers are identical to our test servers other than hard disk and memory sizes (we use VMWare extensively and they come from the same template).

This means that all the binaries compiled on the test server should be compatible with our live servers, so I just copied the xcache-1.2.2 folder from the test server and followed the above steps again starting with the “make install” step.

1
[root@testserver ~]# tar -cvzf xcache-install.tgz xcache-1.2.2/

copy this to the /root/ directory on the live server

1
2
3
4
5
6
7
8
9
10
[root@liveserver ~]# tar -xvzf xcache-install.tgz
[root@liveserver xcache-1.2.2]# make install
[root@liveserver xcache-1.2.2]# cp /etc/php.ini /etc/php.ini.bk
[root@liveserver xcache-1.2.2]# cat xcache.ini >> /etc/php.ini
[root@liveserver xcache-1.2.2]# vi /etc/php.ini
[root@liveserver xcache-1.2.2]# php -v
PHP 5.1.6 (cli) (built: Sep 20 2007 10:16:10)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
    with XCache v1.2.2, Copyright (c) 2005-2007, by mOo

Leave a Reply

Your email address will not be published. Required fields are marked *