Simply Fast WordPress [3] Techniques to Speed Up WordPress 540% with CentOS 7

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 part 3, I will explain how to speed up WordPress by 540% just by using the standard CentOS environment. --Kengyu Nakamura, Prime Strategy Co., Ltd.

In the previous article , we installed the PHP accelerator APC (Alternative PHP Cache) to get WordPress 250% faster.

Continuing with this article, we will use the standard repositories of CentOS 7 to speed up WordPress even more by accelerating the following:

1.    PHP execution time
2.    MySQL execution time
3.    Translation execution time
4.    HTTP response time

We will achieve 540% more speed by configuring Apache and the OS to be optimized without outside repositories or page caching.

WordPress Japanese version
WordPress Japanese version

Difference between OPCache and APC

APC uses a code cache feature to cash PHP intermediate code, and stores user cache in the memory as KVS (Key Value Store). Last article, we used the code cache feature to shorten the PHP execution time. This article, we will install another PHP accelerator, OPCache, to shorten that time even more.

OPCache is a high performance PHP accelerator that comes bundled with PHP since version 5.5, but you can also install it on 5.4. However, because OPCache does not utilize user cache, we will install APCu, which has the same features as APC. This user cache is important for optimizing the translation acceleration I will explain later.

By the way, you can not use APC with PHP versions later than 5.5. If you wish to use the features, you will need to install OPCache and APCu.

Now let's begin. This technique continues from previous tuning, so please refer to earlier articles to get to this point.

Install OPCache and APCu

Log in to your virtual machine via SSH and switch to the root user.

[centos@ip ~]$ sudo su -

Next, use the pecl command to install OPCache and APCu. APCu uses a wizard so generally just keep pressing Enter to continue.

# pecl install zendopcache-7.0.5
# pecl install apcu-4.0.10

You can utilize extensions with the pecl command to change the version. The above command will install the latest versions for both. If you want to check what the latest version is and what version of PHP it is compatible with, see the following sites:

Next, we will create apc.ini. Copy the following code to "/etc/php.d/apc.ini" and save.

[opcache]
zend_extension = /usr/lib64/php/modules/opcache.so
opcache.enable = 1
opcache.enable_cli = 1
opcache.memory_consumption = 128
opcache.interned_strings_buffer = 8
opcache.max_accelerated_files = 4000
opcache.blacklist_filename = /etc/php.d/opcache*.blacklist
[apcu]
extension = apcu.so
apc.enabled = 1
apc.enable_cli = 1
apc.shm_size = 64M
apc.mmap_file_mask = /tmp/apc.XXXXXX

Restart Apache to save the changes.

[root@ip ~]# systemctl restart httpd

Load the front page in your browser and refresh a few times to get the page load speed. In my environment it was 66ms.

Viewing the page load time with Firebug
Viewing the page load time with Firebug

Perform a benchmark test with ab.

[root@ip ~]# ab -n 100 -c 10 http://ec2-xxx.xxx.compute.amazonaws.com/

In my environment, requests per second was 30.51.

Tuning contents Page load time Requests per second
Default environment 176ms 11.24
APC 70ms (251%) 29.20
OPcache+APCu 66ms (266%) 30.51

With OPcache+APCu, we have improved performance 260% that of the default environment and 6% more than with APC.