How to install APC in Ubuntu 7.10

Devolio

Search

Wednesday, January 9. 2008

How to install APC in Ubuntu 7.10

APC, or Alternative PHP Cache, is a framework for PHP to cache opcodes. Opcodes are the actual instructions that are used when PHP executes scripts. By caching these, you can usually vastly improve performance across the board for PHP based applications. This guide covers installing APC in Ubuntu 7.10 with PHP5 and Apache2.

Setting up


This guide assumes you already have Apache2 and PHP5 working, and I personally like to use Xdebug to profile and verify improvements I make.

First we're going to open up a terminal (Applications->Accessories->Terminal). If you haven't installed PEAR and php5-dev, you'll have to grab those packages as well.
sudo apt-get install apache2-threaded-dev

Again, if you need to install pear and php5-dev, you can use this instead
sudo apt-get install apache2-threaded-dev php5-dev php-pear

Installing APC


Once that is done installing, we can use pecl and install APC. Before I install APC, I'm going to use Xdebug to benchmark my current setup to see how much of an improvement I can get.
sudo pecl install apc


That will get APC through pecl, and build it. Once it's finished, we can open up our php.ini file
sudo gedit /etc/php5/apache2/php.ini

And add in the extension...
extension=apc.so

Save your php.ini file, and we're good to go. All we have to do now is restart apache, by using
sudo /etc/init.d/apache2 restart

Testing


And by checking the output of phpinfo() in a PHP script, we can make sure that it's installed correctly and running.


Now I'll reload my setup again. Without even looking at the benchmarks, I can tell that the load time has improved, especially on the second load, almost instantly. The benchmarks will hopefully confirm my assumption.

Results



With APC installed and enabled, we have cut the time cost in half, and the page loads noticably faster. The numbers say it's about a ~50% improvement in speed. All in all, well worth the time to install.

If you want to learn more about APC, you can check it out on pecl and php.net.

Share

Save This Page
StumbleUpon Toolbar Stumble It!

Digg it

Trackbacks

No Trackbacks

Comments
Display comments as (Linear | Threaded)

#1 - aznowicz 2008-02-06 04:43 - (Reply)

apache2-dev seems to be replaced by package apache2-threaded-dev

#1.1 - Joey said:
2008-02-06 04:50 - (Reply)

Thanks for the heads up aznowicz, I've updated the article accordingly.

#2 - mozey said:
2008-04-24 23:34 - (Reply)

DUDE, i just got it working,

12 requests/second
to
54 requets/second

:-)

my application tho is lots of php and no db.


Add Comment

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications