LoginSignup
161
160

More than 5 years have passed since last update.

Apache2.2の設定ファイルをApache2.4に移植するためにやったことまとめ

Last updated at Posted at 2015-05-23

Apache2.2からApache2.4 に移行する場合、設定ファイルをそのまま持ってきても動きません。
数日格闘したら解決できたのですが、
これからやる人が同じ苦労をしなくてすむようにノウハウを記録しておきます。

下記は、Apache2.2/CentOS6 から Apache2.4/CentOS7 に移行するための方法です。
他のディストリビューションでも似たようなものだと思います。

公式マニュアルを見ておきましょう

2.2 -> 2.4 アップグレードガイドがあります。

http://httpd.apache.org/docs/2.4/new_features_2_4.html
http://httpd.apache.org/docs/2.4/upgrading.html

ただ、すごく分かりにくいのと、CentOS固有(ディストリ固有)の情報は書いてないので、実際に動かしてエラーを1個ずつ解決していくしかなさそうです。

MPMが普通のモジュールになった

従来、MPMといえばコンパイル時に選択するものであって、後から変更はできなかったのですが、これが普通のモジュールと同じ扱いになったようです。
なので明示的にLoadModuleする必要があります。

mpm_preforkを使いたい場合

/etc/httpd/conf/httpd.conf
+LoadModule mpm_prefork_module modules/mod_mpm_prefork.so

mod_unixdが必要

User, Groupディレクティブを使うのに必要でした。

/etc/httpd/conf/httpd.conf
+LoadModule unixd_module modules/mod_unixd.so

mod_authn_aliasは別のモジュールに機能が移管された

Cannot load modules/mod_authn_alias.so into server

The functionality provided by mod_authn_alias in previous versions (i.e., the AuthnProviderAlias directive) has been moved into mod_authn_core.

よくわからんので設定削除しました。

/etc/httpd/conf/httpd.conf
-LoadModule authn_alias_module modules/mod_authn_alias.so

mod_authn_default, mod_authz_defaultは廃止になった

Cannot load modules/mod_authn_default.so into server
Cannot load modules/mod_authz_default.so into server 

これは公式マニュアルに明記してありました。

These modules have been removed: mod_authn_default, mod_authz_default, mod_mem_cache.

廃止されたのなら迷わず外します。

/etc/httpd/conf/httpd.conf
-LoadModule authn_default_module modules/mod_authn_default.so
-LoadModule authz_default_module modules/mod_authz_default.so

LDAPまわりで仕様変更?

Cannot load modules/mod_ldap.so into server

mod_ldap: LDAPTrustedClientCert is now consistently a per-directory setting only. If you use this directive, review your configuration to make sure it is present in all the necessary directory contexts.

よくわからん。そもそもLDAP機能使ってないのでモジュール外しました。

/etc/httpd/conf/httpd.conf
-LoadModule ldap_module modules/mod_ldap.so
-LoadModule authnz_ldap_module modules/mod_authnz_ldap.so

Order allow,deny系が仕様変更

ディレクトリやファイル単位でのアクセス制御の仕組みが大幅に変わったようです。

/etc/httpd/conf/httpd.conf
 <Files ~ "^\.ht">
-    Order allow,deny
-    Deny from all
+    Require all denied
 </Files>

これに関してはググれば記事がいっぱい出てくるので問題ないでしょう。

人間とウェブの未来 - Apache 2.4系でのモダンなアクセス制御の書き方

mod_ssl で後方互換壊れた?

SSLSessionCache, SSLMutexまわりでエラーが出ました。

 SSLPassPhraseDialog  builtin
-SSLSessionCache         shmcb:/var/cache/mod_ssl/scache(512000)
+#SSLSessionCache         shmcb:/var/cache/mod_ssl/scache(512000)
 SSLSessionCacheTimeout  300
-SSLMutex default
+#SSLMutex default

よくわかっていませんが、とり急ぎコメントアウトしたらエラーは消えました。
何かわかったら追記します。

MPMのディレクティブ名が変更

MaxRequestsPerChild has been renamed to MaxConnectionsPerChild, describes more accurately what it does. The old name is still supported.
MaxClients has been renamed to MaxRequestWorkers, which describes more accurately what it does. For async MPMs, like event, the maximum number of clients is not equivalent than the number of worker threads. The old name is still supported.

MaxClients → MaxRequestWorkers
MaxRequestsPerChild → MaxConnectionsPerChild

より実体に近い名前に変更になったとのことです。

/etc/httpd/conf/httpd.conf
-MaxClients 50
+MaxRequestWorkers 50

-MaxRequestsPerChild 1000
+MaxConnectionsPerChild 1000

一応古い名前でも警告が出るだけで動作はするようです。

DefaultTypeが無効に

The DefaultType directive no longer has any effect, other than to emit a warning if it's used with any value other than none. You need to use other configuration settings to replace it in 2.4.

書いても意味なくなったらしいので削除。

/etc/httpd/conf/httpd.conf
-DefaultType text/plain

NameVirtualHostが廃止

The NameVirtualHost directive no longer has any effect, other than to emit a warning. Any address/port combination appearing in multiple virtual hosts is implicitly treated as a name-based virtual host.

「Listenと何が違うんや」と思いながらおまじないだと思って設定していましたが、廃止されたようです。

歴史的にはVirtual HostにはIPベースと名前ベースの2方式があって、現在では名前ベースVirtual Hostしか使われてないのでそれに合わせたということ?みたいです(間違ってたらごめんなさい)

歴史的経緯については弾さんの記事がわかりやすいです。

404 Blog Not Found:IPアドレスはいつ枯渇してもおかしくない

元々Virtual Hostというのは、一つのホストに複数のIP Addressを割り当ててサービスを切り替えることを指していたが、IPアドレスがカツカツの現在では、複数のサーバーを単一のIPアドレスで運用するという、逆の目的のものを指すことが多い。この場合、サーバーの識別はホスト名で行われるが、全てのサービスでNamed Virtual Hostが使えるわけではない。例えばHTTPが正式対応したのは、Version 1.1からである。

要はNameVirtualHostイラネということで。

/etc/httpd/conf/httpd.conf
-NameVirtualHost *:80
-NameVirtualHost *:443

CentOS7ではmod_systemdが必要

/etc/httpd/conf/httpd.conf
+LoadModule systemd_module modules/mod_systemd.so

詳細はQiitaの別記事に書いたのでごらんください。

Apache2.4 on CentOS7 でsystemctl start httpdで起動しない問題の対象法

迷ったときは、素のOSにApache2.4をインストールして設定ファイルを眺めてみよう。

素のCentOS7にApache2.4をyum installしてその設定ファイルを根気よく読んで自分の設定ファイルと比較すれば、たいてい道は開けると思います。

以上全部対応したら、CentOS7/Apache2.4でPHPアプリがちゃんと動くようになりました!!11
\\\ ٩( ˘ω˘ )و ////

161
160
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
161
160