I’ve used eAccelerator and XCache for quite some to speed up my WordPress sites, but with PHP6 around the corner, I wanted to get my feet wet with alternative PHP cache (APC) – an opcode cacher which will be built into the next generation of PHP. This is a walkthrough for how to install APC in a shared hosting environment (BlueHost in my case).
Before beginning, you’ll need to have SSH access to your server for compiling the APC module and have your php.ini file accessible (usually directly under public_html). Once you’ve SSHed into your box, execute the following commands in order.
mkdir modules apc
tar -xzvf APC-3.1.8.tgz
./configure --enable-apc --enable-apc-mmap --with-apxs --with-php-config=/usr/bin/php-config
mv apc.so /home/BLUEHOST-USERNAME/modules
Steps 1-6 create the necessary directories we’ll be using, download the latest stable APC file, extract it, and point to the directory.
Steps 7-9 compile the APC module according to the PHP version your server is running.
Steps 10-11 move the newly compiled module (apc.so) to a readily accessible directory which we will define in our php.ini file.
Now FTP into your box, create a backup of your php.ini file (/public_html/php.ini) and proceed to edit the original php.ini with a text editor program (ie, Wordpad for Windows, TextEdit for Mac OS X, Gedit for Linux).
Using the “Find” function, search for “extension_dir.” Place a semicolon before the line to comment it out, and copy and paste the following code in the next line. Change “BLUEHOST-USERNAME” to your username.
extension_dir = "/home/BLUEHOST-USERNAME/modules"
Note that this step will knock out any other modules which are loaded from the default extension_dir path. I haven’t found a way to load APC otherwise (as a zend_extension, for example).
Next, search for “Windows Extensions” in your php.ini file. You will see a list of directives preceded by semicolons. Copy and paste the following set of parameters above the “Windows Extensions” line to configure APC.
Finally, save and upload your php.ini file back to your public_html directory. You’ll need to restart your FastCGI engine, so log into your CPanel, find “Process Manager” under the “Advanced” header, and kill off any /ramdisk/bin/fcgiphp5 processes. Once they’re dead, navigate back to your site (this will automatically “restart” the FastCGI process and incorporate APC into the engine).
To verify that APC is indeed loaded, create a phpinfo file, and navigate to it via a web browser. Scroll down and look for an APC section.
If you’re a WordPress user, be sure to download the APC Object Cache Backend to your computer, extract it, and move the object-cache.php file to your server directly under the /wp-content/directory (note, this should not be installed like a regular plugin since those are installed under /wp-content/plugins/)
Though I haven’t run any official benchmarks comparing APC to XCache and eAccelerator, the very fact that it’s incorporated into PHP6 and seems to currently have more active development were good enough reasons for me to switch over.