Apache2が起動できないとき

本記事では、Apache2をインストールし、その後、起動できないときどうすればよいかという記事になります。

OSは、Ubuntuです。

Apache2とは

Apacheとは、オープンソース(無料)のWebサーバーです。

昔からあるものの、今でもなお愛用され続けています。

レンタルサーバーで個人ブログを立ち上げる際、ほとんどの場合、ApacheのWebサーバーが使われます。

アップデートを繰り返し、現在はApache2が主流となっています。

起動できない事象

Apache2 をインストールし、

$ sudo apt install apache2

起動しようとすると

$ sudo systemctl start apache2.service

以下のようなエラーメッセージがでました。

Job for apache2.service failed because the control process exited with error code.
See "systemctl status apache2.service" and "journalctl -xe" for details.

systemctl status apache2.serviceを見ろとのこと

$ sudo systemctl status apache2.service
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: failed (dead) since Sat 2023-04-15 15:08:41 JST; 43s ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 469256 ExecStop=/usr/sbin/apachectl stop (code=exited, status=0/SUCCESS)
Main PID: 15981 (code=exited, status=0/SUCCESS)

Active: failedとなっており、起動できていません。

systemctl restart apache2.service としてもエラーとなります。

解決方法

2つの方法を紹介します。

1.nginxがactiveになっているか確認

nginxはWebサーバーの1つです。

sudo systemctl status nginx.serviceを実行。

$ sudo systemctl status nginx.service
● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running)  since Sat 2023-04-15 15:07:00 JST; 22s ago
       Docs: man:nginx(8)
    Process: 468398 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 468409 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)

Active: activeだった場合、

nginxを止めます。

$ sudo systemctl stop nginx.service

その後、apache2をリスタートします。

$ sudo systemctl restart apache2.service

apache2が起動できたか確認。

sudo systemctl status apache2.serviceを実行。

$ sudo systemctl status apache2.service
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (runnig) since Sat 2023-04-15 15:08:41 JST; 43s ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 469256 ExecStop=/usr/sbin/apachectl stop (code=exited, status=0/SUCCESS)
Main PID: 15981 (code=exited, status=0/SUCCESS)

Active: activeになっていれば、無事起動できています。

2.再度、インストール

apache2に必要なファイルが壊れている可能性があるので、再度インストールしましょう。

apache2をアンインストールします。

$ sudo apt remove apache2.service

そして再度インストール

$ sudo apt install apache2.service

apache2を起動します。

$ sudo systemctl start apache2

ache2が起動できたか確認。

sudo systemctl status apache2.serviceを実行。

$ sudo systemctl status apache2.service
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (runnig) since Sat 2023-04-15 15:08:41 JST; 43s ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 469256 ExecStop=/usr/sbin/apachectl stop (code=exited, status=0/SUCCESS)
Main PID: 15981 (code=exited, status=0/SUCCESS)

Active: activeになっていれば、無事起動できています。