Integrating APC (Alternative PHP Cache) Into PHP5 And Lighttpd (Debian Etch)

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Thu, 2008-10-09 11:30. :: Debian | Lighttpd | PHP

Integrating APC (Alternative PHP Cache) Into PHP5 And Lighttpd (Debian Etch)

Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>
Last edited 08/26/2008

This guide explains how to integrate APC (Alternative PHP Cache) into PHP5 and lighttpd on a Debian Etch system. APC is a free and open PHP opcode cacher for caching and optimizing PHP intermediate code. It's similar to other PHP opcode cachers, such as eAccelerator and XCache.

I do not issue any guarantee that this will work for you!

 

1 Preliminary Note

I have tested this on a Debian Etch server with the IP address 192.168.0.100 where lighttpd and PHP5 are already installed and working (e.g. like in this tutorial). I'll use lighttpd's default document root /var/www in this tutorial for demonstration purposes. Of course, you can use any other vhost as well, but you might have to adjust the path to the info.php file that I'm using in this tutorial.

 

2 Checking PHP5's Current State

First, before we install APC, let's find out about our PHP5 installation. To do this, we create the file info.php in our document root /var/www:

vi /var/www/info.php

<?php
phpinfo();
?>

Afterwards, we call that file in a browser: http://192.168.0.100/info.php

As you see, we have PHP 5.2.0 installed...

... but APC isn't mentioned anywhere on the page:

 

3 Installing APC

APC is a PHP extension that can be installed using PECL. PECL comes with the php-pear package, so we install that now:

apt-get install php-pear

Furthermore we must install some APC dependencies so that PECL can build APC:

apt-get install php5-dev build-essential

Now that all dependencies are installed, we can install APC as follows:

pecl install apc

When you see the following question, please answer with no:

[...]
Use apxs to set compile flags (if using APC with Apache)? [yes] :
<-- no
[...]

Now that APC is installed, we create the configuration file /etc/php5/cgi/conf.d/apc.ini. We must at least add the line extension=apc.so in there; all other configuration options are optional. You can find a list of all available configuration options on http://de2.php.net/manual/en/ref.apc.php.

vi /etc/php5/cgi/conf.d/apc.ini

extension=apc.so
apc.enabled=1
apc.shm_size=30

That's it. Restart lighttpd, and you're done:

/etc/init.d/lighttpd restart

Afterwards, open info.php again in a browser: http://192.168.0.100/info.php

You should now see APC mentioned on the page which means it has successfully been integrated and is working as expected:

 

4 Links


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by justafish (not registered) on Mon, 2011-11-07 19:49.

You'll probably need to install the libpcre3-dev as well in order to install APC

Submitted by Adam (not registered) on Fri, 2008-10-10 12:15.

I love it! Been searching for a guide recently and but no luck , but did manage to install APC on debian setup but now with this guide it all went like a breeze with no errors as I experienced trying earlier.