mod_log_sql 2.0 Documentation

Home » Projects » Apache » Mod_log_sql » Docs-2.0 » mod_log_sql 2.0 Documentation

Prev: Preparing MySQL for logging --- Up: Configuration --- Next: Testing the basic setup

A very basic logging setup in Apache

  1. Tell the module what database to use and the appropriate authentication information.

    So, edit httpd.conf and insert the following lines somewhere after any LoadModule / AddModule statements. Make sure these statements are "global," i.e. not inside any VirtualHost stanza. You will also note that you are embedding a password in the file. Therefore you are advised to "chmod 660 httpd.conf" to prevent unauthorized regular users from viewing your database user and password.

    Use the MySQL database called "apachelogs" running on "dbmachine.foo.com". Use username "loguser" and password "l0gg3r" to authenticate to the database. Permit the module create tables for us.

    Basic Example

    LogSQLLoginInfo mysql://loguser:l0gg3r@dbmachine.foo.com/apachelogs
    LogSQLCreateTables on

    If your database resides on localhost instead of another host, specify the MySQL server's socket file as follows:

    LogSQLDBParam socketfile /your/path/to/mysql.sock

    If your database is listening on a port other than 3306, specify the correct TCP port as follows:

    LogSQLDBParam port 1234
  2. The actual logging is set up on a virtual-host-by-host basis. So, skip down to the virtual host you want to set up. Instruct this virtual host to log entries to the table "access_log" by inserting a LogSQLTransferLogTable directive. (The LogSQLTransferLogTable directive is the minimum required to log -- other directives that you will learn about later simply tune the module's behavior.)

    <VirtualHost 1.2.3.4>
     [snip]
     LogSQLTransferLogTable access_log
     [snip]
    </VirtualHost>
  3. Restart apache.

    # /etc/rc.d/init.d/httpd stop
    # /etc/rc.d/init.d/httpd start