mod_auth_mysql was written in order to allow users to use the blazing quick speed of MySQL in order to store authentication information for their apache web servers.
You can get the module here or from TCX's Contrib directory.
Register mod_auth_mysql!
This manual assumes you've successfully compiled mod_auth_mysql, and that you're now trying to figure out how to use it.
mod_auth_mysql, like other apache authentication modules, is used in order to protect pages with username/password. The unique thing is that the passwords and usernames is stored in a MySQL database for much quicker access. Also, unlike the previous implementation of the module, SQL links are kept alive in between hits to acheive even better performance.
Protecting a directory with a username/password is simple, and involves two steps:
You would generally need one table, that contains 3 fields - username, password, and group. In some cases the group wouldn't be required and in others you may want to have extra fields in that table for other usages. If you already have the database and table with the necessary fields, you can skip to the next phase. Otherwise:
| 1. |
Create a database to store the authentication table, e.g.:
prompt> mysqladmin create http_auth
NOTE: You *don't* have to have this table in a seperate database, you can skip creating a new database
and use an existing database if it fits your needs.
|
| 2. |
Create the auth table, e.g.:
prompt> mysql http_auth
mysql> create table mysql_auth (
-> username char(25),
-> passwd char(25),
-> groups char(25),
-> primary key (username)
-> );
NOTE 1: You *don't* have to use a new table for this purpose; You can use existing fields in existing tables for this purpose.NOTE 2: All of the above names (the table name and field names) are the defaults the module looks for. They CAN be overriden using directives. |
| 3. | Insert the information into the table. Both the username and group fields are pre, whereas with the password, whereas the password field should contain standard UNIX DES encrypted passwords (this can be overriden using a directive as well, but the default is using encrypted passwords). |
| 1. |
If you're using a MySQL server other than localhost, and/or you want to specify a different user than
the httpd user when accessing the MySQL server, and/or you need to specify a password for that user,
you'd need to add the following line somewhere in your httpd.conf (doesn't really matter where):
Auth_MySQL_Info [host] [user] [password]This information can *only* be specified in the server's httpd.conf, since it's used server-wide. |
||||||||||||||||||||||||||
| 2. |
If you're going to use mainly one MySQL database for all of your pages, you should probably add the
following line to your httpd.conf as well:Auth_MySQL_General_DB [database_name]The database can be set on a per-directory basis using a different directive in .htaccess, as mentioned later in this file. |
||||||||||||||||||||||||||
| 3. |
Create (or update) a file named .htaccess inside the directory you would like to protect. Here are a few
simple .htaccess files (full documentation about the various possible non-MySQL-auth specific directives
can be obtained from the apache docs):
Allow any known user to accses:
Allow access only to specific users:
Allow only members of group 'executives' access the information:
AuthName "My Company's Financial Information" |
||||||||||||||||||||||||||
| 4. |
Take a look at the following directives, and see if you need to use any of them:
|