1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Apache

Last updated at Posted at 2019-03-16

Apache インストール

[Red Hat Linux or CentOSで実施]

sudo yum -y install httpd

インストールに成功したかを確認する

pm -qa | grep httpd

httpd-2.4.6-88.el7.x86_64
httpd-tools-2.4.6-88.el7.x86_64

Apacheの状態を確認する。
まだ走っていないので、以下の出力が出てくるはず。

/bin/systemctl status httpd.service 

もしくは、

service httpd status

● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:httpd(8)
           man:apachectl(8)

Apache 走る

上記と同じコマンド'service'もしくは'/bin/systemctl'で走らせる。

service httpd start

もう一度Apacheの状態を確認する。

service httpd status

● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2019-03-16 05:07:50 UTC; 26s ago
     Docs: man:httpd(8)
           man:apachectl(8)

'Running'の単語が確認できればOK。

Apache Port 80

sudo netstat -tupan | grep -i httpd

ポートが80になっているのを確認できればOK。
なので、ユーザーからアクセスされるときは、http

Protocol Port
http 80
https 443

Apache Port 443 入れ方

sudo yum install mod_ssl

sudo netstat -tupan | grep -i httpd

ポート443が確認できるはず。
できなければサーバーの構築を見直す必要があるかも。

Config

# http::80 の設定ファイル
 ls /etc/httpd/conf/httpd.conf
# https::443 の設定ファイル
 ls /etc/httpd/conf.d/ssl.conf

vim コマンドで設定ファイルを読む/書く前に、以下のパッケージをインストールすることをオススメ。

sudo yum install vim vim-enhanced

ファイルが読みやすくなるから。

vim /etc/httpd/conf/httpd.conf

Configファイルの中身をちょっと見てみると、

キー デフォルト値 意味
ServerRoot /etc/httpd コンフィグ(設定)ファイルを見る場所
Listen 80 ポート番号
Include conf.modules.d/*.conf モジュールをい見る場所
User apache Apacheを走る時のユーザー
Group apache ユーザーが所属しているグループ名
ServerAdmin root@localhost Apacheがエラー表示を行う場合などに、問い合わせ先となる連絡先メールアドレス
DocumentRoot /var/www/html コンテンツを配置しておく場所。ユーザーのリクエストに対してコンテンツを返すがそのコンテンツの場所
ErrorLog logs/error_log エラーをログに保存するパスとファイル名
LogLevel warn エラーが起きた時、どのエラーレベルをもとにエラーログに記録するかの設定。詳細はこちら
IfModule 色々 もしあるmodulesが使われていた場合に実施する。詳細は以下を

Apache LogLevel テーブル

https://httpd.apache.org/docs/2.4/ja/mod/core.html#loglevel を参照

レベル 説明
emerg 緊急 - システムが利用できない Child cannot open lock file.
alert 直ちに対処が必要 getpwuid: couldn't determine user name from uid (getpwuid: UID からユーザ名を特定できなかった)
crit 致命的な状態 socket: Failed to get a socket, exiting child (socket: ソケットが得られないため、子プロセスを終了させた)
error エラー Premature end of script headers (スクリプトのヘッダが足りないままで終わった)
warn 警告 child process 1234 did not exit, sending another SIGHUP (子プロセス 1234 が終了しなかった。もう一度 SIGHUP を送る)
notice 普通だが、重要な情報 httpd: caught SIGBUS, attempting to dump core in ... (httpd: SIGBUS シグナルを受け、... へコアダンプをした)
info 追加情報 "Server seems busy, (you may need to increase StartServers, or Min/MaxSpareServers)..." (「サーバは負荷が高い、 (StartServers や Min/MaxSpareServers の値を増やす必要があるかも)」)
debug デバッグメッセージ "Opening config file ..." (設定ファイルを開いている...)

設定したレベル以上のエラーが起きた場合のみログに記録される。
例えばエラーレベルはDebugの場合、それ以上の事が起きればログに記録される。

Apache IfModules

Apacheはいくつかの機能をモジュールことに管理(保存/削除/読み込み)している。
場合によってはサーバーごとにApacheの使い方が違ってくると、modulesの管理が必須になってくる。
よって、設定ファイルで各モジュールに対する挙動をのせる必要があるが、
そんなに滅多に使わないと思う。。。

Apache Log読む

tail -f /var/log/httpd/access_log
1
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?