How to install XCache on VPS CentOS 7

XCache is free and open source PHP. By using XCache, you will have better performance in your PHP script execution on a Linux VPS. It can achieve this by eliminating the compilation time of the PHP code, caching the compiled version of the PHP code into memory, and then using the compiled version of the code. It can significantly speed up page generation times up to 5x faster, and it also optimizes and enhances many other aspects of PHP scripts and reduces server load.

In this tutorial, we are going to show you how to install XCache on CentOS 7 VPS.

First of all, login to your CentOS 7 VPS server and make sure all packages on your server are up to date

                      yum -y update
                    

Then, install the following packages

                      yum install -y php-devel gcc make
                    

Once the required packages are installed, proceed to download XCache. Go to their official website and select the latest stable version of XCache. At the time of this writing, this is version 3.2.0

                      cd /opt
wget https://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz
                    

Unpack the downloaded .tar archive

                      tar -zxvf xcache-3.2.0.tar.gz
                    

This will create a new directory ‘XCache-3.2.0’. Go to this directory

                      cd xcache-3.2.0
                    

Run phpize command to prepare XCache as PHP extension

                      phpize
Configuring for:
PHP Api Version:         20100412
Zend Module Api No:      20100525
Zend Extension Api No:   220100525
                    

Next, we need to configure, compile and install XCache

                      ./configure --enable-xcache
make
make install
                    

The location of xcache.so is shown in the last step

                      Installing shared extensions:     /usr/lib64/php/modules/
                    

So the location of the XCache extension is the path:

                      /usr/lib64/php/modules/
                    

Now we need to edit the PHP configuration file. In order to find it, you need to. for you to do

                      php -i |grep php.ini
Configuration File (php.ini) Path => /etc
Loaded Configuration File => /etc/php.ini
                    

Create a config file for XCache and add the following lines

                      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
                    

Make sure to add the correct path to the XCache extension.

You can change the parameters in the xcache.ini file according to your needs.

Restart the Apache web server for the changes to take effect

                      systemctl restart  httpd.service
                    

At this point, XCache should be successfully installed on your server. You can check this by running the following command

                      # php -v
PHP 5.4.16 (cli) (built: Jun 23 2015 21:17:27) 
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 Optimizer v3.2.0, Copyright (c) 2005-2014, by mOo
    with XCache Cacher v3.2.0, Copyright (c) 2005-2014, by mOo
    with XCache Coverager v3.2.0, Copyright (c) 2005-2014, by mOo
                    

PS. If you liked this post, please share it with your friends on social networks using the buttons on the left side of the post, or just leave a comment below. Thank you in advance.

Related Posts