Complex PHP applications, such as Drupal, can gain a lot of performance benefits from running a PHP op-code cache/accelerators.

APC,
Alternate PHP Cache, is now the most maintained free/open source op-code cache, and is being used more and more as it emerges to be the
most stable.

The instructions here detail how to get APC running on a CentOS 5 server. The server happened to have Plesk on it as well, which initially made me hesitant to install APC "normally", since Plesk is so picky on what other software is installed on the server. However, it seems to have worked out well.

First, we need the pecl command so we can download and install APC from the repositories.

Do to so, we execute the following command:

yum install php-pear

But, this will not run on its own, we need the following package for the phpize command:

yum install php-devel

We also need the apxs command, which is installed via the following package:

yum install httpd-devel

Now we have all the software we need, so we install apc via the pecl command:

pecl install apc 

Once that finishes, we need to enable apc in Apache's configuration. the following command should do this for us.

echo "extension=apc.so" > /etc/php.d/apc.ini

Then we restart Apache:

/etc/init.d/httpd start

And we are all done. Watch for less execution time per page, and decreased memory usage per Apache process compared to what you had
before.

Links

You can find some additional tips at Setting up Alternative PHP Caching APC support on Centos server.

Comments

Fri, 2011/03/04 - 08:32

I was having problem to install APC via 'pecl' cause I didn't install the 'pcre-devel'.

This was very helpful! Thank you very much guys! :)

Tue, 2011/04/26 - 15:54

yum install pcre-devel did the trick. APC installed.

In phpinfo() apc shows as one of the modules but none of the variables like those below show.

apc.enabled=1
apc.shm_segments=1
apc.optimization=0
apc.shm_size=32
apc.ttl=0
#apc.ttl=7200
apc.user_ttl=7200
apc.num_files_hint=1024
apc.mmap_file_mask=/tmp/XXXXXX
apc.enable_cli=1
apc.cache_by_default=1

How do we know its installed and working? Also, we located apc.php but executing it in a browser gives us 500 error

Thanks a ton

Sun, 2011/10/16 - 11:19

A video tutorial would be greatly appreciated as I'm sure there are many newbies such as myself who don't have the slightest idea how to work this.

Between google, dealing with a hosting helpdesk who is losing his/her patience, and my own complete frustration with trying to figure this out, I am requesting a video tutorial please.

Thu, 2011/10/20 - 10:53

make: *** [apc.lo] Erreur 1
ERROR: `make' failed
[root@ks32755 ~]#

for : pecl install apc
:/

Wed, 2012/01/04 - 06:48

Can't run the first command successfully. Here is what I get:

Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository contrib is listed more than once in the configuration
Determining fastest mirrors
Plesk | 951 B 00:00
Plesk-Third-Party | 951 B 00:00
base | 1.1 kB 00:00
extras | 2.1 kB 00:00
updates | 1.9 kB 00:00
Excluding Packages in global exclude list
Finished
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package php-pear.noarch 1:1.4.9-6.el5 set to be updated
--> Processing Dependency: php-devel for package: php-pear
--> Running transaction check
---> Package php-devel.x86_64 0:5.1.6-27.el5_5.3 set to be updated
--> Processing Dependency: php = 5.1.6-27.el5_5.3 for package: php-devel
--> Processing Dependency: autoconf for package: php-devel
--> Processing Dependency: automake for package: php-devel
--> Running transaction check
---> Package autoconf.noarch 0:2.59-12 set to be updated
--> Processing Dependency: imake for package: autoconf
---> Package automake.noarch 0:1.9.6-2.3.el5 set to be updated
---> Package php-devel.x86_64 0:5.1.6-27.el5_5.3 set to be updated
--> Processing Dependency: php = 5.1.6-27.el5_5.3 for package: php-devel
--> Running transaction check
---> Package imake.x86_64 0:1.0.2-3 set to be updated
---> Package php-devel.x86_64 0:5.1.6-27.el5_5.3 set to be updated
--> Processing Dependency: php = 5.1.6-27.el5_5.3 for package: php-devel
--> Finished Dependency Resolution
php-devel-5.1.6-27.el5_5.3.x86_64 from base has depsolving problems
--> Missing Dependency: php = 5.1.6-27.el5_5.3 is needed by package php-devel-5.1.6-27.el5_5.3.x86_64 (base)
Error: Missing Dependency: php = 5.1.6-27.el5_5.3 is needed by package php-devel-5.1.6-27.el5_5.3.x86_64 (base)
You could try using --skip-broken to work around the problem
You could try running: package-cleanup --problems
package-cleanup --dupes
rpm -Va --nofiles --nodigest
The program package-cleanup is found in the yum-utils package.

What do the last two errors mean and how should I fix it?

php-devel-5.1.6-27.el5_5.3.x86_64 from base has depsolving problems
--> Missing Dependency: php = 5.1.6-27.el5_5.3 is needed by package php-devel-5.1.6-27.el5_5.3.x86_64 (base)
Error: Missing Dependency: php = 5.1.6-27.el5_5.3 is needed by package php-devel-5.1.6-27.el5_5.3.x86_64 (base)

Fri, 2012/06/22 - 17:17

The upload is working but the progress bar is remains at 0% what can i do ? :( please help

Fri, 2013/04/12 - 14:55

You don't mention that when you run:
pecl install apc
you are asked a question (or maybe it's just the first of a series):

Enable internal debugging in APC [no] :

What does that mean and what are the pros and cons of replying "yes" or "no" ?

Fri, 2013/04/12 - 17:45

You just hit enter. The default is fine.

But, this was for an older version of Ubuntu. The latest version (12.04) has a php-apc package that works well, with no need to install using pecl.

Pages

Is your Drupal or Backdrop CMS site slow?
Is it suffering from server resources shortages?
Is it experiencing outages?
Contact us for Drupal or Backdrop CMS Performance Optimization and Tuning Consulting