[Server & Network General] さくらのレンタルサーバで PHP 7.1 を利用して WordPress のパフォーマンス向上させる
さくらオススメの設定もあわせて確認する。
[markdown]
## PHP 7.1 の有効化
昨年末に「[さくらのレンタルサーバ PHP7.1 提供開始のお知らせ](https://www.sakura.ad.jp/news/sakurainfo/newsentry.php?id=1490)」がありました。
いつの間にか[WordPress の推奨動作環境も PHP 7 になっている](https://ja.wordpress.org/)ので対応します。
> [いつWordPressをPHP7にすべきか? – Capital P – WordPressメディア](https://capitalp.jp/2017/01/05/when-to-upgrade-php7/)
といってもコントロールパネルからバージョンを変更するだけです。
## プラグインのインストール
### WP Super Cache を外す
まず [WP Super Cache](https://ja.wordpress.org/plugins/wp-super-cache/) を外しました。
と言うのも
> [Topic: WP Super Cache causing problems in WordPress 4.7 « WordPress.org Forums](https://wordpress.org/support/topic/wp-super-cache-causing-problems-in-wordpress-4-7/)
>
> We’ll be careful with PHP 7.1 for now.
とのこと。
他にも運用に気を遣うことが多いので外してしまいます。
### さくらのレンタルサーバおすすめ
> [【クイックインストール】さくらのレンタルサーバ版WordPressの特長 – さくらのサポート情報](https://help.sakura.ad.jp/hc/ja/articles/206056602–%E3%82%AF%E3%82%A4%E3%83%83%E3%82%AF%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB-%E3%81%95%E3%81%8F%E3%82%89%E3%81%AE%E3%83%AC%E3%83%B3%E3%82%BF%E3%83%AB%E3%82%B5%E3%83%BC%E3%83%90%E7%89%88WordPress%E3%81%AE%E7%89%B9%E9%95%B7)
– Autoptimize … 入れました。
– Disable Google Fonts … Google Fonts を外したので入れない(追記: 2017/08/24 [対策が必要でした](https://www.d-wood.com/blog/2017/08/24_9220.html))。
– ImageMagick Engine … そもそも ImageOptim してからアップロードしているが試用してみる。
– Remove query strings from static resources … GTmetrix で怒られるやつです。
– Protect Uploads … パフォーマンスには関係ないが入れる。
– All In One WP Security & Firewall … SiteGuard WP Plugin を利用しているので保留。
それぞれインストール後、有効化と設定を行います。
## mod_deflate と mod_expire の設定
こちらによると「さくらのレンタルサーバのウェブサーバ(Apache)側でも、快適にご利用いただくための設定を適用しています。」とのことなので確認します。
> [【クイックインストール】さくらのレンタルサーバ版WordPressの特長 – さくらのサポート情報](https://help.sakura.ad.jp/hc/ja/articles/206056602–%E3%82%AF%E3%82%A4%E3%83%83%E3%82%AF%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB-%E3%81%95%E3%81%8F%E3%82%89%E3%81%AE%E3%83%AC%E3%83%B3%E3%82%BF%E3%83%AB%E3%82%B5%E3%83%BC%E3%83%90%E7%89%88WordPress%E3%81%AE%E7%89%B9%E9%95%B7)
“`:.htaccess
# BEGIN SAKURA Internet Inc.
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/x-javascript application/javascript application/ecmascript
ExpiresActive On
ExpiresDefault “access plus 1 week”
ExpiresDefault “access plus 1 month”
# END SAKURA Internet Inc.
“`
以前の設定を置き換えてしまいます。
> [Apache: mod_deflate, mod_expire でページの表示速度を改善する【設定編】 | deadwood](https://www.d-wood.com/blog/2016/05/19_8036.html)
## 結果
以前の結果と比較します。
> [WP Super Cache でページの表示速度を改善する | deadwood](https://www.d-wood.com/blog/2016/05/26_8078.html)
| | before | after |
|:——————–|:——-:|:——:|
| Requests per second | 2.89 | 51.44 |
| Time per request | 691.417 | 38.878 |
良さそうです。
“`prettyprinted
% ab -c 2 -n 100 https://www.d-wood.com/blog/2013/12/27_5159.html
This is ApacheBench, Version 2.3 <$Revision: 1748469 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.d-wood.com (be patient)…..done
Server Software: Apache/2.2.31
Server Hostname: www.d-wood.com
Server Port: 80
Document Path: /blog/2013/12/27_5159.html
Document Length: 256 bytes
Concurrency Level: 2
Time taken for tests: 1.944 seconds
Complete requests: 100
Failed requests: 0
Non-2xx responses: 100
Total transferred: 49500 bytes
HTML transferred: 25600 bytes
Requests per second: 51.44 [#/sec] (mean)
Time per request: 38.878 [ms] (mean)
Time per request: 19.439 [ms] (mean, across all concurrent requests)
Transfer rate: 24.87 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 16 18 2.0 18 25
Processing: 17 20 2.9 20 34
Waiting: 17 20 2.8 20 34
Total: 34 39 4.0 38 55
Percentage of the requests served within a certain time (ms)
50% 38
66% 40
75% 41
80% 41
90% 45
95% 47
98% 53
99% 55
100% 55 (longest request)
“`
> [【初心者向け】ApacheBench入門 | Developers.IO](http://dev.classmethod.jp/tool/ab-tutorial/)
[/markdown]