Quick Overview of Alternate PHP Cache (APC)
APC stands for Alternate PHP Cache. It is an open source caching module to cache PHP codes and thereby optimizing it. With this caching enabled in the server, PHP code will be cached and it will be served faster from then on without having to re-run the code.
Installation & Configuration of APC
One of the shortcomings of APC is that it won’t work with suPHP. So we need to install FCGI and make it the default PHP handler.
You can install FCGI by running easyapache. And for making FCGI, the default handler, goto:
Home >> Service Configuration >> Configure PHP and SuExec
Select CGI from the PHP 5 Handler drop down and Save New Configuration.
With this, pre-requisites of installing APC is complete.
For installing the APC cache, we need to install the dependency packages first.
yum install php-pear php-devel httpd-devel pcre-devel gcc make
With the dependencies installed, we can simply install APC with PECL. PECL is PHP Extension Community Library which contains the PHP extensions. PECL should be already in the cPanel servers along with the cPanel installation.
pecl install apc
A few questions will be prompted pre to installation. You can go with the recommended default option. SO, just hit ‘Enter’ for each one. You may refer the screenshot below.
This will enable the APC extension by mentioning the extension in the PHP configuration file (php.ini).
You can modify the APC functionality by editing the apc.ini file. By default this file is not created in cPanel servers. So we can edit the parameters in php.ini itself. The following command gives you php.ini file.
php -i | grep php.ini
The output can be referred from the screenshot.
The loaded configuration file is /usr/local/lib/php.ini by default in cPanel servers, So we can add the APC parameters in the PHP configuration file.
Here are a few recommended APC parameters:
#Enable/Disable APC apc.enabled=1 #Number of Memory segments (RAM) used by APC (It only uses 1 shm_segment, so you can set it as 1 or remove it) apc.shm_segments=1 #Number of storage space (RAM) allocated for APC (Default is 32 MB) apc.shm_size=1024M #APC Max file size apc.max_file_size=1M #Number of Opcode files stored in APC (default is 1000, you can increase values for more performance) apc.num_files_hint=20000
If you need to customize APC, you can add the values as mentioned above and make sure you restart apache after the changes.
You have APC installed and enabled now.