Did You Know?
Donate to TecMint

We are pleased to announce our new TecMint Q/A section to submit your Linux questions

Install XCache to Accelerate and Optimize PHP Performance

Download Your Free eBooks NOW - 10 Free Linux eBooks for Administrators

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

Ravi Saive

Owner at TecMint.com
Simple Word 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.

Linux Services & Free WordPress Setup

Our post is simply ‘DIY’ aka ‘Do It Yourself, still you may find difficulties and want us to help you out. We offer wide range of Linux and Web Hosting Solutions at fair minimum rates. Please submit your orders by Clicking Here.

22 Responses

  1. kashyap says:

    I am getting below error :
    Error: php-xcache conflicts with php-pecl-apc-3.1.9-2.el6.x86_64
    plz help

  2. Vladimir says:

    Does this automaticaly caches the compiled php script? Or we need to tell it what scripts it should cache?

  3. Insignia says:

    Just want to verify if my intuitions is correct that xcache can also be installed or be configured as part of lampp?..

  4. Tapas says:

    Hi Ravi,

    The reference URL for configuration given on step 2 is giving 503.
    Can you please elaborate the configuration or can you give other reference URL?

    Thanks

  5. leon says:

    thanks but i have two questions in mind

    1- The latest xcache version is 3.0.3 how we can update to it

    2-when trying to access xcache admin panel i am getting error

    Forbidden

    You don’t have permission to access /xcache on this server.

    i have checked permissions and they are ok

  6. Dante says:

    Hi i get the following error when i try to install xcache, can you help with suggestion on how to fix and install properly.Thanks

    Error: Package: xcache-admin-3.0.4-1.el6.noarch (epel)
    Requires: php-xcache = 3.0.4-1.el6
    Available: php-xcache-3.0.0-2.el6.remi.1.x86_64 (mt_dv_extras)
    php-xcache = 3.0.0-2.el6.remi.1
    Installing: php-xcache-3.0.1-1.el6.remi.x86_64 (mt_dv_extras)
    php-xcache = 3.0.1-1.el6.remi
    Error: Package: php-xcache-3.0.1-1.el6.remi.x86_64 (mt_dv_extras)
    Requires: php(zend-abi) = 20100525-x86-64
    Installed: php-common-5.4.13-1.el6.remi.x86_64 (installed)
    php(zend-abi) = 20100525-x86-64
    Available: php-common-5.4.10-1.el6.remi.x86_64 (mt_dv_extras)
    php(zend-abi) = 20100525-x86-64
    Available: php-common-5.4.11-1.el6.remi.x86_64 (mt_dv_extras)
    php(zend-abi) = 20100525-x86-64
    Available: php-common-5.4.12-1.el6.remi.x86_64 (mt_dv_extras)
    php(zend-abi) = 20100525-x86-64
    Error: Package: php-xcache-3.0.1-1.el6.remi.x86_64 (mt_dv_extras)
    Requires: php(api) = 20100412-x86-64
    Installed: php-common-5.4.13-1.el6.remi.x86_64 (installed)
    php(api) = 20100412-x86-64
    Available: php-common-5.4.10-1.el6.remi.x86_64 (mt_dv_extras)
    php(api) = 20100412-x86-64
    Available: php-common-5.4.11-1.el6.remi.x86_64 (mt_dv_extras)
    php(api) = 20100412-x86-64
    Available: php-common-5.4.12-1.el6.remi.x86_64 (mt_dv_extras)
    php(api) = 20100412-x86-64
    You could try using –skip-broken to work around the problem
    You could try running: rpm -Va –nofiles –nodigest

    • Ravi Saive says:

      Seems your old packages are conflicting with new ones. So, fix such errors you must remove older version of php-xcache and php-common.

      # yum remove php-xcache php-common
      

      And then try to install it again.

      # yum install php-xcache php-common
      
      • Dante says:

        Dependencies Resolved

        ============================================================================================================================================================================================================================================
        Package Arch Version Repository Size
        ============================================================================================================================================================================================================================================
        Removing:
        php-common x86_64 5.4.13-1.el6.remi installed 6.2 M
        Removing for dependencies:
        SSHTerm noarch 0.2.2-10.11092910 installed 4.9 M
        cs-gs x86_64 2.0.0-cos6.build110120608.16 installed 845 k
        php x86_64 5.4.13-1.el6.remi installed 9.1 M
        php-cli x86_64 5.4.13-1.el6.remi installed 7.7 M
        php-devel x86_64 5.4.13-1.el6.remi installed 12 M
        php-gd x86_64 5.4.13-1.el6.remi installed 665 k
        php-imap x86_64 5.4.13-1.el6.remi installed 199 k
        php-ldap x86_64 5.4.13-1.el6.remi installed 109 k
        php-mbstring x86_64 5.4.13-1.el6.remi installed 2.5 M
        php-mcrypt x86_64 5.4.13-1.el6.remi installed 86 k
        php-mysql x86_64 5.4.13-1.el6.remi installed 447 k
        php-odbc x86_64 5.4.13-1.el6.remi installed 178 k
        php-pdo x86_64 5.4.13-1.el6.remi installed 348 k
        php-pear noarch 1:1.9.4-12.el6.remi.1 installed 2.2 M
        php-snmp x86_64 5.4.13-1.el6.remi installed 107 k
        php-xml x86_64 5.4.13-1.el6.remi installed 622 k
        php-xmlrpc x86_64 5.4.13-1.el6.remi installed 153 k
        plesk-core x86_64 11.0.9-cos6.build110120608.16 installed 79 M
        plesk-l10n noarch 11.0.9-cos6.build110120827.16 installed 21 M
        pp-sitebuilder noarch 11.0.10-38713.12081600 @SITEBUILDER_11_0_10-dist 181 M
        psa x86_64 11.0.9-cos6.build110120608.16 installed 473 k
        psa-atmail noarch 1:1.05-cos6.build110120606.19 installed 13 M
        psa-backup-manager x86_64 11.0.9-cos6.build110120608.16 installed 8.5 M
        psa-backup-manager-vz x86_64 11.0.0-cos6.build110120123.10 installed 1.6 k
        psa-fileserver x86_64 11.0.9-cos6.build110120608.16 installed 367 k
        psa-firewall x86_64 11.0.9-cos6.build110120608.16 installed 540 k
        psa-horde noarch 3.3.13-cos6.build110120606.19 installed 20 M
        psa-imp noarch 4.3.11-cos6.build110120606.19 installed 12 M
        psa-ingo noarch 1.2.6-cos6.build110120606.19 installed 5.1 M
        psa-kronolith noarch 2.3.6-cos6.build110120606.19 installed 6.3 M
        psa-libxml-proxy x86_64 2.7.8-0.301910 installed 1.2 M
        psa-migration-agents x86_64 11.0.9-cos6.build110120608.16 installed 169 k
        psa-migration-manager x86_64 11.0.9-cos6.build110120608.16 installed 1.0 M
        psa-mimp noarch 1.1.4-cos6.build110120418.19 installed 2.9 M
        psa-miva x86_64 1:5.06-cos6.build110120606.19 installed 4.5 M
        psa-mnemo noarch 2.2.5-cos6.build110120606.19 installed 4.1 M
        psa-passwd noarch 3.1.3-cos6.build110120606.19 installed 3.7 M
        psa-php5-configurator x86_64 1.6.2-cos6.build110120608.16 installed 6.4 k
        psa-spamassassin x86_64 11.0.9-cos6.build110120608.16 installed 159 k
        psa-turba noarch 2.3.6-cos6.build110120606.19 installed 6.1 M
        psa-updates noarch 11.0.9-cos6.build110120704.10 installed 0.0
        psa-vhost noarch 11.0.9-cos6.build110120606.19 installed 159 k
        psa-vpn x86_64 11.0.9-cos6.build110120608.16 installed 1.9 M
        psa-watchdog x86_64 11.0.9-cos6.build110120608.16 installed 2.9 M

        Transaction Summary
        ============================================================================================================================================================================================================================================
        Remove 45 Package(s)

        Installed size: 425 M
        Is this ok [y/N]: n

        sorry for the long post just want to make sure that i am doing the right thing, alot of sites on the server. This is what i get when i run yum remove php-xcache php-common, I believe clicking y will remove just the php-common and not affect anything else? Thanks.

        • Ravi Saive says:

          It will not affect anything just updates to latest versions, go ahead..

        • Daniel says:

          Remove 45 Package(s)
          Installed size: 425 M

          hhahahaaa OMG removing 425mb? LOL .. isn’t it like 20% of all CentOS ? :D hahahaa… I would’ve NEVER blindly accept such removal, before I know what each package is used for…

          Ravi, I really like your blog and happy I found it. I trust your experience.

          But can you explain what was that process of removing 45 packages, and how come it was safe actually? it will remove them and automatically reinstall new package versions or something?

          Thanks :)

          • Ravi Saive says:

            It seems you are using older version of OS and lot’s of packages need to be upgraded to install latest Xcache on the system.

Leave a Reply

This work is licensed under a (cc) BY-NC | TecMint uses cookies. By using our services, you comply to use of our cookies. More info: Privacy Policy.
© 2012-2014 All Rights Reserved.