« 話題のメガマックを食らう! | メイン | 合気道を極めるとこんなに強くなれる! »
March 01, 2007
mod_auth_mysqlをインストールしてみる
興味本位でmod_auth_mysqlを会社のテストサーバーにインストールしてみたので、手順の説明。
テスト環境:
OS:RHLinux9
Apache:v2.0.53
Mysql:v4.0.23
まずはソースをココからダウンロード
以下手順
ソースを解凍し、ディレクトリに移動
#tar zxvf mod_auth_mysql-2.8.1.tar.gz #cd mod_auth_mysql-2.8.1 #ls -l -rw-r--r-- 1 root root 3356 12月 15 2004 BUILD -rw-r--r-- 1 root root 3565 12月 15 2004 CHANGES -rw-r--r-- 1 root root 13630 12月 11 2004 CONFIGURE -rw-r--r-- 1 root root 434 12月 8 2004 README -rw-r--r-- 1 root root 37995 12月 15 2004 mod_auth_mysql.c
とりあえずBUILDの中身を見てコンパイル方法をチェックしExampleの指示通りに実行
#apxs -c -L/usr/lib/mysql -I/usr/include/mysql -lmysqlclient -lm -lz mod_auth_mysql.c (-L/usr/lib/mysqlと -I/usr/include/mysql オプションはサーバーの環境に合わせてパスを変更してください)
コンパイルが終わるとファイルがいくつか出来ています
#ls -l -rw-r--r-- 1 root root 3356 12月 15 2004 BUILD -rw-r--r-- 1 root root 3565 12月 15 2004 CHANGES -rw-r--r-- 1 root root 13630 12月 11 2004 CONFIGURE -rw-r--r-- 1 root root 434 12月 8 2004 README -rw-r--r-- 1 root root 37995 12月 15 2004 mod_auth_mysql.c -rw-r--r-- 1 root root 927 3月 1 11:45 mod_auth_mysql.la -rw-r--r-- 1 root root 333 3月 1 11:45 mod_auth_mysql.lo -rw-r--r-- 1 root root 87064 3月 1 11:45 mod_auth_mysql.o -rw-r--r-- 1 root root 0 3月 1 11:45 mod_auth_mysql.slo
Apache2系ではmod_auth_mysql.laを使うらしいので、BUILDの指示通りapxsを実行
#apxs -i mod_auth_mysql.la
実行が完了すると/usr/local/apache2(Apacheインストールディレクトリ)下のmodulesディレクトリ下にmod_auth_mysql.soが出来ます。
#ls -l /usr/local/apache2/modules -rw-r--r-- 1 root root 8440 3月 28 2005 httpd.exp -rwxr-xr-x 1 root root 7083747 3月 28 2005 libphp4.so -rwxr-xr-x 1 root root 74199 3月 1 11:47 mod_auth_mysql.so
これまた指示通りhttpd.confにLoadModuleの設定する
#vi httpd.conf LoadModule mysql_auth_module modules/mod_auth_mysql.so # #Apacheを再起動して組み込み完了 #apachectl restart #
あとはMySQLに認証用のDBとテーブルを作成
データベース名: webauth テーブル名: user_pwd create table user_pwd ( name varchr(30) not null, pass varchar(30), primary key (name) );
最後に.htaccessをこんな感じで作成
AuthName "mod_auth_mysql Page" AuthType Basic require valid-user AuthMySQLHost localhost AuthMySQLDB webauth AuthMySQLUser mysql AuthMySQLPassword fugafuga AuthMySQLUserTable user_pwd AuthMySQLNameField name AuthMySQLPasswordField pass AuthMySQLCryptedPasswords Off
で.htaccessを設置したディレクトリにブラウザでアクセスして、ベーシック認証画面が表示されDBに登録したユーザー名とパスワードでログインが出ればインストール成功です。
参考サイト:
MySQLを使ったデータベース認証
http://tsuttayo.sytes.net/apache/access/db/
Author nitoka : March 1, 2007 12:26 PM
TrackBack
TrackBack URL:
http://www.nitoka.net/blog/mt-tb.cgi/288


