If you’re unable to get xCache working, or are looking for other PHP caching solutions on your server to help reduce the load, APC cache is a great alternative. APC stands for Alternative PHP Cache and has been around for a long time, and now supports PHP 5.3 in its latest version we’re about to install.  APC is an open source cache alternative, and gets it’s updates from a handful of dedicated developers.

Simply follow along to get a good clean install of the latest APC version. All of these commands are run from SSH as the root or super user.

[sourcecode language=”bash”] # cd /usr/src
# wget http://pecl.php.net/get/APC-3.1.3p1.tgz
# gzip -d APC-*
# tar -xf APC-*
# cd APC-*
# which php
# phpize
# ./configure –enable-apc –enable-apc-mmap –with-apxs –with-php-config=/usr/local/bin/php-config
# make
#make install
[/sourcecode]

Line 1. Changes you to the /usr/src directory. {optional}
Line 2. Gets the latest APC version
Line 3. Unpacks the version
Line 4. Unpacks the download
Line 5. Moves you to the APC folder
Line 6. Lets you know where PHP is, should be something like ‘/usr/local/bin/php’
Line 7. Creates configuration files
Line 8. Configures APC cache with the predefined options
Line 9. Makes the install files
Line 10. Installs APC to your system

Lastly we need to edit the php.ini file

[sourcecode language=”bash”] # locate php.ini
# nano /location/of/php.ini
[/sourcecode]

Search for ‘extension_dir’ and below that place

[sourcecode language=”bash”] extension=”apc.so”
apc.enabled=1
apc.shm_segments=1
apc.shm_size=128
apc.ttl=7200
apc.user_ttl=7200
apc.num_files_hint=1024
apc.mmap_file_mask=/tmp/apc.XXXXXX
apc.enable_cli=1
[/sourcecode]

Finally restart apache
[sourcecode language=”bash”] # service httpd restart
[/sourcecode]

Alternative PHP Cache (APC) is now installed to your system. You can tweak the settings by editing the lines above in your php.ini file. (Don’t forget to restart every time). If you want to check if APC is working, simply create a php info page, and look for the section on APC. There is also an “apc.php” file inside your /usr/src/APC-* folder, you can move to a public location and view it from the internet for stats.

Related Articles

One Comment

  1. Johnathin

    This guide worked perfectly for me on a cPanel server. I couldn’t get the xCache one to work for some reason, so thanks for the guide.

Leave a comment

Your email address will not be published. Required fields are marked *