Install XCache to Accelerate and Optimize PHP Performance

In most cases PHP performance can slow down the performance of websites. To optimize and accelerate website performance you need to improve the PHP performance. For this purpose, you can use opcode cachers such as eAccelerator, APC, Memcached, XCache, etc. Personally, my favourite choice is XCache.

XCache is a free, open source operation code cacher, it is designed to enhance the performance of PHP scripts execution on servers. It optimizes the performance by eliminating the compilation time of PHP code by caching the compiled version of code into the memory and this way the compiled version loads the PHP script directly from the memory. This will surety accelerate the page generation time by up to 5 times faster and also optimizes and increases many other aspects of php scripts and reduce website/server load.

May not be 5 times faster, but it will definite improves the standard PHP installation with the opcode XCaher. This article explains how to setup and integrate XCache into PHP installation on a RHEL, CentOS, Fedora and Ubuntu, Linux Mint and Debian systems.

Step 1: Installation of XCache for PHP

Users who running an Red Hat based distributions, can able to install XCache through a package manager by enabling epel repository. Once you’ve enabled epel repository, you can use the following yum command to install it.

RHEL/CentOS/Fedora
# yum install php-xcache xcache-admin

By default, XCache is available for Debian based distributions from the package manager. Therefore, you can install the XCache package by using the following apt-get command.

Debian/Ubuntu/Linux Mint
# apt-get install php5-xcache

Step 2: Configuring of XCache for PHP

The XCache.ini configuration file has couple of settings that I do recommend you to understand as they are vital to use in this plugin. The detailed information of XCache configuration settings can be found at XcacheIni. If you don’t want to change any settings, you can use default settings as they are good enough to use with XCache.

RHEL/CentOS/Fedora
# vi /etc/php.d/xcache.ini
Debian/Ubuntu/Linux Mint
# vi /etc/php5/conf.d/xcache.ini
OR
# vi /etc/php5/mods-available/xcache.ini

Step 3: Restarting Apache for XCache

Once you’re done with configuration settings, restart your Apache web server.

# /etc/init.d/httpd restart
# /etc/init.d/apache2 restart

Step 4: Verifying XCache for PHP

Once you’ve restarted web service, type the following command to verify XCache. You should see the XCache lines as shown below.

# php -v
Sample Output
PHP 5.3.3 (cli) (built: Jul  3 2012 16:40:30)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with XCache v3.0.1, Copyright (c) 2005-2013, by mOo
    with XCache Optimizer v3.0.1, Copyright (c) 2005-2013, by mOo
    with XCache Cacher v3.0.1, Copyright (c) 2005-2013, by mOo
    with XCache Coverager v3.0.1, Copyright (c) 2005-2013, by mOo

Alternatively, you can verify XCache by creating a ‘phpinfo.php‘ file under your document root directory (i.e. /var/www/html or /var/www).

vi /var/www/phpinfo.php

Next, add the following php lines to it and save the file.

<?php
phpinfo();
?>

Open a web browser and call the file like “http://your-ip-address/phpinfo.php“. You will see the following output screen shot.

Install XCache for PHP

XCache Info

Step 5: Enabling XCache Admin Panel for PHP

By default the admin panel is protected with http-auth and in disabled state, if you’ve not set a password. To set user/password open the Xcache.ini file. But, first you have to create md5 password using following command.

# echo -n "typeyourpassword" | md5sum
Sample Output
e10adc3949ba59abbe56e057f20f883e

Now open Xcache.ini file add the generated md5 password. See the following example, add your own password md5 string.

[xcache.admin]
xcache.admin.enable_auth = On
; Configure this to use admin pages
 xcache.admin.user = "mOo"
; xcache.admin.pass = md5($your_password)
 xcache.admin.pass = "e10adc3949ba59abbe56e057f20f883e"

The simplest way to do so is copying the whole directory xcache (admin was in older release) to your web root directory (i.e. /var/www/html or /var/www).

# cp -a /usr/share/xcache/ /var/www/html/
OR
# cp -a /usr/share/xcache/htdocs /var/www/xcache
OR
cp -a /usr/share/xcache/admin/ /var/www/ (older release)

Now call it from your browser, a http-auth login prompt window will pop-up. Enter your user/pass in, and it’s done.

http://localhost/xcache
OR
http://localhost/admin (older release)
XCache 3.0 Newer Version
XCache 3.0 Admin Panel

XCache 3.0 Admin Panel

XCache 2.0 Older Version
Install xcache admin

XCache Admin Panel

Reference Links

XCache Homepage

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Ravi Saive

I am Ravi Saive, creator of TecMint. A Computer Geek and Linux Guru who loves to share tricks and tips on Internet. Most Of My Servers runs on Open Source Platform called Linux. Follow Me: Twitter, Facebook and Google+

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

35 Responses

  1. reza says:

    hi

    i already installed xcache with litespeed web server.
    but after 1 or 2 weeks , i see the wordpress sites give 500 internal server error.
    so i unistalled that :( .

  2. shamrat says:

    hi, I am using centos 5.6 with pleask 12 which has multiple version of php. above tutorial places the xcache with php 5.3 but how to put it on php 5.6 running as one more version on plesk. thanks in advanced.

  3. shafira says:

    Hi, thanks for this tutorial, i was install it on my LEMP server on centos 6 and i was configuration like this tutorial for access xcache admin panel but when every time iam login, the login box still appear,,, i was restart my nginx and php-fpm but still not work.

    • Ravi Saive says:

      @shafira,
      Have you checked logs for any errors..and also have you generated and added correct md5 password to Xcache.ini file?

Got something to say? Join the discussion.

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.