mod_auth_mysqlのインストール(Windows編)

   1.  Apache webserver binaries and module binariesから
      Apacheのバージョンに合わせたmod_auth_mysql-w32.zipをダウンロードする。
   2. ダウンロードしたファイルを解凍する。
   3. 解凍したファイルのうち、mod_auth_mysql.soをApacheのインストール・ディレクトリの中のmodulesフォルダにコピーする。
   4. httpd.confの編集
      以下の行を追加する。
      LoadModule mysql_auth_module modules/mod_auth_mysql.so
   5. Apacheの再起動する。


MySQLの準備

MySQLへユーザーIDとパスワードを記述するデータベース作成。

データベース名: webauth
テーブル名: user_pwd

テーブル「user_pwd」を作成する。
create table user_pwd (
  name varchr(30) not null,
  pass varchar(30),
  primary key (name)
);

user_pwdにユーザー名とパスワードを登録する。


.htaccessの準備
アクセス制御したいディレクトリに.htaccessというファイルを作る。

  AuthName "mod_auth_mysql による認証"(パスワード入力画面のタイトル)
  AuthType Basic
  require valid-user
  AuthMySQLHost localhost
  AuthMySQLDB webauth(データベースの名前 )	      
  AuthMySQLUser user名
  AuthMySQLPassword userのパスワード
  AuthMySQLUserTable user_pwd(テーブル名)
  AuthMySQLNameField name(ユーザーIDを保存するフィールド名)
  AuthMySQLPasswordField pass(パスワードを保存するフィールド名)
  AuthMySQLCryptedPasswords Off

これで、アクセス制御を設定したページが出来上がる。