自宅のWebサーバーのチューニングをしようとApacheのmod_mem_cacheの設定をしようとしたのですが、Scientific Linux 6のyumでインストールしたApacheはmod_mem_cacheに対応しないようです。
きっとmod_mem_cacheに致命的な問題でもあるのでしょうね。
別のチューニングを考えたいと思います。
自宅のWebサーバーのチューニングをしようとApacheのmod_mem_cacheの設定をしようとしたのですが、Scientific Linux 6のyumでインストールしたApacheはmod_mem_cacheに対応しないようです。
きっとmod_mem_cacheに致命的な問題でもあるのでしょうね。
別のチューニングを考えたいと思います。
今回はさらにセキュリティを向上するためにSSLを導入したいと思います。
メールサーバーのSSL証明書を作成する時にも実施しましたが下準備を行います。
# 設定ファイルを作業用ディレクトリにコピーします
[root@sl6 tls]# cp openssl.cnf ./www
[root@sl6 tls]# cd www
# 作業用ディレクトリの内容を確認しておきます
[root@sl6 www]# ls -la
合計 20
drwxr-xr-x. 2 root root 4096 6月 22 12:16 2011 .
drwxr-xr-x. 7 root root 4096 6月 22 12:16 2011 ..
-rw-r--r--. 1 root root 10906 6月 22 12:16 2011 openssl.cnf
# コピーしてきたopenssl.cnfファイルがあることを確認します
# 設定ファイルを編集します
[root@sl6 www]# vi openssl.cnf
# 42行目~44行目、48行目、55行目~56行目を修正します
dir = . # Where everything is kept # /etc/pki/CA から . に変更
certs = $dir # Where the issued certs are kept # $dir/certs から $dir に変更
crl_dir = $dir # Where the issued crl are kept # $dir/crl から $dir に変更
new_certs_dir = $dir # default place for new certs. # $dir/newcerts から $dir に変更
private_key = $dir/cakey.pem # The private key # $dir/private/cakey.pem から $dir/cakey.pem に変更
RANDFILE = $dir/.rand # private random number file # $dir/private/.rand から $dir/.rand に変更
# 保存してviエディタを終了します
# index.txtという空ファイルと01と書き込んだserialファイルを作成します
[root@sl6 www]# touch index.txt
[root@sl6 www]# echo 01 > serial
# 作業用ディレクトリの内容を確認しておきます
[root@sl6 www]# ls -la
合計 24
drwxr-xr-x. 2 root root 4096 6月 22 12:18 2011 .
drwxr-xr-x. 7 root root 4096 6月 22 12:16 2011 ..
-rw-r--r--. 1 root root 0 6月 22 12:18 2011 index.txt
-rw-r--r--. 1 root root 10867 6月 22 12:18 2011 openssl.cnf
-rw-r--r--. 1 root root 3 6月 22 12:18 2011 serial
# index.txtファイルとserialファイルがあることを確認します
認証局の秘密鍵を作成します。
# 作業用ディレクトリの内容を確認しておきます
[root@sl6 www]# ls -la
合計 28
drwxr-xr-x. 2 root root 4096 6月 22 12:19 2011 .
drwxr-xr-x. 7 root root 4096 6月 22 12:16 2011 ..
-rw-r--r--. 1 root root 963 6月 22 12:19 2011 cakey.pem
-rw-r--r--. 1 root root 0 6月 22 12:18 2011 index.txt
-rw-r--r--. 1 root root 10867 6月 22 12:18 2011 openssl.cnf
-rw-r--r--. 1 root root 3 6月 22 12:18 2011 serial
# 認証局の秘密鍵ファイル[cakey.pem]が作成されたことを確認します
「2.認証局の秘密鍵作成」で作成した認証局の秘密鍵ファイルを使って認証局の証明書を作成します。
# 作業用ディレクトリの内容を確認しておきます
[root@sl6 www]# ls -la
合計 32
drwxr-xr-x. 2 root root 4096 6月 22 12:21 2011 .
drwxr-xr-x. 7 root root 4096 6月 22 12:16 2011 ..
-rw-r--r--. 1 root root 944 6月 22 12:21 2011 cacert.pem
-rw-r--r--. 1 root root 963 6月 22 12:19 2011 cakey.pem
-rw-r--r--. 1 root root 0 6月 22 12:18 2011 index.txt
-rw-r--r--. 1 root root 10867 6月 22 12:18 2011 openssl.cnf
-rw-r--r--. 1 root root 3 6月 22 12:18 2011 serial
# 認証局の証明書ファイル[cacert.pem]が作成されたことを確認します
サーバー秘密鍵を作成します。
# メールサーバーにSSLでアクセスした時に毎回パスフレーズを聞かれないようにパスフレーズ付きサーバー秘密鍵を作成します
[root@sl6 www]# openssl rsa -in ./server.key -out ./server.key
Enter pass phrase for ./server.key: server.keyファイル作成時のパスフレーズ入力
writing RSA key
# 作業用ディレクトリの内容を確認しておきます
[root@sl6 www]# ls -la
合計 36
drwxr-xr-x. 2 root root 4096 6月 22 12:21 2011 .
drwxr-xr-x. 7 root root 4096 6月 22 12:16 2011 ..
-rw-r--r--. 1 root root 944 6月 22 12:21 2011 cacert.pem
-rw-r--r--. 1 root root 963 6月 22 12:19 2011 cakey.pem
-rw-r--r--. 1 root root 0 6月 22 12:18 2011 index.txt
-rw-r--r--. 1 root root 10867 6月 22 12:18 2011 openssl.cnf
-rw-r--r--. 1 root root 3 6月 22 12:18 2011 serial
-rw-r--r--. 1 root root 887 6月 22 12:21 2011 server.key
# サーバー秘密鍵ファイル[server.key]が作成されたことを確認します
「4.サーバー秘密鍵作成」で作成したサーバー秘密鍵ファイルを使ってサーバー証明要求書を作成します。
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []: 入力せずEnter
An optional company name []: 入力せずEnter
# 作業用ディレクトリの内容を確認しておきます
[root@sl6 www]# ls -la
合計 40
drwxr-xr-x. 2 root root 4096 6月 22 12:22 2011 .
drwxr-xr-x. 7 root root 4096 6月 22 12:16 2011 ..
-rw-r--r--. 1 root root 944 6月 22 12:21 2011 cacert.pem
-rw-r--r--. 1 root root 963 6月 22 12:19 2011 cakey.pem
-rw-r--r--. 1 root root 0 6月 22 12:18 2011 index.txt
-rw-r--r--. 1 root root 10867 6月 22 12:18 2011 openssl.cnf
-rw-r--r--. 1 root root 3 6月 22 12:18 2011 serial
-rw-r--r--. 1 root root 639 6月 22 12:22 2011 server.csr
-rw-r--r--. 1 root root 887 6月 22 12:21 2011 server.key
# サーバー証明要求書ファイル[server.csr]が作成されたことを確認します
サーバー証明要求書ファイルに書名を行い、サーバー証明書を作成します。
Using configuration from ./openssl.cnf
Enter pass phrase for ./cakey.pem: cakey.pemのパスフレーズを入力します
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number: 1 (0x1)
Validity
Not Before: Jun 22 03:23:28 2011 GMT
Not After : Jun 19 03:23:28 2021 GMT
Subject:
countryName = JP
stateOrProvinceName = chiba
organizationName = sa-sa-ki.jp
commonName = www.sa-sa-ki.jp
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Key Identifier:
xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx
X509v3 Authority Key Identifier:
keyid:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx
Certificate is to be certified until Jun 19 03:23:28 2021 GMT (3650 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
# 作業用ディレクトリの内容を確認しておきます
[root@sl6 www]# ls -la
合計 60
drwxr-xr-x. 2 root root 4096 6月 22 12:23 2011 .
drwxr-xr-x. 7 root root 4096 6月 22 12:16 2011 ..
-rw-r--r--. 1 root root 3039 6月 22 12:23 2011 01.pem
-rw-r--r--. 1 root root 944 6月 22 12:21 2011 cacert.pem
-rw-r--r--. 1 root root 963 6月 22 12:19 2011 cakey.pem
-rw-r--r--. 1 root root 76 6月 22 12:23 2011 index.txt
-rw-r--r--. 1 root root 21 6月 22 12:23 2011 index.txt.attr
-rw-r--r--. 1 root root 0 6月 22 12:18 2011 index.txt.old
-rw-r--r--. 1 root root 10867 6月 22 12:18 2011 openssl.cnf
-rw-r--r--. 1 root root 3 6月 22 12:23 2011 serial
-rw-r--r--. 1 root root 3 6月 22 12:18 2011 serial.old
-rw-r--r--. 1 root root 3039 6月 22 12:23 2011 server.cer
-rw-r--r--. 1 root root 639 6月 22 12:22 2011 server.csr
-rw-r--r--. 1 root root 887 6月 22 12:21 2011 server.key
# サーバー証明書ファイル[server.cer]が作成されたことを確認します
# 各ファイルをrootユーザ読み取り専用に権限を変更します
[root@sl6 www]# chmod 400 *
# 作業用ディレクトリの内容を確認しておきます
[root@sl6 www]# ls -la
合計 60
drwxr-xr-x. 2 root root 4096 6月 22 12:23 2011 .
drwxr-xr-x. 7 root root 4096 6月 22 12:16 2011 ..
-r--------. 1 root root 3039 6月 22 12:23 2011 01.pem
-r--------. 1 root root 944 6月 22 12:21 2011 cacert.pem
-r--------. 1 root root 963 6月 22 12:19 2011 cakey.pem
-r--------. 1 root root 76 6月 22 12:23 2011 index.txt
-r--------. 1 root root 21 6月 22 12:23 2011 index.txt.attr
-r--------. 1 root root 0 6月 22 12:18 2011 index.txt.old
-r--------. 1 root root 10867 6月 22 12:18 2011 openssl.cnf
-r--------. 1 root root 3 6月 22 12:23 2011 serial
-r--------. 1 root root 3 6月 22 12:18 2011 serial.old
-r--------. 1 root root 3039 6月 22 12:23 2011 server.cer
-r--------. 1 root root 639 6月 22 12:22 2011 server.csr
-r--------. 1 root root 887 6月 22 12:21 2011 server.key
# 全ファイルの権限が読み取りのみになっていることを確認しておきます
作成したサーバー証明書ファイル使ってSSL通信できるようにApacheの設定ファイルを変更します。
# General setup for the virtual host, inherited from global configuration
DocumentRoot "/var/www/html" # コメント解除
ServerName www.sa-sa-ki.jp:443 # コメント解除とドメイン名をwww.example.comからwww.sa-sa-ki.jpに変更
**************** 以下追加 ****************
#
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
#
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
#
# For a single logfile with access, agent, and referer information
# (Combined Logfile Format), use the following directive:
#
CustomLog logs/ssl_access_log combined
**************** 以下追加終わり ****************
# Server Certificate:
# Point SSLCertificateFile at a PEM encoded certificate. If
# the certificate is encrypted, then you will be prompted for a
# pass phrase. Note that a kill -HUP will prompt again. A new
# certificate can be generated using the genkey(1) command.
SSLCertificateFile /etc/pki/tls/www/server.cer #/etc/pki/tls/certs/localhost.crtから/etc/pki/tls/www/server.cerに変更
# Server Private Key:
# If the key is not combined with the certificate, use this
# directive to point at the key file. Keep in mind that if
# you've both a RSA and a DSA private key you can configure
# both in parallel (to also allow the use of DSA ciphers, etc.)
SSLCertificateKeyFile /etc/pki/tls/www/server.key # /etc/pki/tls/private/localhost.keyから/etc/pki/tls/www/server.keyに変更
# 保存してviエディタを終了します
Apacheを再起動して設定ファイルを反映します
[root@sl6 www]# /etc/rc.d/init.d/httpd restart
httpd を停止中: [ OK ]
httpd を起動中: [ OK ]
HTTPSのポート番号のアクセス許可設定を行います。
# 保存してviエディタを終了します
# iptablesを再起動して設定を反映します
[root@sl6 www]# /etc/rc.d/init.d/iptables restart
iptables: ファイアウォールルールを消去中: [ OK ]
iptables: チェインをポリシー ACCEPT へ設定中filter [ OK ]
iptables: モジュールを取り外し中: [ OK ]
iptables: ファイアウォールルールを適用中: [ OK ]
ルータがない場合は不要な手順になりますが、yasuの家にはCTUとサーバーの間にルータがありますので併せてNAT設定で443番ポートをサーバーに向けます。
設定方法はルータの設定手順に従ってください。
■関連記事
Scientific Linux 6で自宅サーバー構築 その1 サーバー機Express 5800 GT110bのオンボードRAIDでRAID1設定
Scientific Linux 6で自宅サーバー構築 その2 Scientific Linux 6をExpress5800/GT110bにインストール
Scientific Linux 6で自宅サーバー構築 その3 Scientific Linux 6インストール後の初期設定
Scientific Linux 6で自宅サーバー構築 番外編その1 Scientific Linux 6のcronについて
Scientific Linux 6で自宅サーバー構築 その4 Scientific Linux 6 にClamAVをインストールしてウィルス対策
Scientific Linux 6で自宅サーバー構築 その5 Scientific Linux 6 にTripwireをインストールしてファイル改ざんを検知する
Scientific Linux 6で自宅サーバー構築 その6 Scientific Linux 6 にchkrootkitをインストールしてrootkit感染を検知する
Scientific Linux 6で自宅サーバー構築 その7 NTPサーバーで自動時刻合わせ
Scientific Linux 6で自宅サーバー構築 その8 バッファオーバーフロー攻撃対策を行う
Scientific Linux 6で自宅サーバー構築 その9 logwatchでサーバー監視
Scientific Linux 6で自宅サーバー構築 その10 DNSサーバーを構築
Scientific Linux 6で自宅サーバー構築 番外編その2 Scientific Linuxを6.0から6.1にアップグレードする
Scientific Linux 6で自宅サーバー構築 その11 PostfixとDovecotとSMTP-AUTHでメールサーバーを構築する
Scientific Linux 6で自宅サーバー構築 その12 メールサーバーにSSLを導入する
Scientific Linux 6で自宅サーバー構築 その13 Apache PHP MySQLをインストール
Scientific Linux 6で自宅サーバー構築 その14 WebサーバーにSSLを導入する
Scientific Linux 6で自宅サーバー構築 その15 WordPressを導入する
Scientific Linux 6で自宅サーバー構築 その16 Piwikでアクセスログ集計
Scientific Linux 6で自宅サーバー構築 その17 Squidをインストール
Scientific Linux 6で自宅サーバー構築 その18 sshで鍵認証を導入
Scientific Linux 6で自宅サーバー構築 その19 WebDavの設定
Scientific Linux 6で自宅サーバー構築 その20 lm_sensorをインストール
今回はWebサーバとDatabaseサーバをインストール・設定していきます。
Apache、PHP、MySQL、関連パッケージをインストールします。
Dependencies Resolved
============================================================
Package Arch Version Repository Size
============================================================
Installing:
httpd x86_64 2.2.15-5.sl6 sl 810 k
mod_ssl x86_64 1:2.2.15-5.sl6 sl 84 k
mysql-server x86_64 5.1.52-1.el6_0.1 sl-security 8.1 M
php x86_64 5.3.2-6.el6_0.1 sl-security 1.1 M
php-gd x86_64 5.3.2-6.el6_0.1 sl-security 102 k
php-mbstring x86_64 5.3.2-6.el6_0.1 sl-security 503 k
php-mysql x86_64 5.3.2-6.el6_0.1 sl-security 75 k
Installing for dependencies:
apr x86_64 1.3.9-3.el6_1.2 sl-security 122 k
apr-util x86_64 1.3.9-3.el6_0.1 sl-security 86 k
apr-util-ldap x86_64 1.3.9-3.el6_0.1 sl-security 15 k
httpd-tools x86_64 2.2.15-5.sl6 sl 67 k
libXpm x86_64 3.5.8-2.el6 sl 58 k
mailcap noarch 2.1.31-1.1.el6 sl 26 k
mysql x86_64 5.1.52-1.el6_0.1 sl-security 888 k
perl-DBD-MySQL x86_64 4.013-3.el6 sl 133 k
perl-DBI x86_64 1.609-4.el6 sl 704 k
php-cli x86_64 5.3.2-6.el6_0.1 sl-security 2.2 M
php-common x86_64 5.3.2-6.el6_0.1 sl-security 515 k
php-pdo x86_64 5.3.2-6.el6_0.1 sl-security 71 k
Transaction Summary
============================================================
Install 19 Package(s)
Upgrade 0 Package(s)
Total download size: 16 M
Installed size: 47 M
Downloading Packages:
(1/19): apr-1.3.9-3.el6_1.2.x86_64.rpm | 122 kB 00:01
(2/19): apr-util-1.3.9-3.el6_0.1.x86_64.rpm | 86 kB 00:00
(3/19): apr-util-ldap-1.3.9-3.el6_0.1.x86_64.rpm | 15 kB 00:00
(4/19): httpd-2.2.15-5.sl6.x86_64.rpm | 810 kB 00:00
(5/19): httpd-tools-2.2.15-5.sl6.x86_64.rpm | 67 kB 00:00
(6/19): libXpm-3.5.8-2.el6.x86_64.rpm | 58 kB 00:00
(7/19): mailcap-2.1.31-1.1.el6.noarch.rpm | 26 kB 00:00
(8/19): mod_ssl-2.2.15-5.sl6.x86_64.rpm | 84 kB 00:00
(9/19): mysql-5.1.52-1.el6_0.1.x86_64.rpm | 888 kB 00:00
(10/19): mysql-server-5.1.52-1.el6_0.1.x86_64.rpm | 8.1 MB 00:18
(11/19): perl-DBD-MySQL-4.013-3.el6.x86_64.rpm | 133 kB 00:00
(12/19): perl-DBI-1.609-4.el6.x86_64.rpm | 704 kB 00:01
(13/19): php-5.3.2-6.el6_0.1.x86_64.rpm | 1.1 MB 00:04
(14/19): php-cli-5.3.2-6.el6_0.1.x86_64.rpm | 2.2 MB 00:14
(15/19): php-common-5.3.2-6.el6_0.1.x86_64.rpm | 515 kB 00:03
(16/19): php-gd-5.3.2-6.el6_0.1.x86_64.rpm | 102 kB 00:00
(17/19): php-mbstring-5.3.2-6.el6_0.1.x86_64.rpm | 503 kB 00:01
(18/19): php-mysql-5.3.2-6.el6_0.1.x86_64.rpm | 75 kB 00:00
(19/19): php-pdo-5.3.2-6.el6_0.1.x86_64.rpm | 71 kB 00:00
------------------------------------------------------------
Total 306 kB/s | 16 MB 00:51
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : php-common-5.3.2-6.el6_0.1.x86_64 1/19
Installing : apr-1.3.9-3.el6_1.2.x86_64 2/19
Installing : apr-util-1.3.9-3.el6_0.1.x86_64 3/19
Installing : perl-DBI-1.609-4.el6.x86_64 4/19
Installing : perl-DBD-MySQL-4.013-3.el6.x86_64 5/19
Installing : httpd-tools-2.2.15-5.sl6.x86_64 6/19
Installing : apr-util-ldap-1.3.9-3.el6_0.1.x86_64 7/19
Installing : php-cli-5.3.2-6.el6_0.1.x86_64 8/19
Installing : php-pdo-5.3.2-6.el6_0.1.x86_64 9/19
Installing : mysql-5.1.52-1.el6_0.1.x86_64 10/19
Installing : libXpm-3.5.8-2.el6.x86_64 11/19
Installing : mailcap-2.1.31-1.1.el6.noarch 12/19
Installing : httpd-2.2.15-5.sl6.x86_64 13/19
Installing : 1:mod_ssl-2.2.15-5.sl6.x86_64 14/19
Installing : php-5.3.2-6.el6_0.1.x86_64 15/19
Installing : php-gd-5.3.2-6.el6_0.1.x86_64 16/19
Installing : mysql-server-5.1.52-1.el6_0.1.x86_64 17/19
Installing : php-mysql-5.3.2-6.el6_0.1.x86_64 18/19
Installing : php-mbstring-5.3.2-6.el6_0.1.x86_64 19/19
Installed:
httpd.x86_64 0:2.2.15-5.sl6 mod_ssl.x86_64 1:2.2.15-5.sl6 mysql-server.x86_64 0:5.1.52-1.el6_0.1 php.x86_64 0:5.3.2-6.el6_0.1 php-gd.x86_64 0:5.3.2-6.el6_0.1
php-mbstring.x86_64 0:5.3.2-6.el6_0.1 php-mysql.x86_64 0:5.3.2-6.el6_0.1
Dependency Installed:
apr.x86_64 0:1.3.9-3.el6_1.2 apr-util.x86_64 0:1.3.9-3.el6_0.1 apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1 httpd-tools.x86_64 0:2.2.15-5.sl6 libXpm.x86_64 0:3.5.8-2.el6
mailcap.noarch 0:2.1.31-1.1.el6 mysql.x86_64 0:5.1.52-1.el6_0.1 perl-DBD-MySQL.x86_64 0:4.013-3.el6 perl-DBI.x86_64 0:1.609-4.el6 php-cli.x86_64 0:5.3.2-6.el6_0.1
php-common.x86_64 0:5.3.2-6.el6_0.1 php-pdo.x86_64 0:5.3.2-6.el6_0.1
Complete!
#
# ServerAdmin: Your address, where problems with the server should be
# e-mailed. This address appears on some server-generated pages, such
# as error documents. e.g. admin@your-domain.com
#
# 管理者メールアドレスを変更します
ServerAdmin root@sa-sa-ki.jp # ドメイン名をlocalhostからsa-sa-ki.jpに変更
#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If this is not set to valid DNS name for your host, server-generated
# redirections will not work. See also the UseCanonicalName directive.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
# You will have to access it by its address anyway, and this will make
# redirections work in a sensible way.
#
# FQDNを変更します
ServerName www.sa-sa-ki.jp:80 # コメント解除してWebサーバーのFQDNに変更
#
# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
#
# First, we configure the "default" to be a very restrictive set of
# features.
#
Options None # FollowSymLinksからNoneに変更
AllowOverride None
Order deny,allow # 追加
Deny from all# 追加
#
# This should be changed to whatever you set DocumentRoot to.
#
#
# 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 ExecCGI FollowSymLinks # IndexesからExecCGIに変更
#
# 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
#
# NoneからAllに変更してファイルアクセス(.htaccess)の使用可能な指示子を全て許可にします
AllowOverride All # NoneからAllに変更
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
#
# AddHandler allows you to map certain file extensions to "handlers":
# actions unrelated to filetype. These can be either built into the server
# or added with the Action directive (see below)
#
# To use CGI scripts outside of ScriptAliased directories:
# (You will also need to add "ExecCGI" to the "Options" directive.)
#
# CGIスクリプトに拡張子.plを追加します
AddHandler cgi-script .cgi .pl # コメント解除して.plを追加
#
# Optionally add a line containing the server version and virtual host
# name to server-generated pages (internal error documents, FTP directory
# listings, mod_status and mod_info output etc., but not CGI generated
# documents or custom error documents).
# Set to "EMail" to also include a mailto: link to the ServerAdmin.
# Set to one of: On | Off | EMail
#
# エラーページにApacheのバージョンを表示しないようにOn から Off に変更
ServerSignature Off # OnからOffに変更
#
# Aliases: Add here as many aliases as you need (with no limit). The format is
# Alias fakename realname
#
# Note that if you include a trailing / on fakename then the server will
# require it to be present in the URL. So "/icons" isn't aliased in this
# example, only "/icons/". If the fakename is slash-terminated, then the
# realname must also be slash terminated, and if the fakename omits the
# trailing slash, the realname must also omit it.
#
# We include the /icons/ alias for FancyIndexed directory listings. If you
# do not use FancyIndexing, you may comment this out.
#
Alias /icons/ "/var/www/icons/"
# Options Indexesを削除してiconsディレクトリのファイル一覧を表示しないようにします
Options MultiViews FollowSymLinks # Indexesを削除
AllowOverride None
Order allow,deny
Allow from all
# 保存してviエディタを終了します
ドキュメントルートの権限を変更します。
; Decides whether PHP may expose the fact that it is installed on the server
; (e.g. by adding its signature to the Web server header). It is no security
; threat in any way, but it makes it possible to determine whether you use PHP
; on your server or not.
; http://www.php.net/manual/en/ini.core.php#ini.expose-php
# HTTPヘッダーにPHPのバージョンを表示しないようにOn から Off に変更
expose_php = Off # OnからOffに変更
;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;
; Whether to allow HTTP file uploads.
; http://www.php.net/manual/en/ini.core.php#ini.file-uploads
file_uploads = On
; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
; http://www.php.net/manual/en/ini.core.php#ini.upload-tmp-dir
;upload_tmp_dir =
; Maximum allowed size for uploaded files.
; http://www.php.net/manual/en/ini.core.php#ini.upload-max-filesize
# WordPressでアップロード可能なファイルサイズを10MBに変更
upload_max_filesize = 10M # 2Mから10Mに変更
# 保存してviエディタを終了します
Apacheのポート番号のアクセス許可設定を行います。
# 保存してviエディタを終了します
[root@sl6 ~]# /etc/rc.d/init.d/iptables restart
iptables: ファイアウォールルールを消去中: [ OK ]
iptables: チェインをポリシー ACCEPT へ設定中filter [ OK ]
iptables: モジュールを取り外し中: [ OK ]
iptables: ファイアウォールルールを適用中: [ OK ]
ルータがない場合は不要な手順になりますが、yasuの家にはCTUとサーバーの間にルータがありますので併せてNAT設定で80番ポートをサーバーに向けます。
設定方法はルータの設定手順に従ってください。
Apacheの起動と自動起動の設定を行います。
[root@sl6 ~]# chkconfig httpd on
[root@sl6 ~]# chkconfig --list | grep httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
MySQLの設定を行います。
[root@sl6 ~]# vi /etc/hosts 127.0.0.1 sl6.sa-sa-ki.jp localhost localhost.localdomain localhost4 localhost4.localdomain4 # ホスト名を追加(先頭に追加) ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 # 保存してviエディタを終了します # MySQL起動 [root@sl6 ~]# /etc/rc.d/init.d/mysqld start MySQL データベースを初期化中: Installing MySQL system tables... To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /usr/bin/mysqladmin -u root password 'new-password' /usr/bin/mysqladmin -u root -h sl6.sa-sa-ki.jp password 'new-password' Alternatively you can run: /usr/bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with: cd /usr ; /usr/bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd /usr/mysql-test ; perl mysql-test-run.pl Please report any problems with the /usr/bin/mysqlbug script! [ OK ] mysqld を起動中: [ OK ] # MySQL自動起動設定 [root@sl6 ~]# chkconfig mysqld on [root@sl6 ~]# chkconfig --list mysqld mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off # MySQL初期設定 # MySQLにrootでログインします [root@sl6 ~]# mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.1.52 Source distribution Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. This software comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to modify and redistribute it under the GPL v2 license Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. # ユーザー一覧を検索します mysql> select user,host,password from mysql.user; +------+-----------------+----------+ | user | host | password | +------+-----------------+----------+ | root | localhost | | | root | sl6.sa-sa-ki.jp | | | root | 127.0.0.1 | | | | localhost | | | | sl6.sa-sa-ki.jp | | +------+-----------------+----------+ 5 rows in set (0.00 sec) # パスワードを登録していきます mysql> set password for root@localhost=password('パスワード'); Query OK, 0 rows affected (0.00 sec) mysql> set password for root@"sl6.sa-sa-ki.jp"=password('パスワード'); Query OK, 0 rows affected (0.00 sec) mysql> set password for root@127.0.0.1=password('パスワード'); Query OK, 0 rows affected (0.00 sec) mysql> select user,host,password from mysql.user; +------+-----------------+-------------------------------------------+ | user | host | password | +------+-----------------+-------------------------------------------+ | root | localhost | *パスワード | | root | sl6.sa-sa-ki.jp | *パスワード | | root | 127.0.0.1 | *パスワード | | | localhost | | | | sl6.sa-sa-ki.jp | | +------+-----------------+-------------------------------------------+ 5 rows in set (0.00 sec) mysql> exit bye # rootユーザでログインします [root@sl6 ~]# mysql -u root -p Enter password:rootユーザのパスワード Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.1.52 Source distribution Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. This software comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to modify and redistribute it under the GPL v2 license Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. # データベースの一覧を表示します mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | test | +--------------------+ 3 rows in set (0.00 sec) # testデータベースは不要なので削除します mysql> drop database test; Query OK, 0 rows affected (0.04 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | +--------------------+ 2 rows in set (0.00 sec) mysql> exit bye
■関連記事
Scientific Linux 6で自宅サーバー構築 その1 サーバー機Express 5800 GT110bのオンボードRAIDでRAID1設定
Scientific Linux 6で自宅サーバー構築 その2 Scientific Linux 6をExpress5800/GT110bにインストール
Scientific Linux 6で自宅サーバー構築 その3 Scientific Linux 6インストール後の初期設定
Scientific Linux 6で自宅サーバー構築 番外編その1 Scientific Linux 6のcronについて
Scientific Linux 6で自宅サーバー構築 その4 Scientific Linux 6 にClamAVをインストールしてウィルス対策
Scientific Linux 6で自宅サーバー構築 その5 Scientific Linux 6 にTripwireをインストールしてファイル改ざんを検知する
Scientific Linux 6で自宅サーバー構築 その6 Scientific Linux 6 にchkrootkitをインストールしてrootkit感染を検知する
Scientific Linux 6で自宅サーバー構築 その7 NTPサーバーで自動時刻合わせ
Scientific Linux 6で自宅サーバー構築 その8 バッファオーバーフロー攻撃対策を行う
Scientific Linux 6で自宅サーバー構築 その9 logwatchでサーバー監視
Scientific Linux 6で自宅サーバー構築 その10 DNSサーバーを構築
Scientific Linux 6で自宅サーバー構築 番外編その2 Scientific Linuxを6.0から6.1にアップグレードする
Scientific Linux 6で自宅サーバー構築 その11 PostfixとDovecotとSMTP-AUTHでメールサーバーを構築する
Scientific Linux 6で自宅サーバー構築 その12 メールサーバーにSSLを導入する
Scientific Linux 6で自宅サーバー構築 その13 Apache PHP MySQLをインストール
Scientific Linux 6で自宅サーバー構築 その14 WebサーバーにSSLを導入する
Scientific Linux 6で自宅サーバー構築 その15 WordPressを導入する
Scientific Linux 6で自宅サーバー構築 その16 Piwikでアクセスログ集計
Scientific Linux 6で自宅サーバー構築 その17 Squidをインストール
Scientific Linux 6で自宅サーバー構築 その18 sshで鍵認証を導入
Scientific Linux 6で自宅サーバー構築 その19 WebDavの設定
Scientific Linux 6で自宅サーバー構築 その20 lm_sensorをインストール
会社のWindow XPから自宅のWebDavに接続ができない。
Snow LeopardやUbuntuからも接続はできるんだけど、ファイルの一覧が表示されない。
Apacheのログをみたら
Provider encountered an error while streaming a multistatus PROPFIND response. [404, #0]
って表示されてる。
んで、このメッセージでググってみました。
IT Harmony: Provider encountered an error while streaming a multistatus PROPFIND response
同じ現象で困っている方がいたので、その方のサイトを見てみると・・・
【現象】WebDAV 共有しているはずが、アクセスすると上記エラーによりアクセスできない。
≪理由≫Apache の仕様により 2GB 以上のファイルがあると上記エラーが発生し、ファイル一覧表示すらできないらしい。
最近2GBを超えるようなファイルをWebDav共有フォルダに置いた記憶はないのだが、不要なファイルやフォルダを整理したらWindowsからは接続できるようになったし、Snow LeopardやUbuntuからもファイルの一覧が表示されるようになった。
結論:WebDavには何でもつっこんではいけない
昨日は基本認証を試してみましたが、今日はダイジェスト・アクセス認証を試してみたいと思います。
「ダイジェスト・アクセス認証」とは:ITpro
今回もCentOS 5.4で試しますが、Apache 2.2であればプラットホームは何でもいいと思います
まずはサーバにダイジェスト・アクセス認証用のディレクトリを作成します。
次にダイジェスト・アクセス認証の設定を行います。
ここでは.htaccessに設定を行います。
また認証ユーザはひとまずdigestとします。
viエディタを保存終了([Esc]キーを押した後に、[:]キー、[w]キー、[q]キーを順番に押し[Enter]キーを押す)します
認証ユーザのパスワードを付与します。
パスワードはひとまずdigestとします。
※ポイントとしては新規作成の場合はオプション-cを付けるのと、2番目の引数('Digest Auth')は.htaccessに指定したAuthNameに指定した名前と同じ必要があります
Adding user digest in realm Digest
New password: digest
Re-type new password: digest
ダイジェスト・アクセス認証の確認を行います。
ダイジェスト・アクセス認証の確認ページを作成します。
viエディタを保存終了([Esc]キーを押した後に、[:]キー、[w]キー、[q]キーを順番に押し[Enter]キーを押す)します
ブラウザを起動して、ダイジェスト・アクセス認証の確認ページのURLを入力します。
認証用のダイアログが表示されるので、ユーザ(digest)とパスワード(digest)を入力して[OK]ボタンをクリックします。

Apache 2.2 で基本認証(basic authentication)を試してみます。
基本認証とは 【basic authentication】 - 意味/解説/説明/定義 : IT用語辞典
今回はCentOS 5.4で試しますが、Apache 2.2であればプラットホームは何でもいいと思います
まずはサーバに基本認証用のディレクトリを作成します。
#基本認証用のディレクトリを作成します
[root@centos ~]# mkdir /var/www/html/basic
次に基本認証の設定を行います。
ここでは.htaccessに設定を行います。
また認証ユーザはひとまずbasicとします。
viエディタを保存終了([Esc]キーを押した後に、[:]キー、[w]キー、[q]キーを順番に押し[Enter]キーを押す)します
認証ユーザのパスワードを付与します。
パスワードはひとまずbasicとします。
#既に/etc/httpd/conf/.htpasswdファイルを作成済みの場合
[root@centos ~]# htpasswd /etc/httpd/conf/.htpasswd basic
※ポイントとしては新規作成の場合はオプション-cを付けます
New password: basic
Re-type new password: basic
Adding password for user basic
基本認証の確認を行います。
基本認証の確認ページを作成します。
viエディタを保存終了([Esc]キーを押した後に、[:]キー、[w]キー、[q]キーを順番に押し[Enter]キーを押す)します
ブラウザを起動して、基本認証の確認ページのURLを入力します。
認証用のダイアログが表示されるので、ユーザ(basic)とパスワード(basic)を入力して[OK]ボタンをクリックします。

なお基本認証はユーザとパスワードが平文で流れるのでhttpプロトコルで重要なページの認証方法としてはふさわしくありません。
基本認証する場合はhttpsプロトコルで認証するか、ダイジェストアクセス認証(Digest Access Authentication)がいいと思います。
今回はApacheにサーバー証明書を導入してみたいと思います。
以前IISでも同じような事をやりましたが、今回はそれのApache版といったところでしょうか。
なおApacheでSSL通信を行う場合、mod_sslというモジュールが必要になりますのでインストールされてない方は
yum -y install mod_ssl を実行してインストールしてください。
yasuはLAMP環境構築の時に一緒にインストールしているので、ここではインストール手順を割愛します。
OpenSSLの設定ファイルを編集します
/etc/pki/tls直下にOpenSSLの設定ファイルがあるので、それを/etc/pki/tls/yasuにコピーします
[root@centos ~]# cp -p /etc/pki/tls/openssl.cnf /etc/pki/tls/yasu
/etc/pki/tls/yasuにコピーしたOpenSSLの設定ファイルをviエディタで開き、以下の箇所を編集します
[root@centos ~]# cd /etc/pki/tls/yasu
[root@centos yasu]# vi openssl.cnf
■修正前
[37~39行目]
dir = ./demoCA # Where everything is kept
certs = $dir/certs # Where the issued certs are kept
crl_dir = $dir/crl # Where the issued crl are kept
[43行目]
new_certs_dir = $dir/newcerts # default place for new certs.
[50~51行目]
private_key = $dir/private/cakey.pem# The private key
RANDFILE = $dir/private/.rand # private random number file
■修正後
[37~39行目]
dir = . # Where everything is kept
certs = $dir # Where the issued certs are kept
crl_dir = $dir # Where the issued crl are kept
[43行目]
new_certs_dir = $dir # default place for new certs.
[50~51行目]
private_key = $dir/cakey.pem# The private key
RANDFILE = $dir/.rand # private random number file
/etc/pki/tls/yasu に中身が空っぽのテキストファイル index.txt と01と書いた serial ファイルを作成します
[root@centos yasu]# touch index.txt
[root@centos yasu]# echo 01 > serial
[root@centos yasu]# ls -l
合計 28
-rw-r--r-- 1 root root 0 3月 17 11:31 index.txt
-rw-r--r-- 1 root root 9534 3月 17 11:30 openssl.cnf
-rw-r--r-- 1 root root 3 3月 17 11:31 serial
認証局の秘密鍵を作成します。
[root@centos yasu]# ls -l
合計 36
-rw-r--r-- 1 root root 963 3月 17 15:28 cakey.pem
-rw-r--r-- 1 root root 0 3月 17 11:31 index.txt
-rw-r--r-- 1 root root 9534 3月 17 11:30 openssl.cnf
-rw-r--r-- 1 root root 3 3月 17 11:31 serial
これで/etc/pki/tls/yasu ディレクトリにはcakey.pemというファイルが作成されましたね。
これが認証局の秘密鍵になります。
「2.認証局の秘密鍵作成」で作成した認証局の秘密鍵ファイルを使って認証局の証明書を作成します。
[root@centos yasu]# ls -l
合計 44
-rw-r--r-- 1 root root 1164 3月 17 15:33 cacert.pem
-rw-r--r-- 1 root root 963 3月 17 15:28 cakey.pem
-rw-r--r-- 1 root root 0 3月 17 11:31 index.txt
-rw-r--r-- 1 root root 9534 3月 17 11:30 openssl.cnf
-rw-r--r-- 1 root root 3 3月 17 11:31 serial
cacert.pem というファイルが作成されました。
「3.認証局の証明書作成」で作成した認証局の証明書をブラウザにインポートする為、DER形式にバイナリエンコードします。
ca.der というファイルが作成されました。
「13.SSLの動作確認および認証局の証明書インポート」で使うのでそれまで大切に保管してください。
サーバー秘密鍵を作成します。
WebサーバーにSSLでアクセスした時に毎回パスフレーズを聞かれないようにサーバー秘密鍵のパスフレーズを削除します。
[root@centos yasu]# openssl rsa -in ./server.key -out ./server.key
Enter pass phrase for server.key:上記パスフレーズを応答
writing RSA key
[root@centos yasu]# ls -l
合計 60
-rw-r--r-- 1 root root 818 3月 17 15:36 ca.der
-rw-r--r-- 1 root root 1164 3月 17 15:33 cacert.pem
-rw-r--r-- 1 root root 963 3月 17 15:28 cakey.pem
-rw-r--r-- 1 root root 0 3月 17 11:31 index.txt
-rw-r--r-- 1 root root 9534 3月 17 11:30 openssl.cnf
-rw-r--r-- 1 root root 3 3月 17 11:31 serial
-rw-r--r-- 1 root root 887 3月 17 15:38 server.key
server.key というファイルが作成されました。
「5.サーバー秘密鍵作成」で作成したサーバー秘密鍵ファイルを使ってサーバー証明要求書を作成します。
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:何も入力しないで[Enter]キーを押下
An optional company name []:何も入力しないで[Enter]キーを押下
[root@centos yasu]# ls -l
合計 68
-rw-r--r-- 1 root root 773 3月 17 16:49 ca.der
-rw-r--r-- 1 root root 1103 3月 17 16:48 cacert.pem
-rw-r--r-- 1 root root 963 3月 17 16:48 cakey.pem
-rw-r--r-- 1 root root 0 3月 17 11:31 index.txt
-rw-r--r-- 1 root root 9534 3月 17 11:30 openssl.cnf
-rw-r--r-- 1 root root 3 3月 17 11:31 serial
-rw-r--r-- 1 root root 639 3月 17 16:49 server.csr
-rw-r--r-- 1 root root 891 3月 17 16:46 server.key
server.csr というファイルが作成されました。
サーバー証明要求書ファイルに書名を行い、サーバー証明書を作成します。
Certificate is to be certified until Mar 15 07:50:57 2019 GMT (3650 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
[root@centos yasu]# ls -l
合計 108
-rw-r--r-- 1 root root 3050 3月 17 16:51 01.pem
-rw-r--r-- 1 root root 773 3月 17 16:49 ca.der
-rw-r--r-- 1 root root 1103 3月 17 16:48 cacert.pem
-rw-r--r-- 1 root root 963 3月 17 16:48 cakey.pem
-rw-r--r-- 1 root root 76 3月 17 16:51 index.txt
-rw-r--r-- 1 root root 21 3月 17 16:51 index.txt.attr
-rw-r--r-- 1 root root 0 3月 17 11:31 index.txt.old
-rw-r--r-- 1 root root 9534 3月 17 11:30 openssl.cnf
-rw-r--r-- 1 root root 3 3月 17 16:51 serial
-rw-r--r-- 1 root root 3 3月 17 11:31 serial.old
-rw-r--r-- 1 root root 3050 3月 17 16:51 server.cer
-rw-r--r-- 1 root root 639 3月 17 16:49 server.csr
-rw-r--r-- 1 root root 891 3月 17 16:46 server.key
server.cer というファイルが作成されました。
各ファイルをrootユーザ読み取り専用に権限を変更します。
[root@centos yasu]# chmod 400 *
[root@centos yasu]# ls -l
合計 108
-r-------- 1 root root 3050 3月 17 16:51 01.pem
-r-------- 1 root root 773 3月 17 16:49 ca.der
-r-------- 1 root root 1103 3月 17 16:48 cacert.pem
-r-------- 1 root root 963 3月 17 16:48 cakey.pem
-r-------- 1 root root 76 3月 17 16:51 index.txt
-r-------- 1 root root 21 3月 17 16:51 index.txt.attr
-r-------- 1 root root 0 3月 17 11:31 index.txt.old
-r-------- 1 root root 9534 3月 17 11:30 openssl.cnf
-r-------- 1 root root 3 3月 17 16:51 serial
-r-------- 1 root root 3 3月 17 11:31 serial.old
-r-------- 1 root root 3050 3月 17 16:51 server.cer
-r-------- 1 root root 639 3月 17 16:49 server.csr
-r-------- 1 root root 891 3月 17 16:46 server.key
ApacheのSSL用設定ファイル(ssl.conf)を変更します。
LoadModule ssl_module modules/mod_ssl.so
#
# When we also provide SSL we have to listen to the
# the HTTPS port in addition.
#
Listen 443
##
## SSL Global Context
##
## All SSL configuration in this context applies both to
## the main server and all SSL-enabled virtual hosts.
##
#
# Some MIME-types for downloading Certificates and CRLs
#
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl .crl
# Pass Phrase Dialog:
# Configure the pass phrase gathering process.
# The filtering dialog program (`builtin' is a internal
# terminal dialog) has to provide the pass phrase on stdout.
SSLPassPhraseDialog builtin
# Inter-Process Session Cache:
# Configure the SSL Session Cache: First the mechanism
# to use and second the expiring timeout (in seconds).
#SSLSessionCache dc:UNIX:/var/cache/mod_ssl/distcache
SSLSessionCache shmcb:/var/cache/mod_ssl/scache(512000)
SSLSessionCacheTimeout 300
# Semaphore:
# Configure the path to the mutual exclusion semaphore the
# SSL engine uses internally for inter-process synchronization.
SSLMutex default
# Pseudo Random Number Generator (PRNG):
# Configure one or more sources to seed the PRNG of the
# SSL library. The seed data should be of good random quality.
# WARNING! On some platforms /dev/random blocks if not enough entropy
# is available. This means you then cannot use the /dev/random device
# because it would lead to very long connection times (as long as
# it requires to make more entropy available). But usually those
# platforms additionally provide a /dev/urandom device which doesn't
# block. So, if available, use this one instead. Read the mod_ssl User
# Manual for more details.
SSLRandomSeed startup file:/dev/urandom 256
SSLRandomSeed connect builtin
#SSLRandomSeed startup file:/dev/random 512
#SSLRandomSeed connect file:/dev/random 512
#SSLRandomSeed connect file:/dev/urandom 512
#
# Use "SSLCryptoDevice" to enable any supported hardware
# accelerators. Use "openssl engine -v" to list supported
# engine names. NOTE: If you enable an accelerator and the
# server does not start, consult the error logs and ensure
# your accelerator is functioning properly.
#
SSLCryptoDevice builtin
#SSLCryptoDevice ubsec
##
## SSL Virtual Host Context
##
# General setup for the virtual host, inherited from global configuration
先頭の#を外してコメントを解除します
DocumentRoot "/var/www/html"
先頭の#を外してコメントを解除し、サーバー名を修正します
ServerName www.sa-sa-ki.jp:443
# Use separate log files for the SSL virtual host; note that LogLevel
# is not inherited from httpd.conf.
ErrorLog logs/ssl_error_log
TransferLogのファイル名をssl_access_logからssl_transfer_logに変更します
TransferLog logs/ssl_transfer_log
LogLevel warn
ログファイルのフォーマットを定義します
#
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
#
LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" combined
LogFormat "%h %l %u %t "%r" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
#
# For a single logfile with access, agent, and referer information
# (Combined Logfile Format), use the following directive:
#
CustomLog logs/ssl_access_log combined
# SSL Engine Switch:
# Enable/Disable SSL for this virtual host.
SSLEngine on
# SSL Protocol support:
# List the enable protocol levels with which clients will be able to
# connect. Disable SSLv2 access by default:
SSLProtocol all -SSLv2
# SSL Cipher Suite:
# List the ciphers that the client is permitted to negotiate.
# See the mod_ssl documentation for a complete list.
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
# Server Certificate:
# Point SSLCertificateFile at a PEM encoded certificate. If
# the certificate is encrypted, then you will be prompted for a
# pass phrase. Note that a kill -HUP will prompt again. A new
# certificate can be generated using the genkey(1) command.
先頭に#をつけてコメント化します
#SSLCertificateFile /etc/pki/tls/certs/localhost.crt
追加します
SSLCertificateFile /etc/pki/tls/certs/server.cer
# Server Private Key:
# If the key is not combined with the certificate, use this
# directive to point at the key file. Keep in mind that if
# you've both a RSA and a DSA private key you can configure
# both in parallel (to also allow the use of DSA ciphers, etc.)
先頭に#をつけてコメント化します
#SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
追加します
SSLCertificateKeyFile /etc/pki/tls/private/server.key
# Server Certificate Chain:
# Point SSLCertificateChainFile at a file containing the
# concatenation of PEM encoded CA certificates which form the
# certificate chain for the server certificate. Alternatively
# the referenced file can be the same as SSLCertificateFile
# when the CA certificates are directly appended to the server
# certificate for convinience.
#SSLCertificateChainFile /etc/pki/tls/certs/server-chain.crt
# Certificate Authority (CA):
# Set the CA certificate verification path where to find CA
# certificates for client authentication or alternatively one
# huge file containing all of them (file must be PEM encoded)
#SSLCACertificateFile /etc/pki/tls/certs/ca-bundle.crt
# Client Authentication (Type):
# Client certificate verification type and depth. Types are
# none, optional, require and optional_no_ca. Depth is a
# number which specifies how deeply to verify the certificate
# issuer chain before deciding the certificate is not valid.
#SSLVerifyClient require
#SSLVerifyDepth 10
# Access Control:
# With SSLRequire you can do per-directory access control based
# on arbitrary complex boolean expressions containing server
# variable checks and other lookup directives. The syntax is a
# mixture between C and Perl. See the mod_ssl documentation
# for more details.
#
#SSLRequire ( %{SSL_CIPHER} !~ m/^(EXP|NULL)/
# and %{SSL_CLIENT_S_DN_O} eq "Snake Oil, Ltd."
# and %{SSL_CLIENT_S_DN_OU} in {"Staff", "CA", "Dev"}
# and %{TIME_WDAY} >= 1 and %{TIME_WDAY} < = 5
# and %{TIME_HOUR} >= 8 and %{TIME_HOUR} < = 20 )
# or %{REMOTE_ADDR} =~ m/^192.76.162.[0-9]+$/
#
# SSL Engine Options:
# Set various options for the SSL engine.
# o FakeBasicAuth:
# Translate the client X.509 into a Basic Authorisation. This means that
# the standard Auth/DBMAuth methods can be used for access control. The
# user name is the `one line' version of the client's X.509 certificate.
# Note that no password is obtained from the user. Every entry in the user
# file needs this password: `xxj31ZMTZzkVA'.
# o ExportCertData:
# This exports two additional environment variables: SSL_CLIENT_CERT and
# SSL_SERVER_CERT. These contain the PEM-encoded certificates of the
# server (always existing) and the client (only existing when client
# authentication is used). This can be used to import the certificates
# into CGI scripts.
# o StdEnvVars:
# This exports the standard SSL/TLS related `SSL_*' environment variables.
# Per default this exportation is switched off for performance reasons,
# because the extraction step is an expensive operation and is usually
# useless for serving static content. So one usually enables the
# exportation for CGI and SSI requests only.
# o StrictRequire:
# This denies access when "SSLRequireSSL" or "SSLRequire" applied even
# under a "Satisfy any" situation, i.e. when it applies access is denied
# and no other module can change it.
# o OptRenegotiate:
# This enables optimized SSL connection renegotiation handling when SSL
# directives are used in per-directory context.
#SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
SSLOptions +StdEnvVars
SSLOptions +StdEnvVars
# SSL Protocol Adjustments:
# The safe and default but still SSL/TLS standard compliant shutdown
# approach is that mod_ssl sends the close notify alert but doesn't wait for
# the close notify alert from client. When you need a different shutdown
# approach you can use one of the following variables:
# o ssl-unclean-shutdown:
# This forces an unclean shutdown when the connection is closed, i.e. no
# SSL close notify alert is send or allowed to received. This violates
# the SSL/TLS standard but is needed for some brain-dead browsers. Use
# this when you receive I/O errors because of the standard approach where
# mod_ssl sends the close notify alert.
# o ssl-accurate-shutdown:
# This forces an accurate shutdown when the connection is closed, i.e. a
# SSL close notify alert is send and mod_ssl waits for the close notify
# alert of the client. This is 100% SSL/TLS standard compliant, but in
# practice often causes hanging connections with brain-dead browsers. Use
# this only for browsers where you know that their SSL implementation
# works correctly.
# Notice: Most problems of broken clients are also related to the HTTP
# keep-alive facility, so you usually additionally want to disable
# keep-alive for those clients, too. Use variable "nokeepalive" for this.
# Similarly, one has to force some clients to use HTTP/1.0 to workaround
# their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
# "force-response-1.0" for this.
SetEnvIf User-Agent ".*MSIE.*"
nokeepalive ssl-unclean-shutdown
downgrade-1.0 force-response-1.0
# Per-Server Logging:
# The home of a custom SSL log file. Use this when you want a
# compact non-error SSL logfile on a virtual host basis.
CustomLog logs/ssl_request_log
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x "%r" %b"
内容を保存しviエディタを終了します
サーバー証明書ファイルとサーバー秘密鍵ファイルを所定の場所にコピーします。
/etc/pki/tls/private/:
合計 16
-rw------- 1 root root 891 2月 3 23:11 localhost.key
-r-------- 1 root root 891 3月 17 16:46 server.key
内容を保存しviエディタを終了します
設定内容を反映します
[root@centos ~]# /etc/rc.d/init.d/iptables restart
ファイアウォールルールを適用中: [ OK ]
チェインポリシーを ACCEPT に設定中filter [ OK ]
iptables モジュールを取り外し中 [ OK ]
iptables ファイアウォールルールを適用中: [ OK ]
iptables モジュールを読み込み中ip_conntrack_netbios_ns [ OK ]
ルータの設定を変更してTCPの443番ポートを開放します。
開放方法はルータの設定手順に従って実施してください。
SSLの動作確認の為にブラウザを起動してhttps://www.sa-sa-ki.jpにアクセスしてみます。
警告が表示されるので[このサイトの閲覧を続行する(推奨されません)。]をクリックします。

するとページが表示されました。

SSLの動作確認としてはこれでOKなのですが、毎回警告がでるのも鬱陶しいので警告がでないように認証局の証明書インポートします。
「4.認証局の証明書をDER形式バイナリエンコード(ブラウザインポート用)」で作成したca.derファイルをサーバーからクライアントPCにコピーします。
ca.derファイルを右クリックし[証明書をインストール(I)]を選択します。
証明書のインポートウィザードが表示されるので[次へ(N)]ボタンをクリックします。

もう一度Internet Explorerを起動しなおして、再度https://www.sa-sa-ki.jpにアクセスしてみます。

すると警告が表示されなくなりました。
■ 参考サイト ■
flashcast:フリーで働くITエンジニア集団のブログ: OpenSSLでIISのサーバー証明書を作成・導入する
Webサーバー間通信内容暗号化(Apache+mod_SSL) - CentOSで自宅サーバー構築
はじめての自宅サーバ構築 Fedora/CentOS - 通信内容暗号化(OpenSSL & mod_SSL) ~ Webページ編 ~
■関連記事
自宅サーバー再構築 その1 導入を検討する
自宅サーバー再構築 その2 CentOS 5.2 をインストールする
自宅サーバー再構築 その3 インストールしたCentOS 5.2 にリモート接続準備
自宅サーバー再構築 その4 CentOS 5.2 インストール後の初期設定
自宅サーバー再構築 その5 CentOS 5.2 ファイル転送準備
自宅サーバー再構築 その6 CentOS 5.2 にアンチウィルスソフトを導入する
自宅サーバー再構築 その7 CentOS 5.2 にファイル改竄検知システムを導入する
自宅サーバー再構築 その8 CentOS 5.2 にrootkit検知ツールを導入する
自宅サーバー再構築 その9 CentOS 5.2 にバッファオーバーフロー攻撃対策を行う
自宅サーバー再構築 その10 CentOS 5.2 SSHサーバーを構築して外部からリモート接続&リモートファイル転送
自宅サーバー再構築 その11 CentOS 5.2 にDNSサーバーを導入して名前解決(設定編)
自宅サーバー再構築 その12 CentOS 5.2 にDNSサーバーを導入して名前解決(確認編)
自宅サーバー再構築 その13 CentOS 5.2 にLAMP環境構築(Apache、PHP編)
自宅サーバー再構築 その14 CentOS 5.2 にLAMP環境構築(MySQL編)
自宅サーバー再構築 その15 Apacheにサーバー証明書を導入する
自宅サーバー再構築 その16 CentOS 5.2 にWordPressを導入してブログサイトを構築する
自宅サーバー再構築 その17 WordPressのセキュリティ対策
自宅サーバー再構築 その18 CentOS 5.3 にNTPサーバーを導入して自動時間合わせ
自宅サーバー再構築 その19 CentOS 5.3 アンチウィルスソフトのバージョンアップ
自宅サーバー再構築 その20 CentOS 5.3 メールサーバー構築(Postfix設定編)
自宅サーバー再構築 その21 CentOS 5.3 メールサーバー構築(Dovecot設定編)
自宅サーバー再構築 その22 CentOS 5.3 メールサーバー構築(公開編)
自宅サーバー再構築 その23 CentOS 5.3 メールサーバー構築(SSL導入編)
自宅サーバー再構築 その24 CentOS 5.3 メールサーバー構築(メールアカウント作成編)
自宅サーバー再構築 その25 CentOS 5.3 メールサーバー構築(Thunderbird設定編)
自宅サーバー再構築 番外編その1 CentOS 5.3 のリリースと導入済みソフトウェアのアップデート
今回はLAMP環境構築作業の続きでMySQLの設定を行っていきます。
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
MySQLクライアントの文字コードをUTF-8に変更します
[mysql]
default-character-set = utf8
内容を保存しviエディタを終了します
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h centos.sa-sa-ki.jp password 'new-password'
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/bin/mysqlbug script!
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
[ OK ]
MySQL を起動中: [ OK ]
OS再起動時にMySQLを自動起動するようにします
[root@centos ~]# chkconfig mysqld on
[root@centos ~]# chkconfig --list | grep mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
MySQL起動時にMySQLのrootユーザにパスワードを設定するよう指示が表示されていたのでパスワードを設定します。
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
MySQLのユーザ、パスワードを確認
mysql> select user,host,password from mysql.user;
+------+--------------------+----------+
| user | host | password |
+------+--------------------+----------+
| root | localhost | |
| root | centos.sa-sa-ki.jp | |
| root | 127.0.0.1 | |
+------+--------------------+----------+
3 rows in set (0.00 sec)
MySQLに接続する時のホスト名がlocalhost、centos.sa-sa-ki.jp、127.0.0.1でユーザ名がrootのパスワードが未登録な事が確認できます。
これら全てにパスワードを設定していきます。
ホスト名がlocalhostのrootユーザにパスワード設定します
mysql> set password for root@localhost=password('rootパスワード');
Query OK, 0 rows affected (0.00 sec)
ホスト名がcentos.sa-sa-ki.jpのrootユーザにパスワード設定します
mysql> set password for root@"centos.sa-sa-ki.jp"=password('rootパスワード');
Query OK, 0 rows affected (0.00 sec)
ホスト名が127.0.0.1のrootユーザにパスワード設定します
mysql> set password for root@127.0.0.1=password('rootパスワード');
Query OK, 0 rows affected (0.00 sec)
MySQLのユーザ、パスワードを再確認します
mysql> select user,host,password from mysql.user;
+------+--------------------+------------------+
| user | host | password |
+------+--------------------+------------------+
| root | localhost | ++++++++++++++++ |
| root | centos.sa-sa-ki.jp | ++++++++++++++++ |
| root | 127.0.0.1 | ++++++++++++++++ |
+------+--------------------+------------------+
3 rows in set (0.00 sec)
MySQLに接続する時のホスト名がlocalhost、centos.sa-sa-ki.jp、127.0.0.1でユーザ名がrootのパスワードが設定された事が確認できました。
MySQLからログアウトします。
mysql> exit
Bye
パスワードの設定が完了したので、ログインを確認していきます。
ホスト名がcentos.sa-sa-ki.jpのrootユーザでパスワードなしでログイン施行
[root@centos ~]# mysql -u root -h 'centos.sa-sa-ki.jp'
ERROR 1130 (00000): Host 'sa-sa-ki.jp' is not allowed to connect to this MySQL server
ホスト名が127.0.0.1のrootユーザでパスワードなしでログイン施行
[root@centos ~]# mysql -u root -h 127.0.0.1
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
あれ?
ホスト名centos.sa-sa-ki.jpの場合だけエラーメッセージが違いますね。
どうやらDNSサーバーで名前解決すると外部からの接続と認識して外部接続を許可する権限を付与しないとダメなようです。
/etc/hostsにcentos.sa-sa-ki.jpを追加すると他と同じメッセージになったのでひとまずよしとします。
次にパスワードを入力してMySQLにログインできるか確認します。
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
接続できたのでログアウトします。
mysql> exit
Bye
同様にホスト名centos.sa-sa-ki.jpや127.0.0.1の場合も試してみます。
ホスト名がcentos.sa-sa-ki.jpのrootユーザでパスワードありでログイン施行
[root@centos ~]# mysql -u root -h 'centos.sa-sa-ki.jp' -p
Enter password: 設定したrootユーザのパスワードを入力
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 22
Server version: x.x.xx Source distribution
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
接続できたのでログアウトします。
mysql> exit
Bye
ホスト名が127.0.0.1のrootユーザでパスワードありでログイン施行
[root@centos ~]# mysql -u root -h 127.0.0.1 -p
Enter password: 設定したrootユーザのパスワードを入力
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 23
Server version: x.x.xx Source distribution
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
接続できたのでログアウトします。
mysql> exit
Bye
どのパターンもパスワード認証できました。
MySQLにはデフォルトでtestという名前のデータベースが作成されていますが、不要なので削除します。
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
登録データベースを確認します
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.00 sec)
testデータベースを削除します
mysql> drop database test;
Query OK, 0 rows affected (0.00 sec)
再度登録データベースを確認します
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
+--------------------+
2 rows in set (0.00 sec)
testデータベースが削除されている事が確認できました
mysql> exit
Bye
MySQLの初期設定は終了です。
これでデータベースと連携したホームページ作りが可能になります。
なおMySQLを使ったシステムを作る場合はライセンスに関して注意が必要です。
MySQLにはGNU General Public License (一般的には「GPL」と呼ばれます) と商用ライセンスがあります。
GPLは無償でMySQLを使ったシステムを構築できる代わりにソースコードを公開する必要があり、他のユーザはそれを自由に改変、統合、頒布することができます。
商用ライセンスは有償ですがMySQLを使ったシステムのソースコードを公開する必要はありません。
ということで、MySQLを使ったシステムを作る場合はライセンスに留意する必要がありますね。
■ 参考サイト ■
データベースサーバー構築(MySQL) - CentOSで自宅サーバー構築
MySQL :: ライセンスに関する FAQ
■関連記事
自宅サーバー再構築 その1 導入を検討する
自宅サーバー再構築 その2 CentOS 5.2 をインストールする
自宅サーバー再構築 その3 インストールしたCentOS 5.2 にリモート接続準備
自宅サーバー再構築 その4 CentOS 5.2 インストール後の初期設定
自宅サーバー再構築 その5 CentOS 5.2 ファイル転送準備
自宅サーバー再構築 その6 CentOS 5.2 にアンチウィルスソフトを導入する
自宅サーバー再構築 その7 CentOS 5.2 にファイル改竄検知システムを導入する
自宅サーバー再構築 その8 CentOS 5.2 にrootkit検知ツールを導入する
自宅サーバー再構築 その9 CentOS 5.2 にバッファオーバーフロー攻撃対策を行う
自宅サーバー再構築 その10 CentOS 5.2 SSHサーバーを構築して外部からリモート接続&リモートファイル転送
自宅サーバー再構築 その11 CentOS 5.2 にDNSサーバーを導入して名前解決(設定編)
自宅サーバー再構築 その12 CentOS 5.2 にDNSサーバーを導入して名前解決(確認編)
自宅サーバー再構築 その13 CentOS 5.2 にLAMP環境構築(Apache、PHP編)
自宅サーバー再構築 その14 CentOS 5.2 にLAMP環境構築(MySQL編)
自宅サーバー再構築 その15 Apacheにサーバー証明書を導入する
自宅サーバー再構築 その16 CentOS 5.2 にWordPressを導入してブログサイトを構築する
自宅サーバー再構築 その17 WordPressのセキュリティ対策
自宅サーバー再構築 その18 CentOS 5.3 にNTPサーバーを導入して自動時間合わせ
自宅サーバー再構築 その19 CentOS 5.3 アンチウィルスソフトのバージョンアップ
自宅サーバー再構築 その20 CentOS 5.3 メールサーバー構築(Postfix設定編)
自宅サーバー再構築 その21 CentOS 5.3 メールサーバー構築(Dovecot設定編)
自宅サーバー再構築 その22 CentOS 5.3 メールサーバー構築(公開編)
自宅サーバー再構築 その23 CentOS 5.3 メールサーバー構築(SSL導入編)
自宅サーバー再構築 その24 CentOS 5.3 メールサーバー構築(メールアカウント作成編)
自宅サーバー再構築 その25 CentOS 5.3 メールサーバー構築(Thunderbird設定編)
自宅サーバー再構築 番外編その1 CentOS 5.3 のリリースと導入済みソフトウェアのアップデート
今回はApache、PHP、MySQLをインストールしてLAMP環境を構築します。
LAMP環境の説明はubuntu 8.10にApache、PHP、MySQLをインストールしてLAMP環境を構築する » sa-sa-ki.jpのblogを参照ください。
Apache、PHP、MySQLをインストールします
[root@centos ~]# yum -y install httpd php php-mbstring mod_ssl mysql-server php-mysql
Loading "priorities" plugin
Loading "fastestmirror" plugin
Loading mirror speeds from cached hostfile
* base: ftp.iij.ad.jp
* updates: ftp.iij.ad.jp
* addons: ftp.iij.ad.jp
* extras: ftp.iij.ad.jp
0 packages excluded due to repository priority protections
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package php-mbstring.i386 0:x.x.x-xx.xxx_x.x set to be updated
--> Processing Dependency: php-common = x.x.x-xx.xxx_x.x for package: php-mbstring
---> Package mysql-server.i386 0:x.x.xx-x.xxx set to be updated
--> Processing Dependency: libmysqlclient.so.15(libmysqlclient_15) for package: mysql-server
--> Processing Dependency: perl-DBI for package: mysql-server
--> Processing Dependency: perl
-DBD-MySQL for package: mysql-server
--> Processing Dependency: perl(DBI) for package: mysql-server
--> Processing Dependency: libmysqlclient_r.so.15(libmysqlclient_15) for package: mysql-server
--> Processing Dependency: libmysqlclient_r.so.15 for package: mysql-server
--> Processing Dependency: mysql = x.x.xx-x.xxx for package: mysql-server
--> Processing Dependency: libmysqlclient.so.15 for package: mysql-server
---> Package httpd.i386 0:x.x.x-xx.xxx_x.centos.4 set to be updated
filelists.xml.gz 100% |=========================| 2.8 MB 00:00
filelists.xml.gz 100% |=========================| 2.7 MB 00:00
filelists.xml.gz 100% |=========================| 133 kB 00:00
filelists.xml.gz 100% |=========================| 150 B 00:00
---> Package php-mysql.i386 0:x.x.x-xx.xxx_x.x set to be updated
--> Processing Dependency: php-pdo for package: php-mysql
---> Package php.i386 0:x.x.x-xx.xxx_x.x set to be updated
--> Processing Dependency: php-cli = x.x.x-xx.xxx_x.x for package: php
---> Package mod_ssl.i386 1:x.x.x-xx.xxx_x.centos.4 set to be updated
--> Processing Dependency: libdistcache.so.1 for package: mod_ssl
--> Processing Dependency: libnal.so.1 for package: mod_ssl
--> Running transaction check
---> Package distcache.i386 0:x.x.x-xx.x set to be updated
---> Package php-cli.i386 0:x.x.x-xx.xxx_x.x set to be updated
---> Package perl-DBI.i386 0:x.xx-x.xxx set to be updated
---> Package php-pdo.i386 0:x.x.x-xx.xxx_x.x set to be updated
---> Package php-common.i386 0:x.x.x-xx.xxx_x.x set to be updated
---> Package perl-DBD-MySQL.i386 0:x.xxxx-x.xxx set to be updated
---> Package mysql.i386 0:x.x.xx-x.xxx set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
mod_ssl i386 1:x.x.x-xx.xxx_x.centos.4 updates 85 k
mysql-server i386 x.x.xx-x.xxx base 9.7 M
php i386 x.x.x-xx.xxx_x.x updates 1.1 M
php-mbstring i386 x.x.x-xx.xxx_x.x updates 969 k
php-mysql i386 x.x.x-xx.xxx_x.x updates 84 k
Installing for dependencies:
distcache i386 x.x.x-xx.x base 119 k
httpd i386 x.x.x-xx.xxx_x.centos.4 updates 1.1 M
mysql i386 x.x.xx-x.xxx base 4.1 M
perl-DBD-MySQL i386 x.xxxx-x.xxx base 147 k
perl-DBI i386 x.xx-x.xxx base 605 k
php-cli i386 x.x.x-xx.xxx_x.x updates 2.1 M
php-common i386 x.x.x-xx.xxx_x.x updates 154 k
php-pdo i386 x.x.x-xx.xxx_x.x updates 62 k
Transaction Summary
=============================================================================
Install 13 Package(s)
Update 0 Package(s)
Remove 0 Package(s)
Total download size: 20 M
Downloading Packages:
(1/13): mod_ssl-x.x.x-xx. 100% |=========================| 85 kB 00:00
(2/13): php-x.x.x-xx.xxx_ 100% |=========================| 1.1 MB 00:00
(3/13): mysql-x.x.xx-x.xx 100% |=========================| 4.1 MB 00:00
(4/13): php-mysql-x.x.x-x 100% |=========================| 84 kB 00:00
(5/13): perl-DBD-MySQL-x. 100% |=========================| 147 kB 00:00
(6/13): httpd-x.x.x-xx.xx 100% |=========================| 1.1 MB 00:00
(7/13): mysql-server-x.x. 100% |=========================| 9.7 MB 00:02
(8/13): php-common-x.x.x- 100% |=========================| 154 kB 00:00
(9/13): php-mbstring-x.x. 100% |=========================| 969 kB 00:00
(10/13): php-pdo-x.x.x-xx 100% |=========================| 62 kB 00:00
(11/13): perl-DBI-x.xx-x. 100% |=========================| 605 kB 00:00
(12/13): php-cli-x.x.x-xx 100% |=========================| 2.1 MB 00:00
(13/13): distcache-x.x.x- 100% |=========================| 119 kB 00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: php-common ####################### [ 1/13]
Installing: perl-DBI ####################### [ 2/13]
Installing: mysql ####################### [ 3/13]
Installing: httpd ####################### [ 4/13]
Installing: perl-DBD-MySQL ####################### [ 5/13]
Installing: php-cli ####################### [ 6/13]
Installing: php-pdo ####################### [ 7/13]
Installing: distcache ####################### [ 8/13]
Installing: php-mbstring ####################### [ 9/13]
Installing: mysql-server ####################### [10/13]
Installing: php-mysql ####################### [11/13]
Installing: php ####################### [12/13]
Installing: mod_ssl ####################### [13/13]
Installed: mod_ssl.i386 1:x.x.x-xx.xxx_x.centos.4 mysql-server.i386 0:x.x.xx-x.xxx php.i386 0:x.x.x-xx.xxx_x.x php-mbstring.i386 0:x.x.x-xx.xxx_x.x php-mysql.i386 0:x.x.x-xx.xxx_x.x
Dependency Installed: distcache.i386 0:x.x.x-xx.x httpd.i386 0:x.x.x-xx.xxx_x.centos.4 mysql.i386 0:x.x.xx-x.xxx perl-DBD-MySQL.i386 0:x.xxxx-x.xxx
perl-DBI.i386 0:x.xx-x.xxx php-cli.i386 0:x.x.x-xx.xxx_x.x php-common.i386 0:x.x.x-xx.xxx_x.x php-pdo.i386 0:x.x.x-xx.xxx_x.x
Complete!
#
# ServerAdmin: Your address, where problems with the server should be
# e-mailed. This address appears on some server-generated pages, such
# as error documents. e.g. admin@your-domain.com
#
管理者メールアドレスを変更します
ServerAdmin centos@sa-sa-ki.jp
#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If this is not set to valid DNS name for your host, server-generated
# redirections will not work. See also the UseCanonicalName directive.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
# You will have to access it by its address anyway, and this will make
# redirections work in a sensible way.
#
先頭の#を取ってコメントを解除し、サーバー名を変更します
ServerName www.sa-sa-ki.jp:80
#
# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
#
# First, we configure the "default" to be a very restrictive set of
# features.
#
<Directory />
FollowSymLinksからNoneに変更してオプションを無効にします
Options None
AllowOverride None
全てのアクセスを拒否します
Order deny,allow
Deny from all
</Directory>
<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.
#
IndexesからExecCGIに変更してCGIスクリプトの実行を許可しドキュメントルートのファイル一覧を表示しないようにします
Options ExecCGI 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
#
NoneからAllに変更してファイルアクセス(.htaccess)の使用可能な指示子を全て許可にします
AllowOverride All
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
</Directory>
#
# AddHandler allows you to map certain file extensions to "handlers":
# actions unrelated to filetype. These can be either built into the server
# or added with the Action directive (see below)
#
# To use CGI scripts outside of ScriptAliased directories:
# (You will also need to add "ExecCGI" to the "Options" directive.)
#
CGIスクリプトに拡張子.plを追加します
AddHandler cgi-script .cgi .pl
#
# Optionally add a line containing the server version and virtual host
# name to server-generated pages (internal error documents, FTP directory
# listings, mod_status and mod_info output etc., but not CGI generated
# documents or custom error documents).
# Set to "EMail" to also include a mailto: link to the ServerAdmin.
# Set to one of: On | Off | EMail
#
エラーページにApacheのバージョンを表示しないようにOn から Off に変更
ServerSignature Off
#
# Aliases: Add here as many aliases as you need (with no limit). The format is
# Alias fakename realname
#
# Note that if you include a trailing / on fakename then the server will
# require it to be present in the URL. So "/icons" isn't aliased in this
# example, only "/icons/". If the fakename is slash-terminated, then the
# realname must also be slash terminated, and if the fakename omits the
# trailing slash, the realname must also omit it.
#
# We include the /icons/ alias for FancyIndexed directory listings. If you
# do not use FancyIndexing, you may comment this out.
#
Alias /icons/ "/var/www/icons/"
<Directory "/var/www/icons">
Options Indexesを削除してiconsディレクトリのファイル一覧を表示しないようにします
Options MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
内容を保存しviエディタを終了します
所有ユーザとグループがapacheになっている事を確認します
内容を保存しviエディタを終了します
内容を保存しviエディタを終了します
設定内容を反映します
[root@centos ~]# /etc/rc.d/init.d/iptables restart
ファイアウォールルールを適用中: [ OK ]
チェインポリシーを ACCEPT に設定中filter [ OK ]
iptables モジュールを取り外し中 [ OK ]
iptables ファイアウォールルールを適用中: [ OK ]
iptables モジュールを読み込み中ip_conntrack_netbios_ns [ OK ]
開放方法はルータの設定手順に従って実施してください。
OS再起動時にApacheを自動起動するようにします
[root@centos ~]# chkconfig httpd on
[root@centos ~]# chkconfig --list | grep httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
ApacheとPHPのバージョン情報を隠蔽する設定をしたのでその確認をします。
内容を保存しviエディタを終了します
telnetコマンドでhttpヘッダーの内容を確認します
[root@centos ~]# telnet www.sa-sa-ki.jp 80
Trying 192.168.0.20...
Connected to www.sa-sa-ki.jp (192.168.0.20).
Escape character is '^]'.
HEAD /index.html HTTP/1.0
もう一度[Enter]キーを押下してください
HTTP/1.1 200 OK
Date: Fri, 27 Mar 2009 02:20:01 GMT
Apacheのバージョンが表示されていない
Server: Apache
X-Powered-By: PHP/x.x.xも表示されていない
X-Pingback: http://www.sa-sa-ki.jp/blog/xmlrpc.php
Connection: close
Content-Type: text/html; charset=UTF-8
Connection closed by foreign host.
次に存在しないページにブラウザでアクセスして、ApacheやPHPのバージョン情報が表示されない事を確認します。

最後に作成したtest.phpページにブラウザでアクセスして、ApacheとPHPが正常に動いているか確認します。

※セキュリティの為、表示されている情報は隠しています
次回はMySQLの初期設定を行います。
■ 参考サイト ■
Webサーバー構築(Apache) - CentOSで自宅サーバー構築
はじめての自宅サーバ構築 Fedora/CentOS - Webサーバの構築(apache)
■関連記事
自宅サーバー再構築 その1 導入を検討する
自宅サーバー再構築 その2 CentOS 5.2 をインストールする
自宅サーバー再構築 その3 インストールしたCentOS 5.2 にリモート接続準備
自宅サーバー再構築 その4 CentOS 5.2 インストール後の初期設定
自宅サーバー再構築 その5 CentOS 5.2 ファイル転送準備
自宅サーバー再構築 その6 CentOS 5.2 にアンチウィルスソフトを導入する
自宅サーバー再構築 その7 CentOS 5.2 にファイル改竄検知システムを導入する
自宅サーバー再構築 その8 CentOS 5.2 にrootkit検知ツールを導入する
自宅サーバー再構築 その9 CentOS 5.2 にバッファオーバーフロー攻撃対策を行う
自宅サーバー再構築 その10 CentOS 5.2 SSHサーバーを構築して外部からリモート接続&リモートファイル転送
自宅サーバー再構築 その11 CentOS 5.2 にDNSサーバーを導入して名前解決(設定編)
自宅サーバー再構築 その12 CentOS 5.2 にDNSサーバーを導入して名前解決(確認編)
自宅サーバー再構築 その13 CentOS 5.2 にLAMP環境構築(Apache、PHP編)
自宅サーバー再構築 その14 CentOS 5.2 にLAMP環境構築(MySQL編)
自宅サーバー再構築 その15 Apacheにサーバー証明書を導入する
自宅サーバー再構築 その16 CentOS 5.2 にWordPressを導入してブログサイトを構築する
自宅サーバー再構築 その17 WordPressのセキュリティ対策
自宅サーバー再構築 その18 CentOS 5.3 にNTPサーバーを導入して自動時間合わせ
自宅サーバー再構築 その19 CentOS 5.3 アンチウィルスソフトのバージョンアップ
自宅サーバー再構築 その20 CentOS 5.3 メールサーバー構築(Postfix設定編)
自宅サーバー再構築 その21 CentOS 5.3 メールサーバー構築(Dovecot設定編)
自宅サーバー再構築 その22 CentOS 5.3 メールサーバー構築(公開編)
自宅サーバー再構築 その23 CentOS 5.3 メールサーバー構築(SSL導入編)
自宅サーバー再構築 その24 CentOS 5.3 メールサーバー構築(メールアカウント作成編)
自宅サーバー再構築 その25 CentOS 5.3 メールサーバー構築(Thunderbird設定編)
自宅サーバー再構築 番外編その1 CentOS 5.3 のリリースと導入済みソフトウェアのアップデート
以前flashcast:フリーで働くITエンジニア集団のブログ: ubuntu 8.10にApache、PHP、MySQLをインストールしてLAMP環境を構築するで、ubuntuにLAMP環境を作成する方法をご紹介しましたが、flashcast:フリーで働くITエンジニア集団のブログ: ThinkPad X31にインストールしたubuntu 8.10でトラックポイントを有効にするにはでもお伝えした通り、OS入れ替え作業を行いubuntuがまっさらな状態になってしまいましたので、再度LAMP環境を構築しようと思います。
前回と同じだと面白くないので、今回はXAMPP(ザンプ)をインストールして簡単にLAMP環境を構築したいと思います。
XAMPPのいいところはLAMP環境を構築するための必要なソフトウェアが全て梱包してあり、インストールが簡単でかつ複数のOSで利用可能なところでしょうか。
では、インストールしてみることにします。
まずxamppのパッケージをダウンロードします。
apache friends - xampp
Linux用xamppパッケージのダウンロードはこちらです。
http://www.apachefriends.org/download.php?xampp-linux-1.7.tar.gz
xampp-linux-1.7.tar.gzファイルのダウンロードが終わったら、メニューバーの[アプリケーション]-[アクセサリ]-[端末]を選択します。
端末の画面からコマンドを入力していきます。
ダウンロードしたxampp-linux-1.7.tar.gzを解凍しつつ/optディレクトリへ展開します
root@ubuntu: ~# tar xzvf /home/ubuntu/Desktop/xampp-linux-1.7.tar.gz -C /opt
これで/opt/xamppディレクトリにXAMPPがインストールされました。最後にXAMPPのサービスを起動します
root@ubuntu: ~# /opt/lampp/lampp start
Starting XAMPP for Linux 1.7...
XAMPP: Starting Apache with SSL (and PHP5)...
XAMPP: Starting MySQL...
XAMPP: Starting ProFTPD...
XAMPP for Linux started.
たったこれだけでXAMPPの導入は終わりです。
あとは稼動確認をしてみます。
ブラウザを起動して、アドレスに「http://localhost/」と入力してみてください。
XAMPPのタイトルページが表示されますので、「日本語」というリンクをクリックします。

XAMPPのメニューページへ遷移します。
サービスの動作確認をする為に、左ペインにある「ステータス」リンクをクリックします。

最後にubuntuを再起動する度にXAMPPのサービスを再起動する必要があるのですが、毎回サービス起動するのは面倒くさいのでubuntu起動時に自動でサービスを起動する処理を追加します。
exit 0
保存してviエディタを終了します。
ちなみにサービスの自動起動はRedHat系のLinuxを使ってる人は chkconfig を使ったりしますよね?
ubuntuはchkconfigがデフォルトでインストールされていなかったので、/etc/rc.localを使ってブート時に自動起動してみました。
これでubuntuを再起動してもすぐにXAMPPを使うことができて便利ですね。