Install AWStats with GeoIP Plugin

Hits: 6886  

AWStats is a free analytic tool that generates web, streaming, ftp or mail server statistics, graphically. There are many log analyzer but AWStats is open source Web analytics reporting tool, It can analyze log files from Apache, WebStar, IIS.

Installing AWStats on ubuntu 12.04

# apt-get install awstats

Configuring for replace with your real domain

# cp /etc/awstats/awstats.conf /etc/awstats/
# vi /etc/awstats/

Check you have below settings in /etc/awstats/


Generate stats for AWStats for /var/log/apache2/access.log file (Make sure you have fresh log file)

# /usr/lib/cgi-bin/ -update

configuration Apache2 with password

# htpasswd -c /etc/awstats/awstats.pwd admin
# chmod 755 /etc/awstats/awstats.pwd

# vi /etc/apache2/sites-available/awstats

<VirtualHost *:80>
DocumentRoot /var/www
ErrorLog ${APACHE_LOG_DIR}/error_awstats.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access_awstats.log combined
<Directory “/usr/lib/cgi-bin/”>
<Files “”>
Options +ExecCGI
Alias /awstats-icon/ “/usr/share/awstats/icon/”
<Directory /usr/share/awstats/icon>
Options None
AllowOverride All
Order allow,deny
Allow from all
RewriteEngine on
RewriteRule /awstats-icon – [L]
RewriteCond %{QUERY_STRING} !^(.*&)?framename=index(&.*)?$
RewriteCond %{QUERY_STRING} ^(.*&)?framename=.*(&.*)?$
RewriteRule /(.*) /usr/lib/cgi-bin/ [L]
RewriteCond %{QUERY_STRING} ^(.*&)?config=([^&]*)(&(.*))?$
RewriteRule /.* /%2?%1%4 [R,L]
RewriteRule /$ / [R,L]
RewriteRule /([^/]*)(/.*)? /usr/lib/cgi-bin/$1 [QSA,L]
<Location />
SetHandler cgi-script
Satisfy any
Order deny,allow
Deny from all
AuthType Basic
AuthName “AWStats Access”
AuthUserFile /etc/awstats/awstats.pwd
require valid-user
<LocationMatch /(?!|robots.txt)$>
Require user admin
<Location /awstats-icon>
SetHandler None
Allow from all

Enable Virtual Host

# a2ensite awstats
# apache2ctl configtest
# /etc/init.d/apache2 reload

Auto update stats

# crontab -e

*/10 * * * * /usr/share/awstats/tools/
10 03 * * * /usr/share/awstats/tools/
*/10 * * * * /usr/lib/cgi-bin/ -update > /dev/null

Set proper permission on logs

# sudo chmod 644 -R /var/log/apache2/*
# chmod 644 /var/log/apache2

# vi /etc/logrotate.d/apache2   (Replace create 640 root adm with create 644 root adm)

Install GeoIP for AWStats

# apt-get install build-essential zlib1g-dev apg libgeo-ipfree-perl libnet-ip-perl libnet-dns-perl liburi-perl apache2-utils

# cd /usr/src/
# wget
# tar xvzf zlib-1.2.8.tar.gz
# cd zlib-1.2.8
# ./configure –prefix=/usr/local/zlib && make && make install

# wget
# tar xzvf GeoIP-latest.tar.gz
# cd GeoIP-1.6.0
# ./configure && make && make install

# cpan
> install YAML
> install Geo::IP Geo::IPfree Geo::IP::PurePerl URI::Escape Net::IP Net::DNS Net::XWhois Time::HiRes Time::Local
> quit

# cd /usr/src/
# wget
# gzip -d GeoLiteCity.dat.gz
# cp GeoLiteCity.dat /usr/share/GeoIP/GeoLiteCity.dat

Enable AWSTAT configuation for LoadPlugin

# vi /etc/awstats/

Remove comment from /etc/awstats/

LoadPlugin=”geoip GEOIP_STANDARD /usr/share/GeoIP/GeoIP.dat”
LoadPlugin=”geoip_city_maxmind GEOIP_STANDARD /usr/share/GeoIP/GeoLiteCity.dat”

# /etc/init.d/apache2 reload

AWStats will run here




Error opening /usr/share/GeoIP/GeoIPCity.dat at /usr/local/share/perl/5.14.2/Geo/IP/ line [file name in /usr/share/GeoIP]

Make sure you have all files in folder /usr/share/GeoIP/GeoLiteCity.dat else copy

# cp /usr/share/GeoIP/GeoLiteCity.dat /usr/share/GeoIP/GeoIPCity.dat


Other log file analysis and reporting tools

Create Website Thumbnails using PhantomJS

Hits: 8899  

Hope you read my old article “Create WebThumb using LAMP”, it used for creating web thumbnails from Xvfb virtual framebuffer that is more time and resource consuming.

Shell Script with Xvfb try to open web browsers in real remote server to capture web-thumbs…

That whole setup might take a full day and image quality is very bad….

Thanks to PhantomJS

PhantomJS is a headless WebKit with JavaScript API. It has fast and native support for various web standards: DOM handling, CSS selector, JSON, Canvas, and SVG.

Simple Javascript example

console.log(‘Loading a web page’);
var page = require(‘webpage’).create();
var url = ‘’;, function (status) {
//Page is loaded!


– Headless Website Testing
– Screen Capture
– Page Automation
– Network Monitoring

Fork on Github

PhantomJS is using WebKit for a real layout and rendering engine, it can be used to capture web page as screenshot or PDF files. PhantomJS can render anything on the web page, it can be used to convert contents in HTML/CSS, SVG and Canvas.

// Thumbnail of Webpage using webthumb.js

var page = require('webpage').create(),
    system = require('system'),

if (system.args.length !== 3) {
    console.log('Usage: webthumb.js webURL filename');
    console.log('Usage: webthumb.js svnlabs.png');
} else {
    weblink = system.args[1];
    fname = system.args[2];    
    page.viewportSize = { width: 320, height: 480 };, function (status) {
    if (status !== 'success') {
        console.log('Unable to open webpage!');
    } else {
    window.setTimeout(function () {
    }, 3000);

Download webthumb.js

# phantomjs webthumb.js svnlabs.png
# phantomjs webthumb.js svnlabs.pdf

You can even capture webpage as good quality PDF file 😉



You can also use examples/rasterize.js for same sort of functions 😉

# phantomjs examples/rasterize.js svnlabs.png
# phantomjs examples/rasterize.js ‘’ svnlabs.pdf

rasterize.js – rasterizes a web page to image or PDF
render_multi_url.js – renders multiple web pages to images
technews.js – captures Google News as a PNG image

Upload Large Files from Amazon S3 Bucket to Dropbox Folder

Hits: 6602  

Dropbox Uploader is a BASH script (only needs cURL) which can be used to upload, download, list or delete files from Dropbox, an online file sharing, synchronization and backup service.


Amazon S3 to Dropbox
Amazon S3 to Dropbox

Secure:It’s not required to provide your username/password to this script, because it uses the official Dropbox API for authentication process.


# chmod +x
# ./

It will ask “App key”, “App secret” and “Access level (App folder or Full Dropbox)”

As shell script authorize token…

Please visit this URL from your Browser, and allow Dropbox Uploader
to access your DropBox account:


Dropbox token for Command Line
Dropbox token for Command Line

If everything go well …

> Access Token request… OK

Setup completed!

Now you can download Amazon S3 Bucket files on server using “wget” then you can run command like…

# ./ upload /var/www/aws/s3/svnlabs.mp4 /DROPBOX-FOLDER/svnlabs.mp4

I have uploaded media file upto 500MB on dropbox successfully using this shell script 😉

Alternate Options:

You can try Node.js for reading files from Amazon S3 and then upload to Dropbox

Useful JavaScript Tools—Amazon-S3

Amazon S3 Cloud HTML5 MP3 Player

Hits: 4515  

Amazon S3 Cloud HTML5 Player plugin that allows you to link to your amazon S3 bucket and sets up a HTML5 Player playlist (horizontal or vertical). This plugin will support MP3 files only.

Amazon S3 Cloud HTML5 MP3 Player is not associated in any way to

Get Self Hosted Amazon S3 Cloud HTML5 MP3 Player for WordPress just in $24

You will need an amazon account to use this.

AWS access info

Add your amazon information amazon key and amazon secret key. Then just add the bucket to your account add folders.

Amazon S3 Cloud HTML5 MP3 Player Options
Amazon S3 Cloud HTML5 MP3 Player Options

Make sure you have public permission for all your music in your S3 buckets and folders.

S3 Management Console
S3 Management Console

Shortcode for Page or Post

[html5aws3mp3 player=”horizontal” bucket=”BUCKET” endpoint=”BUCKET-ENDPINT” folder=”FOLDER/”]

Plugin Page

Amazon S3 Error Handling

AWS CloudFront with PHP

Create sub buckets on amazon s3

Amazon S3 Cloud HTML5 MP3 Player is not associated in any way to

Amazon S3 Error Handling

Hits: 5869  

Amazon S3 PHP Class A standalone Amazon S3 (REST) client for PHP 5.2.x using CURL that does not require PEAR.

AWS Management Console Home
AWS Management Console Home

AMAZON S3 (Scalable Storage in the Cloud) PHP CLASS

AWS access info
AWS access info

// AWS access info
if (!defined(‘awsAccessKey’)) define(‘awsAccessKey’, ‘CHANGE-KEY’);
if (!defined(‘awsSecretKey’)) define(‘awsSecretKey’, ‘CHANGE-KEY’);

OO method (e,g; $s3->getObject(…)):
$s3 = new S3(awsAccessKey, awsSecretKey);

Statically (e,g; S3::getObject(…)):
S3::setAuth(awsAccessKey, awsSecretKey);

Warning: S3::getBucket(): [PermanentRedirect] The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.

We need to End Point for our S3 Buckets by default it’s

$s3 = new S3(awsAccessKey, awsSecretKey);

S3 Management Console
S3 Management Console

Else we need to specify here…

S3 Management Console
S3 Management Console

$s3 = new S3(awsAccessKey, awsSecretKey, true, ‘‘);

Warning: S3::getBucket(): [60] SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

We need SSL enabled with CURL 😉

OpenSSL phpinfo()
OpenSSL phpinfo()
CURL With OpenSSL phpinfo()
CURL With OpenSSL phpinfo()

For class documentation see:

Recover MySQL root Password

Hits: 2994  

1. Stop the MySQL server.

# /etc/init.d/mysql stop

2. Start the MySQL server process with the –skip-grant-tables option so that it will not prompt for password.

# mysqld_safe –skip-grant-tables &

3. Connect to mysql server as the root.

# mysql -u root

mysql password
mysql password

Welcome to the MySQL monitor….
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

4. Setup new mysql root account password i.e. reset mysql password.

mysql> use mysql;
mysql> update user set password=PASSWORD(“NEW-PASSWORD”) where User=’root’;
mysql> flush privileges;
mysql> quit

5. Exit and restart the MySQL server.

# /etc/init.d/mysql stop

6. Start MySQL server.

# /etc/init.d/mysql start
# mysql -u root -p




Hits: 3741  

If you are searching for SQL or noSQL solutions, it is very difficult to decide among top SQL / noSQL Databases.

MySQL is the best for multi-document transactions, complex security, complex join, extreme compression.

NoSQL is good for linear scalability, high performance, schema flexibility.

But both depend on data need to manage 😉


MySQL support master and slave approach for scaling (vertical scalability).
NoSQL supports horizontal scalability.

Vertical scalability is the ability to increase the capacity of existing hardware or software by adding resources – for example, adding processing power to a server to make it faster. On the other hand, horizontal scalability is the ability to connect multiple entities so that they work as a single logical unit.


SQL is the best for query flexibility, SQL supports both simple and complex queries.
MongoDB supports SQL query and indexes.

Down Time

NoSQL perform well for database size and server performance.


SQL is king of transactions.
MongoDB and Redis support limited transactions.


Every database solution need deployment, backups, monitoring, and performance tuning.

NoSQL are modern web-scale databases having qualities of non-relational, distributed, open-source and horizontally scalable database.

How to play wowza live video on ipad

Hits: 15302  

Install Wowza Examples

Take care for common problems:

Do you have the Application.xml in the right place?

Server URL: rtmp://[wowza-address]/live
Stream Name: livestream

Which format need to broadcast from FMLE?
For iOS streaming, you’ll need h.264 baseline profile 3.0 on the video side and AAC on the audio side.

what is playlist.m3u8?
With Wowza cupertinostreaming…

Sample Code with HTML5 JWPlayer Support

<script type="text/javascript" src="jwplayer.js"></script> 

<div id='mediaplayer'></div>

<script type="text/javascript">  

    'id': 'playerID',    'width': '623',    'height': '365',
    'provider': 'rtmp',  
    'streamer': 'rtmp://[wowza-address]/live',
    'autostart': 'true',
    'stretching': 'exactfit',  

    levels: [{
              bitrate: "500",
              file: "livestream",
              width: "800"
              }, {
              bitrate: "800",
              file: "livestream",
              width: "1280"
    'modes': [
         {type: 'flash', src: 'player.swf'},
          type: 'html5',
          config: {
           levels: [ {'file': 'http://[wowza-address]:1935/live/livestream/playlist.m3u8'} ],
           'provider': 'video'

To play using Adobe Flash player (RTMP)

Server: rtmp://[wowza-address]/vod
Stream: mp4:sample.mp4

To play using RTSP/RTP player or device

To play using an Apple iDevice (Cupertino/Apple HTTP Live Streaming)


How to set up live streaming using an RTMP based encoder

Amazon SES integration with Joomla

Hits: 4143  

Amazon Simple Email Service (Amazon SES) is a highly scalable and cost-effective bulk and transactional email-sending service for businesses and developers. Amazon SES eliminates the complexity and expense of building an in-house email solution or licensing, installing, and operating a third-party email service. The service integrates with other AWS services, making it easy to send emails from applications being hosted on services such as Amazon EC2. With Amazon SES there is no long-term commitment, minimum spend or negotiation required – businesses can utilize a free usage tier and after that enjoy low fees for the number of emails sent plus data transfer fees.

Read this article for general Idea about “Amazon SES”

Amazon SES integration with Joomla

Get Remote Host Client IP Behind Load Balancers (ELB)

Hits: 19888  

I was working on “Private AWS Cloudfront Distribution” for AWS Elastic Load Balancer (ELB), allowing our application servers private access to our AWS cloudfront.

But PHP Server Environment Variable $_SERVER[“REMOTE_ADDR”] is displaying suspicious results, it really tedious to get remote host client IP behind ELB 🙁

Now we have 2 options…

1. mod_rpaf and Amazon ELB

$realclientip = $_SERVER[“HTTP_X_FORWARDED_FOR”];
} else {
$realclientip = $_SERVER[“REMOTE_ADDR”];

2. %{X-Forwarded-For}i from Apache Log (Time Consuming)

You Apache log format would then look something like this:
LogFormat “\”%{X-Forwarded-For}i\” %l %u %t \”%r\” %>s %b \”%{Referer}i\” \”%{User-agent}i\”” combined-elb
CustomLog log/acces_log combined-elb

Apache Module mod_remoteip


$_SERVER[‘REMOTE_ADDR’]; Apache Enviromental Variable is not working on your server 🙂