仮想マシンなどに、CentOS7をインストールして、VirtualHostを設定して
いざ httpd(apache)を起動させようとすると、エラーで起動できないことがあります。
なお、apachectl configtest では、syntax OK となっています。
エラーの内容
systemctl start httpd
Job for httpd.service failed because the control process exited with error code. See “systemctl status httpd.service” and “journalctl -xe” for details.
journalctl -xeの内容
— Subject: Unit httpd.service has begun start-up
— Defined-By: systemd
— Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
— Unit httpd.service has begun starting up.
9月 08 17:18:23 test.reyfox.lo systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
9月 08 17:18:23 test.reyfox.lo kill[16284]: kill: cannot find process “”
9月 08 17:18:23 test.reyfox.lo systemd[1]: httpd.service: control process exited, code=exited status=1
9月 08 17:18:23 test.reyfox.lo systemd[1]: Failed to start The Apache HTTP Server.
— Subject: Unit httpd.service has failed
/var/log/httpd/error_log を見てみる
(13)Permission denied: AH00091: httpd: could not open error log file /var/www/test/logs/error.log.
AH00015: Unable to open logs
つまり、上記内容から、Apacheがログファイルに書き込めないということがわかります。
しかし、/var/www/test/logs/ディレクトリは存在し、ディレクトリ権限も root です。
対処方法
いろいろ調べた結果、SELinuxが原因のようです。
SELinuxを無効化することにより解決します。
SELinuxの無効化方法
コマンドラインから即時無効にする
setenforce 0
起動時に無効にする
/etc/selinux/config に SELINUX=disabled
とする。
これを行った後、 systemctl start httpd で起動するようになりました。
なお、この問題は、仮想マシンのクリーンなCentOS7のインストールの場合のみで、
VPSなどのサービスでは基本的にSELinuxではデフォルトで無効化されています。
ローカルからしかアクセスしない場合(ルータでブロックしてる場合など)は、firewalld も不要なので、
systemctl stop firewalld
systemctl disable firewalld
などして止めてしまうと良いでしょう。