
在Linux上安装和开启PHP APC
该说明文档描述了如何在RHEL 6.3/6.2/6.1/6/5.8/5.6,CentOS 6.3/6.2/6.1/6/5.8/5.6和Fedora 17,16,15,14,13,12上使用PECL命令从代码仓库中下载,安装以及开启APC。
安装APC的依赖包
首先,我们需要安装所需的软件包,pecl,phpize和apxs命令,并使用YUM包管理工具来安装APC。
yum install php-pear php-devel httpd-devel pcre-devel gcc make
使用PECL安装APC
现在我们已经安装了所有必须的软件包以用来安装APC。接下来我们使用PECL命令来安装它。安装过程中请选择默认的设置值。
pecl install apc
输出如下:
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
downloading APC-3.1.9.tgz ...
Starting to download APC-3.1.9.tgz (155,540 bytes)
.................................done: 155,540 bytes
54 source files, building
running: phpize
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626
config.m4:180: warning: AC_CACHE_VAL(PHP_APC_GCC_ATOMICS, ...): suspicious cache-id, must contain _cv_ to be cached
../../lib/autoconf/general.m4:1974: AC_CACHE_VAL is expanded from...
../../lib/autoconf/general.m4:1994: AC_CACHE_CHECK is expanded from...
config.m4:180: the top level
config.m4:180: warning: AC_CACHE_VAL(PHP_APC_GCC_ATOMICS, ...): suspicious cache-id, must contain _cv_ to be cached
../../lib/autoconf/general.m4:1974: AC_CACHE_VAL is expanded from...
../../lib/autoconf/general.m4:1994: AC_CACHE_CHECK is expanded from...
config.m4:180: the top level Enable internal debugging in APC [no] : Enable per request file info about files used from the APC cache [no] : Enable spin locks (EXPERIMENTAL) [no] : Enable memory protection (EXPERIMENTAL) [no] : Enable pthread mutexes (default) [yes] : Enable pthread read/write locks (EXPERIMENTAL) [no] :
开启PHP的APC扩展模块
运行下面的命令以开启APC扩展模块在Apache配置中
echo "extension=apc.so" > /etc/php.d/apc.ini
重启Apache服务
重启Apache服务以使新的更改生效。
service httpd restart
OR
/etc/init.d/httpd restart
验证APC安装是否成功
在Apache WEB服务根目录下创建一个phpinfo.php文件。例如/var/www/html/phpinfo.php
# vi /var/www/html/phpinfo.php
添加下面的代码到该文件,保存并关闭。
<?php
// Show all information, defaults to INFO_ALL
phpinfo();
?>
在浏览器中打开下面的URL链接。你将看到APC模块的开启配置项,如下面所示。

PHP APC Configuration Screen
开启PHP APC管理
开启APC管理面板,你需要复制下面的文件:
cp /usr/share/pear/apc.php /var/www/html/
接下来打开apc.php文件
# vi /var/www/html/apc.php
如下所示,在apc.php文件中设置用户名及密码。
defaults('ADMIN_USERNAME','apc'); // Admin Username
defaults('ADMIN_PASSWORD','Set-Password-Here'); // Admin Password - CHANGE THIS TO ENABLE!!!
在浏览器中输入如下的URL链接,你将可以使用APC的管理面板。
http://localhost/apc.php
下面是一些APC管理面板的截图,以供你参考。
查看主机统计数据

APC View Host Stats Overview
系统缓存条目

APC System Cache Entries Overview
用户缓存条目

APC User Cache Entries Overview
APC登陆截图

APC Admin Login Screen
APC版本检查

APC Version Check Overview
使用PECL升级APC
执行如下的命令即可下载并升级APC
pecl upgrade apc
使用PECL卸载APC
如果你想移除它,使用如下的命令即可从你的系统中完全移除APC。
pecl uninstall apc