きっとブログ
466 words
2 minutes
SecRuleEngineが原因でApacheを起動できないときの解決方法

はじめに#

WordPressをインストールしているときにApacheの設定でつまずいたので、原因と解決方法を共有します!

エラーの原因#

Apacheを再起動しようとするとエラーを吐きました。

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

systemctl status apache2.serviceでApacheの状態を確認してみます。

$ systemctl status apache2.service
× apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sat 2023-02-11 15:11:05 UTC; 1min 16s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 924372 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE)
        CPU: 22ms

systemd[1]: Starting The Apache HTTP Server...
apachectl[924375]: AH00526: Syntax error on line 7 of /etc/apache2/sites-enabled/wordpress.conf:
apachectl[924375]: Invalid command 'SecRuleEngine', perhaps misspelled or defined by a module not included in the server configuration
apachectl[924372]: Action 'start' failed.
apachectl[924372]: The Apache error log may have more information.
systemd[1]: apache2.service: Control process exited, code=exited, status=1/FAILURE
systemd[1]: apache2.service: Failed with result 'exit-code'.
systemd[1]: Failed to start The Apache HTTP Server.

大事なのは、以下の一文でした。

Invalid command 'SecRuleEngine', perhaps misspelled or defined by a module not included in the server configuration

今回はSecRuleEngineを使うためのモジュールがインストールされていないのが原因でした。

解決方法#

mod_securityモジュールをインストールします。

sudo apt install libapache2-mod-security2

次に、mod_securityモジュールを有効化します。

$ sudo a2enmod security2
Considering dependency unique_id for security2:
Module unique_id already enabled
Module security2 already enabled

Apacheを再起動して状態を確認してみます。

$ sudo systemctl restart apache2
$ systemctl status apache2.service
 apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2023-02-11 15:30:30 UTC; 4s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 925150 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 925154 (apache2)
      Tasks: 6 (limit: 28701)
     Memory: 35.4M
        CPU: 180ms
     CGroup: /system.slice/apache2.service
             ├─925154 /usr/sbin/apache2 -k start
             ├─925155 /usr/sbin/apache2 -k start
             ├─925156 /usr/sbin/apache2 -k start
             ├─925157 /usr/sbin/apache2 -k start
             ├─925158 /usr/sbin/apache2 -k start
             └─925159 /usr/sbin/apache2 -k start

systemd[1]: Starting The Apache HTTP Server...
apachectl[925153]: AH00558: apache2: Could not reliably determine the server\'s fully qualified domain name, using 127.0.1.1. Set the 'ServerName'>
systemd[1]: Started The Apache HTTP Server.

無事再起動できました。

おわりに#

今回は以上です。

お読みいただきありがとうございました!