AC-5

某SEの雑記帳

Webサーバ構築(Apache)

      2015/08/10

Apacheのインストール

Webサーバー(Apache)はブラウザからWebサイトを見れるようにするためのサーバーです。

Apacheインストール~設定ファイル編集

[root@test]# yum -y install httpd←httpdインストール
[root@test]# service httpd start←httpd起動
httpd を起動中:                                            [  OK  ]

極論を言ってしまうと、これでApacheのインストールは完了しました。
ブラウザでサーバーのIPアドレスにアクセスすると、下記のようなテストページが確認できます。
WS000000

ただ、この状態ではphpや.htaccessなど使えないという点もあり、セキュリティ的にもよろしくない部分があるので設定ファイルを更新していきます。

[root@test]# cd /etc/httpd/conf/←httpd設定ファイルのあるディレクトリに移動します。
[root@test]#  cp httpd.conf httpd.conf.default←設定ファイルのバックアップをとっておきます
[root@test]#  vi httpd.conf←httpd設定ファイル編集
ServerTokens OS
↓
ServerTokens Prod ← エラーページ等でOS名を表示しないようにする

#ServerName www.example.com:80
↓
ServerName test.com:80 ←サーバー名を指定(ドメイン名: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.2/mod/core.html#options
# for more information.
#
    Options Indexes FollowSymLinks
  ↓
    Options Includes ExecCGI FollowSymLinks ←CGI,SSIの許可

#
# 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の許可

ServerSignature On
↓
ServerSignature Off ←エラーページでサーバー情報を表示しないようにする

AddDefaultCharset UTF-8
↓
#AddDefaultCharset UTF-8 ←コメントアウト(文字化け対応)

AddHandler cgi-script .cgi
↓
AddHandler cgi-script .cgi .pl ←CGIスクリプトに.plを追加

[root@test]# rm -f /etc/httpd/conf.d/welcome.conf←テストページ削除
[root@test]# rm -f /var/www/error/noindex.html←テストページ削除

Perlコマンドへ/usr/local/bin/perlでもアクセスできるようにする。

[root@test]# ln -s /usr/bin/perl /usr/local/bin/perl ←/usr/local/bin/perlから/usr/bin/perlへリンクをはる
[root@test]# whereis perl ← Perlのパスを確認
perl: /usr/bin/perl /usr/local/bin/perl /usr/share/man/man1/perl.1.gz ←Perlのパスに/usr/local/bin/perlが表示されることを確認

ドキュメントルート所有者変更

[root@test]# chown test. /var/www/html/ ←ドキュメントルート所有者とグループを変更(testは例のユーザ)
[root@test]# ll /var/www/ ←ドキュメントルート所有者変更確認
合計 16
drwxr-xr-x 2 root   root   4096 10月 16 23:49 2014 cgi-bin
drwxr-xr-x 3 root   root   4096  6月  2 11:59 2015 error
drwxr-xr-x 2 test   test   4096 10月 16 23:49 2014 html
drwxr-xr-x 3 root   root   4096  6月  2 11:59 2015 icons

Webサーバ起動

[root@test]# httpd -t←設定ファイルの構文チェック
Syntax OK←問題無い事を確認
[root@test]# /etc/rc.d/init.d/httpd start ← httpd起動
httpd を起動中:
[root@test]# chkconfig httpd on ← httpd自動起動設定(再起動しても自動で立ち上がるように)

phpのインストール

[root@test]# yum -y install php php-mbstring←phpインストール
[root@test]# service httpd restart←httpd起動
httpd を起動中:                                            [  OK  ]

 - Linux