• How to install APC Cache in Plesk

What is PHP APC Cache?

If you’ve been around PHP for a while, you’ve probably heard about APC, the Alternative PHP Cache. APC is an opcode cache that can significantly speed up your PHP applications, by caching both PHP code and user variables. Adding APC to an application usually results in improved application response times, reduced server load and happier users.

When dealing with Plesk web servers with multiple users and websites, APC PHP cache might be required in order to achieve reliable server performance. Step 1: Getting Started

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 case you don’t have php-pear installed, run this command:

yum install php-pear

Step 2: APC PHP Dependencies

Next, let’s install any remaining dependencies which are required by PHP APC

yum install php-devel httpd-devel gcc

Step 3: Installing APC using the PECL command

pecl install apc

Step 3: Enable Alternative PHP Cache

Enable APC PHP cache in Apache’s configuration. By using command:

vi /etc/php.d/apc.ini

and add the following code if it's not already there:

; Enable apc 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 enable the APC opcode cache
; WARNING: don't set this option if another opcode cache is enabled

; This can be set to 0 to disable APC.

; The size of each shared memory segment, with M/G suffixe

; The shared memory size reserved for strings, with M/G suffixe
; WARNING: only enable this buffer if you don't use Zend Opcache

; 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 are 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 are 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 have not changed since the last stat. APC will normally only check mtime.

; If on, then relative paths are canonicalized in no-stat mode.
; If set, then files included via stream wrappers can not be cached
; as realpath() does not support stream wrappers.

; 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.

; RFC1867 File Upload Progress hook handler
;apc.rfc1867_prefix =upload_

; Enables APC handling of signals, such as SIGSEGV, that write core files when signaled.
; APC will attempt to unmap the shared memory segment in order to exclude it from the core file

; Records a md5 hash of files.

; not documented

save and quit vi with

esc wq enter

Step 4: Restart Apache, nginx and php-fpm

/etc/init.d/httpd restart
/etc/init.d/nginx restart
/etc/init.d/php-fpm restart

You can edit APC config file to change settings using this command:

vi /etc/php.d/apc.ini

Remember to restart your web services to apply any changes made.

That’s it. Enjoy!

This article was last modified: May 24, 2016, 1:28 p.m.


Please log in to leave a comment.

Add or change tags.

A comma-separated list of tags.


Hacker News