LoginSignup
1
0

EC2でApache周りを触って勉強になった話

Posted at

会社で使用していたEC2がamazon linux1で2023年12月31日でEOLを迎えるので、それの移行対応をしていました。
その際に、apache周りを初めて触ってかなり手こずりましたが色々勉強になったので備忘録として残します。

Apacheの起動

まずEC2にssh接続します。
apacheを停止し、

$apachectl -k stop

もう一度apacheを起動

$apachectl -k graceful
実行結果
Job for httpd.service failed because the control process exited with error code.
See "systemctl status httpd.service" and "journalctl -xeu httpd.service" for details.

が出ました。警告通り systemctl status httpd.service をしても特にわからなかったので、

$apachectl configtest
実行結果
AH00526: Syntax error on line 18 of /etc/httpd/conf.d/ssl.conf:
Invalid command 'SSLPassPhraseDialog', perhaps misspelled or defined by a module not included in the server configuration

上記の結果になった。

調べたところ mod_ssl.so があるか確認する必要があったので下記を実行。

$find /etc/httpd/modules/ -name mod_ssl.so

結果的に見つからなかったので、mod_sslをインストール

$dnf -y install mod_ssl

もう一度 $find /etc/httpd/modules/ -name mod_ssl.so を実行すると、ちゃんとインストールされてました。

$apachectl configtest
実行結果
AH00526: Syntax error on line 422 of /etc/httpd/conf/httpd.conf:
Invalid command 'MinSpareServers', perhaps misspelled or defined by a module not included in the server configuration

調べてみると、MinSpareServers はServer MPMがpreforkで使われるよとのこと。
そこで、Server MPM を確認してみる。

$apachectl -V
実行結果
Architecture:   64-bit
Server MPM:     event
  threaded:     yes (fixed thread count)
    forked:     yes (variable process count)
Server compiled with....

amazon linux2023ではServer MPMがeventになっていたので、httpd.confの中に以下のように修正。

# MinSpareServers ←コメントアウト

もう一度確認。

$apachectl configtest
実行結果
AH00511: WARNING: MaxRequestWorkers of 4 is less than ThreadsPerChild of 25, increasing to 25. MaxRequestWorkers must be at least as large as the number of threads in a single server.
Syntax OK

ThreadsPerChild、ServerLimit、MaxRequestWorkersをhttpd.confの中に設定する。

こちらを追加
↓
<IfModule mpm_event_module>
    ThreadsPerChild 25
    ServerLimit 20
    MaxRequestWorkers 500
</IfModule>

もう一度確認

$apachectl configtest
実行結果
Syntax OK

やっと終わったので、apacheを再起動

$apachectl -k graceful

起動成功!!!

参考
https://qiita.com/marumasa/items/de2cbde0215fe8d20022
https://qiita.com/____easy/items/362d7e2c970afa1eb2bc
https://qiita.com/esparrago_b/items/4f368599aba1a059dbd1

1
0
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
1
0