How to Enable APC With PHP on CentOS 6.3

Share this Article :

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.

1. Install using yum command :

[[email protected] ~]# yum install php-pecl-apc -y

Examples :

[[email protected] ~]# yum install php-pecl-apc -y
Loaded plugins: fastestmirror, presto
Loading mirror speeds from cached hostfile
 * base: mirrors.hostemo.com
 * extras: mirrors.hostemo.com
 * updates: mirrors.hostemo.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package php-pecl-apc.i686 0:3.1.9-2.el6 will be installed
--> Processing Dependency: /usr/bin/pecl for package: php-pecl-apc-3.1.9-2.el6.i686
--> Processing Dependency: /usr/bin/pecl for package: php-pecl-apc-3.1.9-2.el6.i686
--> Running transaction check
---> Package php-pear.noarch 1:1.9.4-4.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================
 Package               Arch            Version                  Repository                     Size
====================================================================================================
Installing:
 php-pecl-apc          i686            3.1.9-2.el6              CentOS6.3-Repository           96 k
Installing for dependencies:
 php-pear              noarch          1:1.9.4-4.el6            CentOS6.3-Repository          393 k

Transaction Summary
====================================================================================================
Install       2 Package(s)

Total download size: 489 k
Installed size: 2.5 M
Downloading Packages:
Setting up and reading Presto delta metadata
Processing delta metadata
Package(s) data still to download: 489 k
----------------------------------------------------------------------------------------------------
Total                                                               3.3 MB/s | 489 kB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : 1:php-pear-1.9.4-4.el6.noarch                                                    1/2
  Installing : php-pecl-apc-3.1.9-2.el6.i686                                                    2/2
  Verifying  : 1:php-pear-1.9.4-4.el6.noarch                                                    1/2
  Verifying  : php-pecl-apc-3.1.9-2.el6.i686                                                    2/2

Installed:
  php-pecl-apc.i686 0:3.1.9-2.el6

Dependency Installed:
  php-pear.noarch 1:1.9.4-4.el6

Complete!

2. Specify shared memory :

[[email protected] ~]# vi /etc/php.d/apc.ini

On Line 12, specify shared memory size :

; The size of each shared memory segment, with M/G suffix
apc.shm_size=512M
; 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;

3. Restart Apache :

[[email protected] ~]# /etc/rc.d/init.d/httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]

4. Create “phpinfo” and please make sure APC has been enabled :

[[email protected] ~]# vi /var/www/html/phpinfo.php
<?php
phpinfo();
?>

APC

Leave a Reply