Update:

On Ubuntu 12.04 LTS (Precise Pangolin) the repositories already contain a package called php-apc that works very well. There is no need to install APC using pecl at all as in the article below.

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 an Ubuntu server running Gutsy Gibbon 7.10.

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

Do to so, we execute the following command:

aptitude install php-pear  

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

aptitude install php5-dev  

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

aptitude install apache2-dev 

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/php5/apache2/conf.d/apc.ini 

Then we restart Apache:

 /etc/init.d/apache2 restart

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.

Comments

Sun, 2009/06/21 - 08:55

Hi, thank you for the tutorial. I was unable to complete the pecl command and encountered this error message:

Sorry, I was not able to successfully run APXS. Possible reasons:

1. Perl is not installed;
2. Apache was not compiled with DSO support (--enable-module=so);
3. 'apxs' is not in your path. Try to use --with-apxs=/path/to/apxs

however, this was resolved with

aptitude install apache2-threaded-dev

Thank you. This is on an installation of Debian 5.

Tue, 2010/01/19 - 06:26

On Ubuntu, I also had to install apache2-threaded-dev:
sudo apt-get install apache2-threaded-dev

Before running:
sudo pecl install apc

and then:
gksudo gedit /etc/php5/apache2/conf.d/apc.ini

...paste in the file:
extension=apc.so

and save it.

Sun, 2010/01/17 - 00:20

I had problems getting this to work on PHP 5.2.12-0.dotdeb.1 This link explains the .dotdeb version does not override the default php-config to php-config5 necessary for phpize.

I tried this:
Running pecl install apc --with-php-config=/usr/bin/php-config5

But it gave me this error:

Attempting to discover channel "--with-php-config=/usr/bin"...
Attempting fallback to https instead of http on channel "--with-php-config=/usr/bin"...
unknown channel "--with-php-config=/usr/bin" in "--with-php-config=/usr/bin/php-config5"
invalid package name/package file "--with-php-config=/usr/bin/php-config5"

:(

Finally I just ran this:
apt-get install php-apc

Everything seems fine!

Sun, 2010/01/17 - 10:09

I always advocate using the long term support (LTS) server version (8.04 at present), and only the official repositories. This makes things easier and more contained. For 8.04 LTS, there is no pre-built APC package in the official repositories.

Ubuntu 9.10 has a php-apc package, but it is not a long term support version, and hence not suitable for live servers.

Mon, 2010/03/08 - 18:40

Few months ago I have installed Zend Optimizer in my Drupal site.
To improve performance I have installed APC and my site is crashing.
Is there a problem with Zend Optimizer and APC? How can I uninstall APC?
Most of my users are unregistered. Would I use Zend or APC?

Mon, 2010/03/08 - 19:08

Did you install APC using pecl? If so then issue this from the command line:

pecl uninstall APC

Otherwise, just prevent APC from getting loaded. Find in your php.ini the place that has apc.so, and add a semicolon (;) before that line. That will have the same effect.

Wed, 2011/06/15 - 11:32

Hi there,

Noobie question here. Hope you can help me. I'm trying to install APC on Ubuntu server 8, and these have been the best instructions I've been able to find so far, so thanks!
I'm running into problems after downloading the pacakages. Specifically, when I try the pecl install apc command, I get the following:
54 source files, building
running phpize
Cannot find config.m4
Make sure that you run '/usr/bin/phpize' in the top level source directory of the module
ERROR: 'phpize' failed
I do have a config.m4 file in the /usr/local/src/APC-3.0.19 directory, which is where I'm trying to run pecl install apc
Now, if I run /usr/bin/phpize, I get a little bit farther:
/usr/local/src/APC-3.0.19# /usr/bin/phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519

At that point I continued on with the remaining steps, no errors.
But I'm not sure if this worked. How do I verify the APC module is installed?
Thanks for any suggestions.
Sir_timbit

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