CentOS 7の標準環境だけですぐできる、WordPress「5.4倍高速化」テクニック 後編:とにかく速いWordPress(4)(2/3 ページ)
エンタープライズ用途での利用が増えている「WordPress」の高速化について解説する本連載。今回はCentOS 7の標準環境でWordPressを「5.4倍まで高速化」するテクニックの後編をお届けします。
Apacheを「event MPM+php-fpm」構成に変更する
最後に、今回のチューニングの総仕上げとなる作業をしましょう。Apacheの構成を「prefork MPM+mod_php」構成から、「event MPM+php-fpm」構成に変更することで、さらなる最適化が図れます。
従来、Apacheの主流となるマルチプロセッシングモジュールは「prefork MPM」でしたが、Apache 2.4から「event MPM」が選択できるようになりました。event MPMは、fast cgi方式のphp-fpmと組み合わせることによって、従来のprefork MPM+mod_phpの組み合わせに比べて、メモリ使用量を大きく減らし、同時接続数増加時のパフォーマンス劣化も抑えられるメリットを得られるようになります。
イメージとしては、軽量高速で近年シェアを伸ばしているWebサーバの「Nginx(エンジンエックス)」に近いものです。Apacheがもともと持っている豊富なモジュールや.htaccessによる柔軟な設定制御などのメリットはそのままに、パフォーマンスが大幅に向上しますので、この構成は「新しいApache」といっても過言ではないと思います。
では、具体的に設定していきましょう。まず、php-fpmを導入し、実行します。
[root@ip plugins]# yum install php-fpm -y [root@ip plugins]# systemctl enable php-fpm [root@ip plugins]# systemctl start php-fpm
次に、Apacheの設定ファイルを変更します。変更するファイルは「/etc/httpd/conf.modules.d/00-mpm.conf」「/etc/httpd/conf.d/php.conf」「/etc/httpd/conf/httpd.conf」の3つです。
# Select the MPM module which should be used by uncommenting exactly # one of the following LoadModule lines: # prefork MPM: Implements a non-threaded, pre-forking web server # See: http://httpd.apache.org/docs/2.4/mod/prefork.html #LoadModule mpm_prefork_module modules/mod_mpm_prefork.so # worker MPM: Multi-Processing Module implementing a hybrid # multi-threaded multi-process web server # See: http://httpd.apache.org/docs/2.4/mod/worker.html # #LoadModule mpm_worker_module modules/mod_mpm_worker.so # event MPM: A variant of the worker MPM with the goal of consuming # threads only for connections with active processing # See: http://httpd.apache.org/docs/2.4/mod/event.html # LoadModule mpm_event_module modules/mod_mpm_event.so
<IfModule prefork.c>
#
# Cause the PHP interpreter to handle files with a .php extension.
#
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
#
# Allow php to handle Multiviews
#
AddType text/html .php
#
# Add index.php to the list of files that will be served as directory
# indexes.
#
DirectoryIndex index.php
#
# Uncomment the following lines to allow PHP to pretty-print .phps
# files as PHP source code:
#
#<FilesMatch \.phps$>
# SetHandler application/x-httpd-php-source
#</FilesMatch>
#
# Apache specific PHP configuration options
# those can be override in each configured vhost
#
php_value session.save_handler "files"
php_value session.save_path "/var/lib/php/session"
</IfModule>
(略)
#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
(略)
# Supplemental configuration
#
# Load config files in the "/etc/httpd/conf.d" directory, if any.
IncludeOptional conf.d/*.conf
# gzip setting
AddOutputFilterByType DEFLATE text/html text/plain text/css
AddOutputFilterByType DEFLATE text/javascript application/x-javascript application/javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# expire setting
ExpiresActive On
ExpiresDefault "access plus 600 seconds"
ExpiresByType text/html "access plus 10 seconds"
# event MPM setting
<IfModule mpm_event_module>
StartServers 2
MinSpareThreads 25
MaxSpareThreads 50
ThreadsPerChild 50
MaxRequestWorkers 50
MaxConnectionsPerChild 0
<FilesMatch \.php$>
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>
</IfModule>
Apacheを再起動して設定を反映させます。
[root@ip plugins]# systemctl restart httpd
筆者の環境では、ページのロード時間が33ms、Requests per secondは60.79となり、さらに約5%のパフォーマンス向上を果たせました。
Copyright © ITmedia, Inc. All Rights Reserved.
関連記事
さっくり理解するPHP 5.5の言語仕様と「いい感じ」の使い方
PHP 5.5.0が公開されました。オペコードキャッシュやジェネレータなど、言語仕様としても実行エンジンとしても挑戦的な内容が含まれています。
WordPress自体のチューニングが必要な理由と高速化の基本的な考え方
企業のCMSサイトやオウンドメディアなどエンタープライズ用途での利用が増加しているWordPressの高速化について解説する連載。初回は、WordPressの高速化が求められる背景や、WordPress高速化の基本的な考え方であるページのロード時間とその構成要素、1秒当たりの同時アクセス数について解説します。
ここが変わったCentOS 7──「新機能の概要とインストール」編
「CentOS 7」を皆さんどれだけ理解していますでしょうか。CentOS 7は、以前のバージョンから使い勝手がかなり変わりました。本連載では、今さら聞けない/おさらいしたいというインフラエンジニアに向け、CentOS 7の概要と基礎から活用Tipsまでを紹介していきます。
安いホスティングに引っ越しって簡単にいうけど 〜リモートアクセスにはSSHを使いましょう〜
安いホスティング先に、メールサーバと社外向けWebサーバが引っ越した。Web画面のリモート設定でいらいらする律子さん。使い慣れたtelnetではアクセスできず……
Webのバグを燃やしまくるFirebugと、そのアドオン7選
httpd.confによるWebサーバの最適化
Webサーバのチューニングには、いくつかの段階がある。今回は、httpd.confの修正によるApacheの最適化について説明する。(編集部)
Apacheパフォーマンス・チューニングのポイント
Apacheをチューニングすることにより、Webサイトのパフォーマンスをより向上させることができる。しかし、その前に何をチューニングすべきなのかを見極める必要がある。
Apacheパフォーマンス・チューニングの実践
前回、ボトルネックになり得るポイントの検討やベンチマークツール「ab」によるパフォーマンス・チェック方法を紹介した。今回はそれらを基に、Apacheのチューニングを行っていく。
MySQLの高度な管理とチューニングテクニック
本連載もついに最終回。今回はMySQLサーバの運用・管理に必要な状態監視、チューニング、バックアップ、セキュリティについて解説する。以下のテクニックを駆使すれば、MySQLをさらに安定稼働させられるだろう。
安全を考えてPHPの実行時設定を調整する
PHPを初期設定のまま使うと、いろいろ問題が起こる可能性があります。今回は、問題の発生を未然に防ぐ設定法をいくつか紹介します。(編集部)