How to install xCache on a CentOS 7 VPS
XCache is a free and open source PHP opcode cacher. Using xCache you can have better performance of your PHP scripts execution on your linux vps. It can achieve this by eliminating the compilation time of PHP code by caching the compiled version of the PHP code into the memory and later uses the compiled version of the code. This can significantly accelerate the page generation time by up to 5 times faster and also optimizes and increases many other aspects of php scripts and reduces the server load.
In this tutorial we will show you how to install xCache on a CentOS 7 VPS from source.
First of all login to your CentOS 7 VPS and make sure that 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 with the xCache downlod. Go to their official website and grab the latest stable version of xCache. At the moment of writing this article it is version 3.2.0
cd /opt wget http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz
Unpack the downloaded tarball archive
tar -zxvf xcache-3.2.0.tar.gz
This will create a new ‘xcache-3.2.0’ directory. Go to that directory and
Execute the ‘phpize’ command to prepare xCache as a 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
Now, we need to edit the PHP configuration file. To find its location you can execute
php -i |grep php.ini Configuration File (php.ini) Path => /etc Loaded Configuration File => /etc/php.ini
Create a configuration file for xCache, and append 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 of the xCache extension.
You can modify the settings in the xcache.ini file according to your needs.
Restart your 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 confirm that by executing the following command
php -v PHP 5.4.16 (cli) (built: Oct 31 2014 12:59:36) 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
Of course you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to xCache for you. They are available 24×7 and will take care of your request immediately.
PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.