What is APC?
APC means Alternative PHP Cache. PHP is the language many websites are built with. Each time someone opens a page, PHP reads and turns the code into a form the computer can run. APC keeps that finished form in memory. The next visitor gets the page faster, like a cook who keeps a dish ready instead of cooking it again.
You need root access for this guide. Root is the main administrator login of the server.
Tip: APC is old and is no longer made. Newer PHP versions use OPcache, which is built in, and APCu for storing data. The steps below work for older PHP versions, and newer tools work in a similar way.
Steps
- Connect to your server with SSH.
- Install the tools needed to build PHP add-ons. On Red Hat style systems:
This installs the build tools and PECL. PECL is the store for PHP add-ons.yum install php-devel php-pear gcc make httpd-devel pcre-devel - Install APC.
This downloads and builds APC. It may ask questions. Press Enter to take the defaults.pecl install apc - Tell PHP to load it. Create a file.
This adds one line that loads APC. The folder may differ on your server.echo "extension=apc.so" > /etc/php.d/apc.ini - Add a memory size line to the same file if you like.
This gives APC 64 MB of memory. Pick a size that suits your server.echo "apc.shm_size=64M" >> /etc/php.d/apc.ini - Restart the web server.
This makes Apache load the new settings.service httpd restart - Check that it works.
If you seephp -m | grep apcapc, it is installed.
If you use cPanel and WHM
Do not build PHP add-ons by hand. In WHM, open Module Installers, then PHP Pecl. You can install add-ons from there.
If you use APCu
For PHP 5.5 and newer, run pecl install apcu. Then use extension=apcu.so.
php -v before you start. Take a backup of your PHP settings files first.Quick recap
- APC keeps compiled PHP code in memory to speed up sites.
- Install build tools, then run
pecl install apc. - Add the extension line to a PHP settings file and restart Apache.
- Newer PHP uses OPcache and APCu.