In this guide I'll cover how to install APC for PHP which is the Alternative PHP Cache that can help speed up your PHP powered website. You can read our speed up PHP with APC guide for more info on how APC works.
After you install APC, you will want to learn how to view and clear the APC cache. That way you can keep tabs on what APC is caching, and how effective it might be working for your website.
Installing APC for PHP
You'll need to have root access on either a VPS or dedicated server in order to install APC for PHP. You also will need to be running either the FastCGI or DSO PHP handlers for APC to function properly.
- Login to your server via SSH with your root SSH access.
- Change directories with the following command:
- Get the source code for APC with the following code:
- Now extract the APC archive with this command:
tar xvzf APC-3.1.13.tgz
- Navigate into the extracted folder:
- Now run the following command to configure APC to your PHP environment:
You should get something like this back:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626
- Next configure the source code to run on your server with this command:
You'll see a lot of text scrolling by looking like this:
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
- Now you'll want to actually create the APC software with this command:
Again you'll see a lot of text scrolling by looking like:
/bin/sh /usr/local/src/APC-3.1.13/libtool --mode=compile cc -I. -I/usr/local/src/APC-3.1.13 -DPHP_ATOM_INC -I/usr/local/src/APC-3.1.13/include -I/usr/local/src/APC-3.1.13/main -I/usr/local/src/APC-3.1.13 -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /usr/local/src/APC-3.1.13/apc.c -o apc.lo mkdir .libs
Libraries have been installed in:
- Locate the extension_dir for PHP with this command:
grep extension_dir /usr/local/lib/php.ini
You should get back a path that looks something like:
extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20090626"
- Run this command to copy the APC Apache module (apc.so) to your PHP extension directory:
cp -frp modules/apc.so /usr/local/lib/php/extensions/no-debug-non-zts-20090626/
- Edit your php.ini file with your favorite text editor after making a backup:
cp -frp /usr/local/lib/php.ini /usr/local/lib/php.ini-BAK
Add these APC settings to the very bottom and save the php.ini file:
apc.optimization = 0
apc.use_request_time = 1
- Place the following code inside a info.php script on your site:
- Access that script on your site such as http://example.com/info.php. Look for the apc section:
If you don't see an apc section yet you might need to restart Apache with this command:
service httpd restart
Congratulations! You should now have successfully installed APC for PHP!
We value your feedback!
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
new! - Enter your name and email address above and we will post your feedback in the comments on this page!