Simply Fast WordPress [5] 1000x Faster WordPress Tuning – PHP 5.6, OPCache, and APCu

This is a series of articles explaining how to speed up WordPress, the use of which is growing rapidly for CMS-based business sites and media sites. In the next few articles, I will offer techniques to tune WordPress’ speed by 1000x. --Kengyu Nakamura, Prime Strategy Co., Ltd.

In the previous articles we setup WordPress using CentOS 7 on Amazon Web Services (AWS) virtual cloud server Amazon Elastic Compute Cloud (Amazon EC2) and discovered techniques to speed up the site 5.4x faster. We only used repositories available from the standard CentOS 7 environment and configured gzip, Tuned, event MPM, and php-fpm.

In the next set of articles, we will speed up WordPress even more by using repositories outside of CentOS 7 and install PHP 5.6, PHP 7, HHVM (HipHop Virtual Machine), and Nginx to further tune our machine. This will all lead up to an Nginx+HHVM configuration that is 18x faster than the default environment without using page caching. Furthermore, we will achieve 1000x more performance in requests per second by adding Nginx’s FastCGI cache to enable page caching.

From here on, we will mostly be focused on requests per second rather than page load time. This is because as we continue to tune, we will no longer be able to overcome latency inherent in page load time, so measurement becomes less reliable.

WordPress Japanese version

WordPress Japanese version

Let’s continue. This technique continues from previous tuning, so please refer to earlier articles to get to this point.

Install PHP 5.6+OPCache+APCu

CentOS’s standard PHP execution environment is PHP 5.4. In this article we will download outside repositories to install PHP 5.6.

First, log in to your virtual machine via SSH and switch to the root user.

[centos@ip ~]$ sudo su -

Let’s remove the PHP 5.4 packages.

[root@ip ~]# yum remove php* -y

Install EPEL and Remi repositories needed for PHP 5.6, OPCache, and APCu.

[root@ip ~]# yum install epel-release -y
[root@ip ~]# rpm -ivh
[root@ip ~]# yum --enablerepo=remi,remi-php56 install php php-mysqlnd php-gd php-xml php-xmlrpc php-mbstring php-mcrypt php-fpm php-opcache php-apcu -y

“apc.ini” is still left over, so we will back up the file to ensure it doesn’t get overwritten.

The PHP settings file (/etc/php.ini), OPCache settings file (/etc/php.d/10- opcache.ini), and APCu settings file are already installed and configured (/etc/php.d/40-apcu.ini).

[root@ip ~]# mv /etc/php.d/apc.ini /etc/php.d/apc.ini.bak

Let’s set the timezone. Go to about the 889th line in “/etc/php.ini” and change the timezone to UTC.

; Defines the default timezone used by the date functions
date.timezone = UTC

With this, installation is finished. Use the php -v command to check the status and confirm there are no issues.

[root@ip ~]# php -v
PHP 5.6.20 (cli) (built: Mar 31 2016 07:17:10) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
[root@ip ~]# php -i | egrep 'apc|opcache'
Additional .ini files parsed => /etc/php.d/10-opcache.ini,/etc/php.d/40-apcu.ini,
MMAP File Mask => /tmp/apc.XXXXXX
apc.coredump_unmap => Off => Off
apc.enable_cli => Off => Off
apc.enabled => On => On
opcache.blacklist_filename => /etc/php.d/opcache*.blacklist => /etc/php.d/opcache*.blacklist
opcache.consistency_checks => 0 => 0
opcache.dups_fix => Off => Off
opcache.enable => On => On
opcache.enable_cli => Off => Off