In this tutorial we will show you how to install and configuration of Alternative PHP Cache (APC) on your CentOS server. For those of you who didn’t know, The Alternative PHP Cache (APC) is a free, open, and robust framework for caching and optimizing PHP intermediate code. It’s an PECL extension which shares the packaging and distribution system with its sister, PEAR. In this post, i will show how to enable APC (Alternative PHP Cache) and makes PHP be fast.
Install Alternative PHP Cache (APC) on CentOS
Step 1. Install dependencies.
yum install php-pear php-devel httpd-devel pcre-devel gcc make
Step 2. Installing Alternative PHP Cache (APC) on CentOS.
pecl install apc
Step 3. Configuring APC.
You can put your configuration in php.ini file but i prefer to have separate file like above for configuration. Values mentioned below are for demonstration purpose, different values for APC can be set which depends on number of PHP pages, size of memory in server, number of page hits e.t.c
; Enable the extension module
extension = apc.so
; Options for the APC module version >= 3.1.3
; See http://www.php.net/manual/en/apc.configuration.php
; This can be set to 0 to disable APC.
; The number of shared memory segments to allocate for the compiler cache.
; The size of each shared memory segment, with M/G suffixe
; A "hint" about the number of distinct source files that will be included or
; requested on your web server. Set to zero or omit if you're not sure;
; Just like num_files_hint, a "hint" about the number of distinct user cache
; variables to store. Set to zero or omit if you're not sure;
; The number of seconds a cache entry is allowed to idle in a slot in case this
; cache entry slot is needed by another entry.
; use the SAPI request start time for TTL
; The number of seconds a user cache entry is allowed to idle in a slot in case
; this cache entry slot is needed by another entry.
; The number of seconds that a cache entry may remain on the garbage-collection list.
; On by default, but can be set to off and used in conjunction with positive
; apc.filters so that files are only cached if matched by a positive filter.
; A comma-separated list of POSIX extended regular expressions.
; The mktemp-style file_mask to pass to the mmap module
; This file_update_protection setting puts a delay on caching brand new files.
; Setting this enables APC for the CLI version of PHP (Mostly for testing and debugging).
; Prevents large files from being cached
; Whether to stat the main script file and the fullpath includes.
; Vertification with ctime will avoid problems caused by programs such as svn or rsync by making
; sure inodes havn't changed since the last stat. APC will normally only check mtime.
; Whether to canonicalize paths in stat=0 mode or fall back to stat behaviour
; With write_lock enabled, only one process at a time will try to compile an
; uncached script while the other processes will run uncached
; Logs any scripts that were automatically excluded from being cached due to early/late binding issues.
;This setting is deprecated, and replaced with apc.write_lock, so let's set it to zero.
Step 4. Enable APC PHP Extension
Once that finishes, run the following command to enable APC extension in Apache configuration.
echo "extension=apc.so" > /etc/php.d/apc.ini
Step 4. Restrat Nginx
service httpd restart
APC provides a web interface with detailed information on the cache (memory usage, hits and misses, cache entries). By default it is not accessible so you need to copy the file /usr/share/php/apc.php to somewhere you can browse to. Now from browser, you can go to http://domain.com/apc.php. I prefer to wait for a day to see the APC performance so we can have clear idea how well our configuration did.
Congratulation’s! You have successfully installed Alternative PHP Cache (APC). Thanks for using this tutorial for installing Alternative PHP Cache (APC) on CentOS system. For additional help or useful information, we recommend you to check the official PHP web site.