Alunduil's Hosting Gentoo Hackery and Other Fun …

2Mar/10

Running awstats on Gentoo

Requirements

I'm assuming for this quick guide that you already have a website installed and consequently apache.

emerge -av awstats

A quick breakdown on the use flags from gentookit's equery:

  • apache2 : Add Apache2 support
  • geoip : Add geoip support for country and city lookup based on IPs
  • vhosts : Adds support for installing web-based applications into a virtual-hosting environment

Configuration

Lots of configuration needs to occur for awstats to work correctly:

First, we need to setup a configuration file for the web site so we can update the statistics. cp /etc/awstats/awstats.model.conf /etc/awstats/awstats..conf

Where fqdn is the fully qualified domain name of your website you'll be monitoriing. After you've copied the default configuration customize it for your particular website.

Second, you need to enable awstats in your apache vhost configuration:

CustomLog /var/www/localhost/log/apache/production.log combined

Alias /awstats/classes "/usr/share/webapps/awstats/6.9-r1/htdocs/classes/"
Alias /awstats/css "/usr/share/webapps/awstats/6.9-r1/htdocs/css/"
Alias /awstats/icons "/usr/share/webapps/awstats/6.9-r1/htdocs/icon/"
ScriptAlias /awstats/ "/usr/share/webapps/awstats/6.9-r1/hostroot/cgi-bin/"
ScriptAlias /awstats "/usr/share/webapps/awstats/6.9-r1/hostroot/cgi-bin/awstats.pl"
ScriptAlias /awstats.pl "/usr/share/webapps/awstats/6.9-r1/hostroot/cgi-bin/awstats.pl"

<Directory "/usr/share/webapps/awstats/6.9-r1/htdocs">
   Options None
   AllowOverride None
   <IfModule mod_access.c>
       Order allow,deny
       Allow from all
   </IfModule>
</Directory>

<Directory "/usr/share/webapps/awstats/6.9-r1/hostroot/cgi-bin">
    Options ExecCGI
    AllowOverride None
    <IfModule mod_access.c>
        Order allow,deny
        Allow from all
    </IfModule>
</Directory>

<Directory "/usr/share/webapps/awstats/6.9-r1/hostroot">
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

<Directory "/usr/share/webapps/awstats/6.9-r1/htdocs/icon">
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

And verify the logging output in /etc/apache2/modules.d/00_mod_log_config.conf:

<IfModule log_config_module>
    # The following directives define some format nicknames for use with
    # a CustomLog directive (see below).
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    LogFormat "%{Referer}i -> %U" referer
    LogFormat "%{User-Agent}i" agent
    LogFormat "%v %h %l %u %t \"%r\" %>s %b %T" script
    LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" VLOG=%{VLOG}e" vhost

    <IfModule logio_module>
        # You need to enable mod_logio.c to use %I and %O
        LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
        LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" vhostio
    </IfModule>

    # The location and format of the access logfile (Common Logfile Format).
    # If you do not define any access logfiles within a <VirtualHost>
    # container, they will be logged here.  Contrariwise, if you *do*
    # define per-<VirtualHost> access logfiles, transactions will be
    # logged therein and *not* in this file.
    CustomLog /var/log/apache2/access_log common

    # If you would like to have agent and referer logfiles,
    # uncomment the following directives.
    #CustomLog /var/log/apache2/referer_log referer
    #CustomLog /var/log/apache2/agent_logs agent

    # If you prefer a logfile with access, agent, and referer information
    # (Combined Logfile Format) you can use the following directive.
    #CustomLog /var/log/apache2/access_log combined
</IfModule>

And Lastly, you need to add a cron entry to update the statistics on a regular basis: # AWStats */15 * * * * perl /usr/share/webapps/awstats/6.9-r1/hostroot/cgi-bin/awstats.pl -config=www.alunduil.com -update > /dev/null

Everything should be running smoothly but give your installation some time to begin collecting statistics.

26Apr/09

Create a Symfony Development Environment

What are We Talking About?

Symfony, the hot new framework for PHP web application development, can drastically reduce development times on intricate applications. By utilizing a framework and the Rapid Application Development, Agile Development, XP, or whatever development cycle you might like best, elegant code is easier to produce and maintain. With proper design patterns already in use, one simply needs to fill in the appropriate logic at each level, and let the application grow into being. For more information on Symfony the following resources are available:

This is all great, but not nearly as useful if we can't develop and test locally. To get a nice development area installed what do we need to do? The following steps outline how to setup a machine so that you can have a projects directory that will automatically map to a nice set of URLs with minimal configuration.

What Do We Need?

We need the following installed (Gentoo use flags are in parentheses):

  • apache
  • mysql
  • php (cli ctype reflection spl simplexml xml pcre session apache2 mysql pdo xsl)
  • symfony

What's the Setup?

So how do we turn a directory full of projects into something we can get at by browsing to http://localhost/project? Well, we start by symlinking (or just changing) the docroot to the directory we want to use.

# rm -rf /var/www/localhost/htdocs
# ln -snf <path to projects> /var/www/localhost/htdocs

What we want to do now is change the vhost declaration for the default virtual host in apache. It's only an addition of a few simple lines (placed after the docroot declaration):

AliasMatch ^/((?!cgi-bin|icons).+)/sf/(.*) /usr/share/php5/data/symfony/web/sf/$2
AliasMatch ^/((?!sf|cgi-bin|icons).+?)/(.*) /var/www/localhost/htdocs/$1/web/$2

<Directory "/usr/share/php5/data/symfony/web/sf">
  Options Indexes FollowSymLinks               
  Order allow,deny                             
  Allow from all                           
</Directory>

The last thing that needs to be done is make sure the default redirect in your symfony project's .htaccess file redirects to //index.php.

Conclusions

That should be all there is to it, but as always your mileage may vary. If you notice significant problems or shortcomings with this how to, please, leave a comment denoting that. I will update this guide appropriately as quickly as possible.

Tagged as: , , No Comments