Recipe 3.19 Logging Activity to a MySQL Database

Problem

Rather than logging accesses to your server in flat text files, you want to log the information directly to a database for easier analysis.

Solution

Install the latest release of mod_log_sql from http://www.grubbybaby.com/mod_log_sql/ according to the modules directions (see Recipe 2.1), and then issue the following commands:

# mysqladmin create apache_log # mysql apache_log # mysql apache_log < access_log.sql mysql> grant insert,create on apache_log.* to webserver@localhost identified by      'wwwpw';

Add the following lines to your httpd.conf file:

<IfModule mod_log_mysql.c>     MySQLLoginInfo localhost webserver wwwpw     MySQLDatabase apache_log     MySQLTransferLogTable access_log     MySQLTransferLogFormat huSUsbTvRA </IfModule>

Discussion

Note that there is currently a difference between the name of the web location, the tarball, and the actual module. The module file and directory retain the "mysql" name, but the directory and the tarball have moved to a more generic "sql" naming convention.

See Also

  • http://www.grubbybaby.com/mod_log_sql/



Apache Cookbook
Apache Cookbook: Solutions and Examples for Apache Administrators
ISBN: 0596529945
EAN: 2147483647
Year: 2006
Pages: 215

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net