LoginSignup
1
1

More than 3 years have passed since last update.

CentOS8 - Install - Apache

Last updated at Posted at 2020-01-02

Apacheインストール

// Apacheはhttpdというパッケージ名で公開
$ sudo yum install httpd
// 確認
$ httpd -version
Server version: Apache/2.4.37 (centos)
Server built:   Oct  7 2019 21:42:00
  • Apacheのインストールと同時に以下のディレクトリやファイルが自動作成
    • /etc/httpd/
    • /etc/sysconfig/httpd
    • /etc/logrotate.d/httpd
    • /usr/lib64/httpd/
    • /var/www/
    • /var/run/httpd/
    • /var/log/httpd/

起動と停止

// 状態確認
$ systemctl status httpd.service
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor pres>
   Active: inactive (dead)
     Docs: man:httpd.service(8)
  • 丸印が赤ならば停止状態
  • "Q"を押下して脱出
// 起動
$ systemctl start httpd.service

// 状態確認
$ systemctl status httpd.service
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor pres>
   Active: active (running) since Thu 2020-01-02 21:23:44 JST; 6s ago
     Docs: man:httpd.service(8)

(以下省略)
  • 丸印が緑ならば起動状態
// 停止
$ systemctl stop httpd.service

設定確認

// httpd.conf:設定ファイル
$ sudo vim /etc/httpd/conf/httpd.conf

(中略)

// ServerName
// 何かを設定した方がいいようだが、詳細不明
# ServerName www.example.com:80

(中略)

// ドキュメントルート(公開ディレクトリ)
// この配下に置いたディレクトリ・ファイルを公開
DocumentRoot "/var/www/html"

(中略)
  • 変更する必要がなければそのまま閉じてよい

テストページ作成

$ sudo vim /var/www/html/index.html
  • ドキュメントルート配下にテストページ用のファイルを新規作成
  • テストページ用のファイル名やコードは任意(以下は例)
    • ファイル名:index.html
    • 記述コード:This is test page.
  • 保存して終了

起動と確認

$ systemctl start httpd.service

自動起動設定と解除

// 自動起動の設定
$ sudo systemctl enable httpd.service
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

// 自動起動の確認
$ systemctl list-unit-files -t service
  • リスト内の以下の項目が enabled になっていれば自動起動状態
    • httpd.service
// 自動起動の解除
$ systemctl disable httpd.service
Removed /etc/systemd/system/multi-user.target.wants/httpd.service.
  • 自動起動したくなければ、自動起動を解除
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