APC or Alternative PHP Cache is an awesome add-on for any apache web server. On my own server I was able to to handle about I was able to serve well over 1 million page views on a single server more traffic just by enabling the software. Facebook recently gave a presentation on how they use APC to serve over a billion php pages per month. My server does about 3% of that and its been running since 2004 so naturally Facebook doing the same thing as me is good reinforcement that I know what I’m doing.
Installing APC
First you have to download the latest APC and then uncompress it. To compile it use these 4 lines.
/usr/bin/phpize
./configure –enable-apc –enable-apc-mmap –with-apxs=/usr/local/apache/bin/apxs –with-php-config=/usr/bin/php-config –enable-apc-pthreadmutex
make
make install
To finish installing APC you need to edit php.ini and point it at the apc.so directory.
extension_dir = /usr/lib/php/extensions/
extension = apc.so
Configuring APC
My Server
apc.shm_segments = 1
apc.shm_size = 64
apc.stat = 1
Facebook
apc.shm_segments = 1
apc.shm_size = 648
apc.stat = 0
Other Improvements
Naturally setting up APC isn’t the only thing you can do to improve your server and your users experience. Enabling MySQL query cache is one thing you should do as it will vastly improve the number of pages your server can serve.
my.cnf with 64mb cache
query_cache_type = 1
query_cache_size = 67108864
Another thing you can do is use the Firefox plugin YSlow from Yahoo and it will show what parts of your site are slow and it will also make suggestions on what you can do to improve load times. They have a user guide thats better than anything I can write.
Beyond simple server setups you can use squid as a reverse transparent proxy to serve static content and you can learn about distributed cluster computing from Google.