Table of Contents
- Getting Started
- Installing XCache
- Configure XCache for PHP
- Enable XCache Admin Control Panel
Running PHP can slow down the performance of the Apache web server. In order to optimize website performance, you will need to improve PHP performance. There are many opcode caches available such as APC, eAccelerator, Memcached, and XCache. XCache is easy to install and use in various operating systems. XCache is an open-source, fast, and stable opcode cacher for PHP. It is used to improve the performance of PHP script execution.
It provides improvements to performance by eliminating the compilation time of PHP code for subsequent requests. After an initial request is made, XCache will cache the compiled PHP code into memory and then start using the compiled version of the code from the cache. This will accelerate the page response time and reduce the server load.
In this tutorial, we will learn how to configure and integrate XCache into PHP on Ubuntu 16.04.
- Ubuntu 16.04 server with Apache and PHP installed.
- Non-root user account with
Let's start making sure that your Ubuntu 16.04 server is fully up to date.
You can update your server by running the following command:
sudo apt-get update -y sudo apt-get upgrade -y
By default, XCache is available in the Ubuntu 16.04 repository. Therefore, you can install XCache package by simply running the following command:
sudo apt-get install php5-xcache
Now, you can verify that the extension is available by running the following command:
sudo php -m | grep -i XCache
If everything is fine, you should see the following output:
XCache XCache Cacher XCache Coverager XCache Optimizer XCache XCache Cacher XCache Coverager XCache Optimizer
Configure XCache for PHP
The XCache configuration file comes with lots of settings to play with. You can find detailed information on XCache configuration settings at INI settings for XCache. Fortunately, the default configuration settings are quite good.
XCache configuration file is located at /etc/php5/mods-available/xcache.ini.
Change the XCache configuration as per your needs. When you are finished, restart Apache service by running the following command:
sudo /etc/init.d/apache2 restart
Once you have started the Apache service, you can check the version of XCache along with PHP by running the following command:
sudo php -v
You should see the following output:
PHP 5.5.9-1ubuntu4.19 (cli) (built: Jul 28 2016 19:31:33) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies with XCache v3.1.0, Copyright (c) 2005-2013, by mOo with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies with XCache Optimizer v3.1.0, Copyright (c) 2005-2013, by mOo with XCache Cacher v3.1.0, Copyright (c) 2005-2013, by mOo with XCache Coverager v3.1.0, Copyright (c) 2005-2013, by mOo
Enable XCache Admin Control Panel
XCache provides a built-in web based control panel. You will need to need to generate an md5-encrypted password in order to be able to access it.
You can do this by running the following command:
echo -n "password" | md5sum
Replace "password" with the password you'd like to use.
Now, open the xcache.ini file and add the generated md5 password to file:
sudo nano /etc/php5/mods-available/xcache.ini
Edit the following line:
[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 = "5f4dcc3b5aa765d61d8327deb882cf99"
When you are finished, restart the Apache service by running the following command:
sudo /etc/init.d/apache2 restart
Next, copy htdocs directory located at /usr/share/xcache/ to your Web root directory:
sudo cp -r /usr/share/xcache/htdocs /var/www/html/xcache/
Now, open your favorite web browser and type the URL
http://server-ip-address/xcache, a http-auth login prompt window will pop-up. Enter your username and password, you should see the Xcache Admin Panel as follows:
We have installed and configure Xcache on the Apache server and boosted website performance. Feel free to add comments or ask questions below.