OpenStats - installation and config

Installation and configuration of the OpenStats library consists of several quite simple steps - let's investigate them a little bit.

The installation has three main steps:

Download and installation of source codes

All the source codes are available for download on sf.net, on the project site. You may download either complete package with all the parts included (logging, analytic and reporting library, documentation, unit tests, etc.) or packages for each part separately.

Download the complete package (openstats-full-xxx.zip) and unpack it - a directory openstats-xxx with the following structure will be created:

  • README - file with all the basic information about project
  • LICENSE - license agreement (GPL v2)
  • cron - scripts used to process collected data
  • doc - documentation (API description in the javadoc style, examples, etc.)
  • gui - web interface used to display generated reports
  • lib - source codes of the library
  • sql - scripts used to create DB structure (tables, indexes, triggers, ...)
  • test - unit tests

To use the library, you need just the "lib" and "sql" directories with necessary source codes (the following list may not be exact) and SQL script used to create DB structure (see the following section):

  • openstats_db.php
  • openstats_db_resultset.php
  • openstats_logging.php
  • openstats_analysis.php
  • openstats_reporting.php

These files may be copied into the directory placed to include_path - I recommend not to mix them with the other libraries, i.e. create a new directory, copy the files into it and to append the directory to include_path.

You don't have to load all the files manually - you just need to load the main file (e.g. openstats_logging.php for logging) - it will load all the needed files automatically:

<?php

    // load the necessary libraries
    require_once('openstats/openstats_logging.php');

    ... all the necessary files are loaded ...

?>

Creation of DB tables, triggers, ...

Directory "sql" contains a single SQL script create.sql that takes care of everything - especially (not necessarily in the following order):

  • creates tables
  • loads data into code-books
  • creates indexes (and unique constraints)
  • creates foreign keys
  • creates triggers

Again - I recommend not to mix the other application tables with openstats tables (there may exist other tables with the same name), so it's better to use separate schema or a completely separate database (maybe even on a different machine).

$ createdb -U postgres openstats
$ createlang -U postgres plpgsql openstats
$ createuser -U postgres openstats
$ psql -U openstats < create.sql

Now the DB structure is created.

Note: If your project has a lot of visitors, it's good to think about some optimizations when creating the structure. For example all three main tables (Sessions, Actions and Parameters) may grow quite qickly, you won't harm anything by placing them to a separate TABLESPACE (on a separate drive) - logging of statistics won't interfere with other I/O operations, etc.

If you've created the tables in a separate schema, read the following section too.

necessary settings

There is only one tiny problem if you've created the database structure in a separate schema - it's necessary to ensure the PHP library and triggers will find the proper tables. You may do that by suitable settings of search_path PostgreSQL option (but carefully, this may disrupt operation of you application), or by setting OPENSTATS_SCHEMA constant to the name of used schema:

<?php

    // set OPENSTATS_SCHEMA to the schema name
    define('OPENSTATS_SCHEMA', 'openstats');

?>

Library function will then set the schema before executing a SQL query, and set it to the original value before returning (you may do the same thing manually).

Comments

There are no comments for this article (or are awaiting acceptance).

New comment

All the comments have to be accepted, so there may be some delay between submitting and accepting (or rejecting) the comment. If you enter the e-mail address, you will be informed about acceptance or rejection.

Subject or body may not contain HTML tags - they will be automatically removed. Paragraphs may be separated using a newline (ENTER).

(optional)