Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Install APC on a Linux server

This guide shows you how to install APC, a PHP speed-up tool, on a Linux server.

Dedicated Servers2 min read7 steps

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

  1. Connect to your server with SSH.
  2. Install the tools needed to build PHP add-ons. On Red Hat style systems:
    yum install php-devel php-pear gcc make httpd-devel pcre-devel
    This installs the build tools and PECL. PECL is the store for PHP add-ons.
  3. Install APC.
    pecl install apc
    This downloads and builds APC. It may ask questions. Press Enter to take the defaults.
  4. Tell PHP to load it. Create a file.
    echo "extension=apc.so" > /etc/php.d/apc.ini
    This adds one line that loads APC. The folder may differ on your server.
  5. Add a memory size line to the same file if you like.
    echo "apc.shm_size=64M" >> /etc/php.d/apc.ini
    This gives APC 64 MB of memory. Pick a size that suits your server.
  6. Restart the web server.
    service httpd restart
    This makes Apache load the new settings.
  7. Check that it works.
    php -m | grep apc
    If you see apc, 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.

Tip: Check your PHP version with 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.