CentOSLinuxTutorials

How To Install XCache for PHP on CentOS

Install XCache for PHP on CentOS

In this tutorial, we will show you how to install XCache for PHP on CentOS. For those of you who didn’t know, XCache is an open-source opcode cacher, which means that it accelerates the performance of PHP on servers. It optimizes performance by removing the compilation time of PHP scripts by caching the compiled state of PHP scripts into the shm (RAM) and using the compiled version straight from the RAM. This will increase the rate of page generation time by up to 5 times as it also optimizes many other aspects of PHP scripts and reduces server load.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of XCache on CentOS.

Prerequisites

  • A server running one of the following operating systems: CentOS or any other RHEL-based distribution.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install XCache for PHP on CentOS

Step 1. First, add the EPEL yum repository to your system.

CentOS 6:

rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

CentOS 7:

rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-1.noarch.rpm

Step 2. Install XCache for PHP.

yum install php-xcache xcache-admin

Step 3. Configuring of XCache for PHP.

nano /etc/php.d/xcache.ini

[xcache-common]
extension = /usr/lib64/php/modules/xcache.so
[xcache]
xcache.shm_scheme =        "mmap"
xcache.size  =               32M
xcache.count =                 1
xcache.slots =                8K
xcache.ttl   =              3600
xcache.gc_interval =         300
; Same as aboves but for variable cache
; If you don't know for sure that you need this, you probably don't
xcache.var_size  =            0M
xcache.var_count =             1
xcache.var_slots =            8K
xcache.var_ttl   =             0
xcache.var_maxttl   =          0
xcache.var_gc_interval =     300
; N/A for /dev/zero
xcache.readonly_protection = Off
xcache.mmap_path =    "/dev/zero"
xcache.cacher =               On
xcache.stat   =               On

You can modify the settings in the xcache.ini file according to your needs. Detailed explanations about these settings you can find on the xCache official website.

Step 4. Restart your Nginx web server.

sudo service nginx restart

At this point, xCache should be successfully installed on your server. You can confirm that by executing the following command:

php -v
PHP 5.5.20 (cli) (built: Dec 31 2014 00:46:99)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
with XCache v3.2.0, Copyright (c) 2005-2014, by mOo
with XCache Cacher v3.2.0, Copyright (c) 2005-2014, by mOo

Congratulations! You have successfully installed XCache for PHP. Thanks for using this tutorial for installing XCache in the CentOS system. For additional help or useful information, we recommend you check the official XCache website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button