HOWTO: Install PECL APC Cache on CentOS (without XAMPP)

Posted Apr 2, 2008 // 6 comments
Frank:

As Irakli already discussed, the Alternative PHP Cache (APC) is an op-code pre-compiler and a cache system that can boost the performance of a PHP application up to 10 times. Op-code caches are very effective for a Drupal website, since Drupal deals with large number of source files and time spent in parsing them significantly affects performance. However, if you don’t have XAMPP and need to install it on CentOS, you can follow this to get around some of the problems that happen with the default server settings. h2. Install Pre-reqs Using yum install the required prerequisites.


sudo yum install php-devel php-pear httpd-devel

Install APC

Use the command


sudo pecl install apc

at this point you’ll likely see the error


Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 92160 bytes) in /usr/share/pear/PEAR/PackageFile/v2/Validator.php on line 1831

Apparantly, the PECL/PEAR scripts do not use the settings from /etc/php.ini so you need to update PEAR’s memory settings to give is some more breathing room. Edit the file /usr/share/pear/pearcmd.php and add the following at the beginning:

@ini_set('memory_limit', '16M');

Configure/Restart

Now configure PHP to use the new extension. Create the file /etc/php.d/apc.ini and in that file put:

extension=apc.so

Now restart apache

sudo /etc/init.d/httpd graceful

Maintenance

In the future, if new versions of APC are released, you can easily upgrade them using

sudo pecl upgrade apc

I hope this helps!

About Frank

Frank Febbraro is the CTO at Phase2. He is primarily interested in software, technology and integrating new techniques and practices with proven methods and approaches. A combination of inherent understanding and real world experience enables ...

more >

Read Frank's Blog

Comments

by Alain Williams (not verified) on Mon, 08/25/2008 - 18:12

A simpler way of fixing the pecl memory problem

Rather than change /usr/share/pear/pearcmd.php (which is a large script that may be updated) change /usr/bin/pecl to include ‘’-d memory_limit=16M’‘. This is more likely to work well with system updates via yum — which may want to update pearcmd.php

I have suggested this fix to redhat — where I raised the bug

by febbraro on Tue, 08/26/2008 - 11:25

Nice!

That is another good idea.

Recently, I have noticed since going to CentOS 5.2 that this problem no longer happens.

by Anonymous (not verified) on Mon, 11/03/2008 - 10:36

phpize cmd not found

If you get command not found error for phpize, then you will need to do yum install php-devel

And yes, problem with ‘pecl install apc’ running out of memory still exists in CentOS 5.2 (Final).

by febbraro on Wed, 09/24/2008 - 17:59

Problem finding apxs

If you run across the problem of

cannot open /httpd/build/config_vars.mk: No such file or directory at /usr/sbin/apxs line 201

The problem is likely that you do not have the x64 version of the apr-devel package installed. So you much first do:

yum install apr-devel.x86_64

Then you can proceed with the installation of APC. Hope this helps someone.

by Anonymous (not verified) on Sat, 02/28/2009 - 15:34

You can also install it with

You can also install it with this command:

pear install pecl/apc

I don't get the memory error if I install it that way.

by Jeff Schuler (not verified) on Fri, 05/29/2009 - 14:14

small typo

sudo /etc/init.d/httpd greaceful

...should be "graceful" not "greaceful"

(feel free to delete this comment!)

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • Allowed HTML tags: <a> <strong> <code> <p> <img> <ul> <ol> <li> <h2> <h3> <h4> <b> <u> <i>
  • You may insert videos with [video:URL]

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.