ヘルプ:Webサーバー構築(Apache)(AlmaLinux9)
提供: すだちWiki
メインページ > ヘルプ:目次 > ヘルプ:自宅サーバー構築(AlmaLinux9) > Webサーバー構築(Apache)(AlmaLinux9)
概要
httpd をインストールしてWebサーバーを構築します。Webサーバー(Apache)はInternet Explorer等のブラウザからWebページをみれるようにするためのサーバーです。なお、HTTP は 80/TCP を使用します。
ここでは、ホームページスペース提供サービスを行っている一般的なWebサーバーと同様に以下のことができるようにする。
- CGIは任意のディレクトリで実行できるようにする。
- SSIは拡張子がshtmlのもののみ実行できるようにする。
- .htaccessを使用できるようにする。
- PHPを使用できるようにする。
Webサーバーインストール
httpdインストール
[root@host2 ~]# dnf -y install httpd
ウェルカムページはリネーム
[root@host2 ~]# mv /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/welcome.conf.org
Webサーバー設定
Webサーバー設定
[root@host2 ~]# vi /etc/httpd/conf/httpd.conf ← httpd設定ファイル編集
ServerAdmin root@localhost
↓
ServerAdmin ****@sudachi.jp ←管理者アドレス指定
#ServerName www.example.com:80
↓
ServerName awajp.com:80 ← サーバー名を指定
<Directory "/var/www/html">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs-2.0/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
↓
#Options Includes FollowSymLinks ← コメントアウト
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None
↓
AllowOverride All ← .htaccessの許可
AddDefaultCharset UTF-8
↓
#AddDefaultCharset UTF-8 ← コメントアウト(文字化け対応)
DirectoryIndex index.html
↓
DirectoryIndex index.html index.php index.cgi ← ディレクトリ名のみでアクセスできるファイル名を追加
# 最終行に追記
# サーバーの応答ヘッダ
ServerTokens Prod
[root@host2 ~]# vi /etc/httpd/conf.d/autoindex.conf ← autoindex設定ファイル編集
<Directory "/usr/share/httpd/icons">
Options Indexes MultiViews FollowSymlinks
↓
Options MultiViews ← iconsディレクトリのファイル一覧を表示しないようにする
AllowOverride None
Require all granted
</Directory>
ドキュメントルート所有者変更
[root@host2 ~]# chown sysop. /var/www/html/ ← ドキュメントルート所有者を変更 [root@host2 ~]# ll /var/www/ ← ドキュメントルート所有者変更確認 合計 0 drwxr-xr-x 2 root root 6 11月 20 06:43 cgi-bin drwxr-xr-x 2 sysop sysop 6 6月 10 2014 html
「httpd.conf」の文法チェック
[root@host2 ~]# apachectl configtest Syntax OK
Webサーバー起動
[root@host2 ~]# systemctl start httpd ← httpd起動 [root@host2 ~]# systemctl enable httpd ← httpd自動起動設定 Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
操作確認
[root@host2 ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2024-04-07 13:06:57 JST; 1min 16s ago
Docs: man:httpd.service(8)
Main PID: 6509 (httpd)
Status: "Running, listening on: port 80"
Tasks: 213 (limit: 26213)
Memory: 43.1M
CGroup: /system.slice/httpd.service
tq6509 /usr/sbin/httpd -DFOREGROUND
tq6510 /usr/sbin/httpd -DFOREGROUND
tq6511 /usr/sbin/httpd -DFOREGROUND
tq6512 /usr/sbin/httpd -DFOREGROUND
mq6513 /usr/sbin/httpd -DFOREGROUND
3月 08 13:06:57 host3.sudachi.jp systemd[1]: Starting The Apache HTTP Server...
3月 08 13:06:57 host3.sudachi.jp systemd[1]: Started The Apache HTTP Server.
3月 08 13:06:57 host3.sudachi.jp httpd[6509]: Server configured, listening on: port 80
