DIMENSION 2.00

/ Nexus / Mac / Ubuntu / カメラ / beatmania / 猫 / 株 / 情報蒐集 /

VPSのApacheが動いてなかった件 → 解決

VPSDebian)のApacheが動いていなかったことに、今ごろ気づいた模様。

慌てて、Apache2のサービスを開始するも……

$ sudo service apache2 start
[sudo] password for esf:
Job for apache2.service failed. See 'systemctl status apache2.service' and 'journalctl -xn' for details.

見事にfailed.

とりあえず、状況が分からないので、言われた通りにしてみる。

$ systemctl status apache2.service
● apache2.service - LSB: Apache2 web server
   Loaded: loaded (/etc/init.d/apache2)
   Active: failed (Result: exit-code) since 水 2015-10-28 15:04:30 JST; 1min 57s ago
  Process: 1510 ExecStart=/etc/init.d/apache2 start (code=exited, status=1/FAILURE)

なるほど、分からん。

Apache2の設定ファイルは長いこと触れていないので、変な設定に変わってるはずは無いのだが、念のため設定ファイルのチェックをしてみることに。

$ apachectl configtest
apache2: Syntax error on line 275 of /etc/apache2/apache2.conf: Could not open configuration file /etc/apache2/conf.d/: No such file or directory
Action 'configtest' failed.
The Apache error log may have more information.

conf.d/ が無いよと怒られる。
そ、そんな馬鹿な、消した覚えはないぞ。

とりあえず確認してみる。

$ ll /etc/apache2
合計 96
-rw-r--r-- 1 root root 10060  8月 20  2013 apache2.conf
-rw-r--r-- 1 root root  7115  2月  1  2015 apache2.conf.dpkg-dist
drwxr-xr-x 2 root root  4096 10月  7 17:22 conf-available/
drwxr-xr-x 2 root root  4096  7月 10 16:45 conf-enabled/
-rw-r--r-- 1 root root    43  6月 19  2013 digest_file
-rw-r--r-- 1 root root  1782  2月  1  2015 envvars
-rw-r--r-- 1 root root 31063 10月 22  2012 magic
drwxr-xr-x 2 root root 12288 10月 28 04:36 mods-available/
drwxr-xr-x 2 root root  4096  7月 10 16:45 mods-enabled/
-rw-r--r-- 1 root root   320  2月  1  2015 ports.conf
drwxr-xr-x 2 root root  4096 10月  7 17:22 sites-available/
drwxr-xr-x 2 root root  4096  7月 10 16:45 sites-enabled/

うーん、確かに無い。
conf-enabled/ ってやつに名前が変わってる予感。

なので、apache2.conf の問題の275行目を書き換える。

#Include conf.d/
Include conf-enabled/

これでバッチリなはずだけど、念のためチェックしておこう。

$ apachectl configtest
AH00526: Syntax error on line 88 of /etc/apache2/apache2.conf:
Invalid ServerName "*:80" use ServerAlias to set multiple server names.
Action 'configtest' failed.
The Apache error log may have more information.


今度は別のエラーが出てきたw

apache2.conf を以下のように書き換えた。
hogehoge.com の部分は適宜自分のに変えて。

#ServerName *:80
ServerName hogehoge.com:80


これで大丈夫なはずなので、再びチェック。

$ apachectl configtest
AH00526: Syntax error on line 94 of /etc/apache2/apache2.conf:
Invalid command 'LockFile', perhaps misspelled or defined by a module not included in the server configuration
Action 'configtest' failed.
The Apache error log may have more information.

いやいやいや……
LockFileのオプション無くなったの??

これは解決策分からんので、調べてみたところ以下のサイトが参考になった。
Apache down after upgrade to Ubuntu 14.04 (Apache2 from 2.2 -> 2.4) | Nicholas TJ


とゆーわけで、以下のように書き換えた。

#LockFile ${APACHE_LOCK_DIR}/accept.lock
Mutex file:${APACHE_LOCK_DIR} default


さて、これで再びチェック。

$ apachectl configtest
Syntax OK

よーし、これで直った。

Apache2の起動と、

$ sudo service apache2 start

サービス開始したか確認

$ sudo netstat -lnput | grep apache2
tcp6    0    0 :::80      :::*     LISTEN   1824/apache2


これでめでたくトラブルシューティング完了。


ちなみにDebianのバージョン

$ cat /etc/debian_version
8.2


Apacheのバージョン

$ apache2 -v
Server version: Apache/2.4.10 (Debian)
Server built:   Aug 28 2015 16:28:08

もしかして、結構長いこと動いてなかったのか……

たまにはVPSの様子を見ないとダメだな。
そして技術も少しやっておかないと本気で勘が鈍る。