An easy way to quickly redirect Apache's access log to a database with absolutely no scripting.

With ApacheLogToDB, you will be required to perform a few simple configuration tasks once and then everything will be automated. You can choose Apache's log format that best suits your preferences, and ApacheLogToDB will create the appropriate database table for you. ApacheLogToDB uses native database drivers to archieve optimum performance and meet highest security standards.
  • Microsoft SQL Server (including free Express Edition) and MySQL databases are currently supported.
  • ApacheLogToDB requires .NET Framework to be installed.

Install And Configuration

  • Deploy ApacheLogToDB's files in the \bin subfolder of your Apache Server installation.
  • Add the following lines to Apache's configuration file httpd.conf (the path must be adjusted in 3rd line):
LoadModule log_config_module modules/
LogFormat "|%h|%l|%u|%t|%r|%>s|%b" db_log
CustomLog "|C:/Apache/bin/ApacheLogToDb.exe" db_log
  • Now the log in Common Log Format (CLF) will be handled by ApacheLogToDB. If you need to customize log format, you can find all necessary instructions at this page.
  • Open ApacheLogToDB.conf.xml configuration file and adjust the following parameters:
    • dbType - It can be either sqlsrv (Microsoft SQL Server) or mysql (MySQL). Default is sqlsrv.
    • dbHost - Address or name of the database instance to which to connect. Default is localhost.
    • dbName - Name of the database in which log records must be stored.
    • dbTable - Name of the table in which log records must be stored.
    • dbUser - Login name of the database user.
    • dbPassword - Database user's password.
    • maxParamLength - If any log record's parameter exceeds this number of characters, the overhead will be cut off. Default is 255. If maxParamLength is set to 0, no cutting occurs.
  • There are many more parameters available, full list and more detailed descriptions can be found here.
  • (Skip this step if you would like to use pre-existing database and user login.) After saving ApacheLogToDB's configuration file, open your database management program and launch one of the the following scripts: this for SQL Server or that for MySQL. The script will create database and database user with all required permissions. Insert database name and user name into the script as it was specified in dbName and dbUser configuration settings in ApacheLogToDB.conf.xml file (see above).
  • Finally launch the following commands from the Windows command line (correct the path as necessary):
cd C:\Apache\bin
ApacheLogToDB.exe -createTableAndExit
  • This will automatically create a database table according to the log format, which was specified in apacheLogFormat configuration setting. Review the table and tune it if necessary. (No indexes are created by default.) Some troubleshooting tips can be found here.
  • Restart Apache HTTP Server. That's all, enjoy!

Last edited Oct 24, 2013 at 10:09 AM by CodeDriller, version 23