久々のサーバ構築案件なので、忘れんようにメモ。
今回作成するホスト www.example.com はバーチャルホストとして作ります。
そして、 www.example.com のFTPアカウントはMySQLで管理します。
今後、FTPアカウントの管理やバーチャルホストのconfigはプログラムにやらせたいなー。

■■ webスペースの領域作成

FTPアカウントは今後MySQLに管理させます。ここのUID/GIDは、UNIXアカウントとは別物です。
FTPアカウントをMySQLに管理させる方法は次のエントリに書きます。乞うご期待!

[root@hoge ~]# mkdir /home/vhost
[root@hoge ~]# mkdir -p /home/vhost/www.example.com/{html,cgi-bin,logs,auth}
[root@hoge ~]# chown -R 1000:1000 /home/vhost/

■■ apache インストール

[root@hoge ~]# yum install httpd mod_ssl
(中略)
Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 httpd                   i386       2.0.52-38.ent.centos4.2  update            891 k
 mod_ssl                 i386       1:2.0.52-38.ent.centos4.2  update            100 k
Installing for dependencies:
 apr                     i386       0.9.4-24.9       base               93 k
 apr-util                i386       0.9.4-21         base               51 k
 distcache               i386       1.4.5-6          base              111 k
 httpd-suexec            i386       2.0.52-38.ent.centos4.2  update             30 k

Transaction Summary
=============================================================================
Install      6 Package(s)
Update       0 Package(s)
Remove       0 Package(s)
Total download size: 1.2 M
Is this ok [y/N]: y

■■ php5のインストール

通常、CentOS4.x系では、yumコマンドでphpをインストールしようとすると、
PHP4系がインストールされます。しかし、もうサポート終わってるので
(セキュリティサポートは2008年8月まで)
centosplusリポジトリを一時的に有効にしてやってPHP5をインストールしてやります。

[root@hoge ~]# yum –enablerepo=centosplus install php
(中略)
Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 php                     i386       5.1.6-3.el4s1.8  centosplus        1.1 M
Installing for dependencies:
 curl                    i386       7.12.1-11.el4    base              230 k
 libidn                  i386       0.5.6-1          base              169 k
 php-cli                 i386       5.1.6-3.el4s1.8  centosplus        2.0 M
 php-common              i386       5.1.6-3.el4s1.8  centosplus        136 k

Transaction Summary
=============================================================================
Install      5 Package(s)
Update       0 Package(s)
Remove       0 Package(s)
Total download size: 3.7 M
Is this ok [y/N]: y

■ さらに、pearもcentosplus経由でインストールする

[root@hoge ~]# yum –enablerepo=centosplus install php-pear
(中略)
Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 php-pear                noarch     1:1.4.11-1.el4s1.1  centosplus        345 k

Transaction Summary
=============================================================================
Install      1 Package(s)
Update       0 Package(s)
Remove       0 Package(s)
Total download size: 345 k
Is this ok [y/N]: y

■ pearが有効になっているか確認する

[root@hoge ~]# pear list
Installed packages, channel pear.php.net:
=========================================
Package        Version State
Archive_Tar    1.3.1   stable
Console_Getopt 1.2     stable
PEAR           1.4.11  stable
XML_RPC        1.5.1   stable

■■ apacheの設定を修正する

■ httpd.confを修正する

[root@hoge ~]# cd /etc/httpd/conf
[root@ho
ge conf]# cp -p httpd.conf httpd.conf.orig
[root@hoge conf]# vi httpd.conf

#—- ServerTokensディレクティブでの表示を最小限にするため
#—- ここを
#—- ServerTokens OS
#—-
#—- こうする
#—- #ServerTokens OS
#—- ServerTokens Prod

#—- サーバ管理者のメールアドレスを変更するため
#—- ここを
#—- ServerAdmin root@localhost
#—-
#—- こうする
#—- #ServerAdmin root@localhost
#—- ServerAdmin webmaster@hoge.example.com

#—- すべてvirtualhostで管理するので、以下をコメントアウトする
#—-
#—- ここを
#—- DocumentRoot “/var/www/html”
#—- こうする
#—- #DocumentRoot “/var/www/html”
#—-
#—- ここを
#—- <Directory />
#—-     Options FollowSymLinks
#—-     AllowOverride None
#—- </Directory>
#—-
#—- こうする
#—- #<Directory />
#—- #    Options FollowSymLinks
#—- #    AllowOverride None
#—- #</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.0/mod/core.html#options
#—- # for more information.
#—- #
#—-     Options Indexes 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
#—-
#—- #
#—- # Controls who can get stuff from this server.
#—- #
#—-     Order allow,deny
#—-     Allow from all
#—-
#—- </Directory>
#—-
#—- こうする
#—- ##### comented by nullpopopo 2008/02/10
#—- #<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
#—- #
#—- ##
#—- ## 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
#—- #
#—- ##
#—- ## Controls who can get stuff from this server.
#—- ##
#—- #    Order allow,deny
#—- #    Allow from all
#—- #
#—- #</Directory>

#—- userdirを使わないので無効にする
#—-
#—- ここを
#—- <IfModule mod_userdir.c>
#—-     #
#—-     # UserDir is disabled by default since it can confirm the presence
#—-     # of a username on the system (depending on home directory
#—-     # permissions).
#—-     #
#—-     UserDir disable
#—-
#—-     #
#—-     # To enable requests to /~user/ to serve the user’s public_html
#—-     # directory, remove the “UserDir disable” line above, and uncomment
#—-     # the following line instead:
#—-     #
#—-     #UserDir public_html
#—-
#—- </IfModule>
#—-
#—- こうする
#—- ##### comented by nullpopopo 2008/02/10
#—- #<IfModule mod_userdir.c>
#—- #    #
#—- #    # UserDir is disabled by default since it can confirm the presence
#—- #    # of a username on the system (depending on home directory
#—- #    # permissions).
#—- #    #
#—- #    UserDir disable
#—- #
#—- #    #
#—- #    # To enable requests to /~user/ to serve the user’s public_html
#—- #    # directory, remove the “UserDir disable” line above, and uncomment
#—- #    # the following line instead:
#—- #    #
#—- #    #UserDir public_html
#—- #
#—- #</IfModule>
#—-

#—- ServerSignatureをOffにしてApache が生成したドキュメント中の情報を抑制する
#—-
#—- ここを
#—- ServerSignature On
#—-
#—- こうする
#—- #ServerSignature On
#—- ServerSignature Off

#—- WebDAVを使わないので無効にする
#—-
#—- ここを
#—- #
#—- # WebDAV module configuration section.
#—- #
#—- <IfModule mod_dav_fs.c>
#—-     # Location of the WebDAV lock database.
#—-     DAVLockDB /var/lib/dav/lockdb
#—- </IfModule>
#—-
#—- こうする
#—- ##
#—- ## WebDAV module configuration section.
#—- ##
#—- #<IfModule mod_dav_fs.c>
#—- #    # Location of the WebDAV lock database.
#—- #    DAVLockDB /var/lib/dav/lockdb
#—- #</IfModule>

#—- /var/www/cgi-bin/ を使わないので無効にする
#—-
#—- ここを
#—- #
#—- # ScriptAlias: This controls which directories contain server scripts.
#—- # ScriptAliases are essentially the same as Aliases, except that
#—- # documents in the realname directory are treated as applications and
#—- # run by the server when requested rather than as documents sent to the client.
#—- # The same rules about trailing “/” apply to ScriptAlias directives as to
#—- # Alias.
#—- #
#—- ScriptAlias /cgi-bin/ “/var/www/cgi-bin/”
#—-
#—- #
#—- # “/var/www/cgi-bin” should be changed to whatever your ScriptAliased
#—- # CGI directory exists, if you have that configured.
#—- #
#—- <Directory “/var/www/cgi-bin”>
#—-     AllowOverride None
#—-     Options None
#—-     Order allow,deny
#—-     Allow from all
#—- </Directory>
#—-
#—- こうする
#—- ##
#—- ## ScriptAlias: This controls which directories contain server scripts.
#—- ## ScriptAliases are essentially the same as Aliases, except that
#—- ## documents in the realname directory are treated as applications and
#—- ## run by the server when requested rather than as documents sent to the client.
#—- ## The same rules about trai
ling “/” apply to ScriptAlias directives as to
#—- ## Alias.
#—- ##
#—- #ScriptAlias /cgi-bin/ “/var/www/cgi-bin/”
#—- #
#—- ##
#—- ## “/var/www/cgi-bin” should be changed to whatever your ScriptAliased
#—- ## CGI directory exists, if you have that configured.
#—- ##
#—- #<Directory “/var/www/cgi-bin”>
#—- #    AllowOverride None
#—- #    Options None
#—- #    Order allow,deny
#—- #    Allow from all
#—- #</Directory>

#—- 言語設定のUTF-8固定を無効にする
#—-
#—- ここを
#—- AddDefaultCharset UTF-8
#—-
#—- こうする
#—- #AddDefaultCharset UTF-8
#—- AddDefaultCharset Off

#—- 最終行に、バーチャルホスト用のディレクトリをincludeする設定を書く
#—-
#—- Include conf/vconf.d/*.conf

ここまで終わったらhttpd.confを保存します。

■ vconf.d 作成

[root@hoge conf]# pwd
/etc/httpd/conf
[root@hoge conf]# mkdir vconf.d

■ vconf.d にダミー用ホストのconfigを書く

[root@hoge conf]# cd vconf.d
[root@hoge vconf.d]# vi www.example.com.conf
<VirtualHost 192.168.0.110:80>
    DocumentRoot /home/vhost/www.example.com/html
    ServerName www.example.com
    ErrorLog /home/vhost/www.example.com/logs/error.log
    CustomLog /home/vhost/www.example.com/logs/access.log combined

    <Directory /home/vhost/www.example.com/html>
        Options Indexes FollowSymlinks MultiViews
        AllowOverride Fileinfo AuthConfig
        #AllowOverride All
        order allow,deny
        Allow from all
    </Directory>

    ScriptAlias /cgi-bin /home/vhost/www.example.com/cgi-bin
    <Directory /home/vhost/www.example.com/cgi-bin>
        Options ExecCGI
        AllowOverride Fileinfo AuthConfig
        order allow,deny
        Allow from all
    </Directory>

</VirtualHost>

■ ダミー用ホストのコンテンツディレクトリにテストファイルを置く

[root@hoge vconf.d]# cd /home/vhost/www.example.com/
[root@hoge www.example.com]# basename `pwd` > html/index.html

[root@hoge www.example.com]# vi html/phpinfo.php
<?php
  phpinfo();
?>

[root@hoge www.example.com]# cd cgi-bin/
[root@hoge cgi-bin]# vi test.cgi
#!/usr/bin/perl

print “Content-type: text/html\n\n”;
print “<html><body>test</body></html>”;

[root@hoge cgi-bin]# chmod 755 test.cgi
[root@hoge cgi-bin]# cd ../
[root@hoge www.example.com]# chown -R webmaster. *

■■ apacheの設定確認と起動

■ 設定確認

[root@hoge www.example.com]# cd
[root@hoge ~]# httpd -t -D DUMP_VHOSTS
VirtualHost configuration:
192.168.0.110:80       www.example.com (/etc/httpd/conf/vconf.d/www.example.com.conf:1)
wildcard NameVirtualHosts and _default_ servers:
_default_:443          hoge.example.com (/etc/httpd/conf.d/ssl.conf:88)
Syntax OK

■ 起動

[root@hoge ~]# /etc/init.d/httpd start
Starting httpd:                                            [  OK  ]

■ 自動起動設定

[root@hoge ~]# chkconfig httpd –list
httpd           0:off   1:off   2:off   3:off   4:off   5:off   6:off

[root@hoge ~]# chkconfig httpd on

[root@hoge ~]# chkconfig httpd –list
httpd           0:off   1:off   2:on    3:on    4:on    5:on    6:off

■ エラーログ確認

[root@hoge ~]# cat /var/log/httpd/error_log
[Sun Feb 10 13:26:43 2008] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Sun Feb 10 13:26:44 2008] [notice] Digest: generating secret for digest authentication …
[Sun Feb 10 13:26:44 2008] [notice] Digest: done
[Sun Feb 10 13:26:44 2008] [notice] LDAP: Built with OpenLDAP LDAP SDK
[Sun Feb 10 13:26:44 2008] [notice] LDAP: SSL support unavailable
[Sun Feb 10 13:26:45 2008] [notice] Apache configured — resuming normal operations

■■ クライアントのHOSTSファイルで名前解決をして、ブラウザでアクセスする

[hostsへ以下のように書く]
192.168.0.2    www.example.com

[ブラウザで以下のURLにアクセスする]
http://www.example.com/
http://www.example.com/phpinfo.php
http://www.example.com/cgi-bin/test.cgi

No comment


Name


Email (will not pubblished)


Website/URL