How to Optimize Drupal 8 Caching with APC on cPanel Hosting

How to Optimize Drupal 8 Caching with APC on cPanel Hosting

Introduction: Drupal 8 Caching & PHP 7 Speed Optimization

This Tutorial will show how to optimize Drupal 8 caching on PHP 7 using Alternative PHP Cache (APC) & third-party contributed modules that integrate with the platform.

Most cPanel web hosting companies running a version of CentOS, CloudLinux, or RHEL provide pre-installation of custom PHP stack extensions like PECL modules.

First confirm whether your cPanel web host has APC pre-installed on the Linux web server or consider upgrading to a VPS/Dedicated server to run APC caching in traffic.

Step One: Installation of APC on the Web Server

Alternative PHP Cache (APC) is one of the oldest PHP caching solutions for web servers and is pre-installed on most cPanel web hosting plans by default.

To install the PECL Modules by command line on VPS hosting or Dedicated servers:

sudo apt-get install php-apc

Or use the command:

pecl install apc

For shared web hosting plans without the ability to install PHP extensions, contact the company to request APC installation on the web server or upgrade to a VPS plan.

APC will not perform well on Drupal 8 websites running on shared Linux plans if the RAM allocation to the cache is too low. The default APC cache size is 32 MB.

For effective use of APC, plan for a minimum of a 128 MB to 256 MB cache allocation, where the rest of the available RAM will be used for Drupal 8 CMS processing.

Note that the RAM allocation must be calculated per Drupal 8 website & APC instance running on shared hosting plans with multiple domain names active on an account.

If the cache settings for APC are not sufficient, i.e. too low, a situation can result where the cache is continually re-populated by PHP code requirements & no speed-up results.

For best APC performance, increase the RAM allocation on your shared Linux plan where possible so that the server caching will not interfere with CMS processing.

Step Two: Edit the php.ini or apc.ini Configuration File

After installation, the administrator will have access to the apc.ini file for configuration settings. In shared hosting environments, it is possible to override this with php.ini.

In the apc.ini or php.ini file for the Drupal 8 installation, add the following lines:

apc.ttl=604800
apc.user_ttl=3600
apc.shm_size=256M
apc.include_once_override=1
auto_globals_jit=Off
apc.num_files_hint = 2048
apc.stat_ctime = 0
apc.file_update_protection = 2
apc.stat = 0

These settings will establish a 256 MB APC allocation for the PHP caching facility. Adjust as required for lower/higher values and review the cache timing variables.

Step Three: Copy apc.php file to Drupal Root for Analytics

In order to access analytics information about PHP performance & server resource usage, it is required to copy the apc.php file from the server to the Drupal root folder.

Drupal 8 does not have an integration module for APC, so it is required to run the apc.php file from the root of the installation rather than the /libraries folder.

Navigate to: /usr/share/pear/apc.php on the web server & copy the apc.php file to the root folder. Then open the page in a web browser at https://example.com/apc.php:

Drupal 8 administrators can access analytics information about the number of cached files/cache requests, amount of free memory, & total allocated RAM usage for APC.

Test the apc.ini settings in production or in a development sandbox with simulated chaos from high traffic patterns to see the performance rates under strain of use.

Step Four: Add Drupal 8 Modules for Cache Management

Memcached, APC, & Zend Opcache are the most popular PHP Accelerators for Drupal web hosting on a LAMP/WAMP environment but all target the PHP layer only.

Drupal 8 administrators need to build a multi-layer page caching strategy where the PHP process caching in augmented by HTML, CSS, & JavaScript caching in the CMS.

To do this make sure to install the Advanced CSS & JavaScript Aggregationmodule which will compress the final output of Drupal 8 web pages to anonymous users.

Drupal 8 Views can be cached for much faster delivery in production:

Additionally, Drupal 8 publishers on shared web hosting can consider a CDN (Content Delivery Network) as a means for additional caching & extending server resources.

Step Five: Build Full-Stack Caching Solutions for Drupal 8

For more advanced PHP Acceleration solutions for Drupal 8 consider HHVM (Hip Hop Virtual Machine), the PHP runtime engine developed by Facebook for faster speeds.

High-traffic Drupal 8 websites frequently implement NGINX, Varnish Cache, Redis, & Memcached to support enterprise-level web traffic of 10 million + monthly page views.

Running APC caching with PHP on the web server as a PECL Module adds an additional layer to the platform optimization that is required to support high traffic.

Conclusion: Run Drupal 8 & APC on VPS/Dedicated Plans

APC is an important component of full-stack web server optimization for PHP 7 acceleration and works best when there is extra RAM allocation to the installation.

Running APC with Drupal 8 can be problematic on cPanel web hosting plans because of limited RAM resources and multiple domains sharing the same IP Address.

Use APC with Drupal 8 on VPS & Dedicated server hosting plans for page speed optimization through better PHP caching, with Memcached, Varnish, NGINX, & Redis.

Check out these top 3 Drupal hosting services:

Kamatera
$4.00 /mo
Starting price
Visit Kamatera
Rating based on expert review
  • User Friendly
    3.5
  • Support
    3.0
  • Features
    3.9
  • Reliability
    4.0
  • Pricing
    4.3
Hostinger
$2.99 /mo
Starting price
Visit Hostinger
Rating based on expert review
  • User Friendly
    4.7
  • Support
    4.7
  • Features
    4.8
  • Reliability
    4.8
  • Pricing
    4.7
Ultahost
$2.90 /mo
Starting price
Visit Ultahost
Rating based on expert review
  • User Friendly
    4.3
  • Support
    4.8
  • Features
    4.5
  • Reliability
    4.0
  • Pricing
    4.8
  • Want to get top recommendations about best hosting? Just click this link!

How to Host Drupal 8 Websites with Varnish Cache on VPS Plans

This Tutorial will show how to install Varnish Cache on a VPS hosting plan to ru
7 min read
Jeffrey Scott
Jeffrey Scott
Hosting Expert

How to Optimize Drupal 8 Caching with Memcached on cPanel Hosting

This Tutorial will show how to improve Drupal 8 performance on shared hosting us
4 min read
Jeffrey Scott
Jeffrey Scott
Hosting Expert

How to Optimize Drupal for Google Pagespeed?

This tutorial helps Drupal 8 web publishers optimize page caching settings: comp
6 min read
Idan Cohen
Idan Cohen
Marketing Expert

How to Host Drupal 8 Websites with Redis on VPS Plans

This Tutorial will show how to install Redis on a VPS hosting plan to run a Drup
4 min read
Jeffrey Scott
Jeffrey Scott
Hosting Expert
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top