Skip to content
Search

Alternative PHP Cache

lastmod 2018-08-17created 2015-01-159 edits

APC (Alternative PHP Cache), like eAccelerator and xcache, performs opcode caching.

How to install

The method below did not work properly in the test environment (CentOS7). <del>

sudo yum install php-pecl-apc

</del>

Install it as follows instead.

sudo yum install php-pear php-devel httpd-devel pcre-devel gcc make
sudo pecl channel-update pecl.php.net
sudo pecl install apc
## 중간에 나오는 질문에 답변한다. (그냥 전부 Enter 해도 된다)

Finally, add the apc configuration and restart the service.

## configuration option "php_ini" is not set to php.ini location
## You should add "extension=apc.so" to php.ini
echo "extension=apc.so" > /etc/php.d/apc.ini

## Restart apache httpd
sudo service httpd restart

Installing APC on MAC OSX

Reference: Installing Alternative PHP Cache (APC) on Mac OS X Lion
Reference: Installing PHP-APC on Ubuntu

./configure
make
sudo make install
  • Next, we can install the APC extension using the normal PECL route:
sudo pecl install apc
  • Confirm that you have the following line in your php.ini file:
extension=apc.so
  • Restart Apache, if required:
sudo apachectl graceful

Configuring APC

Without VirtualHost

Add the following to the bottom of php.ini.

[apc]
extension=apc.so

With VirtualHost

If httpd.conf uses VirtualHost, a slightly different configuration is needed for it to work properly. Add the following to the bottom of php.ini. (First, configure APC caching to be disabled.)

[apc]
extension=apc.so
apc.cache_by_default=0

Then add the following to the .htaccess file in the web root folder of each VirtualHost you want cached.

php_flag apc.cache_by_default On

Or add the following inside the Apache configuration of each VirtualHost you want cached.

<IfModule mod_php5.c>
php_flag apc.cache_by_default On
</IfModule>

Troubleshooting

A summary of fixes for APC-related problems in PHP.

PHP Warning Unable to load dynamic library apc.so

The following warning message may be printed.

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/apc.so' - /usr/lib64/php/modules/apc.so: undefined symbol: zend_new_interned_string in Unknown on line 0 
PHP 5.3.3 (cli) (built: Dec 11 2013 03:29:57) Copyright (c) 1997-2010 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

You need to install the related PHP module. In this case, reinstall the APC module (if it is installed). Install it as follows.

$ pecl uninstall apc
$ pecl install apc

See also