The Discussion Delegate

Answers to the Ultimate Questions about the Web, Mobile and Vercingetorix


How to install Count.ly on Ubuntu 10.04 LTS

This post was created on May 22nd, 2012 by Sudhanshu and has 0 comments. It has been filed under , , , , , ,

Count.ly is probably the best, open source, free and self hosted solution for analytics for mobile and web applications. The first version released on the 19th of May and we decided to go ahead and implement it for our own applications.

There were a few minor hiccups on the way so I thought it would be a good idea to document the process as well. I would like to point out that we’re no experts in Node.js or MongoDB and this is probably the first time that we tried setting up a server to host a node.js application. For the record, I use servers at prgmr.com (I just love them) and use the Ubuntu 10.04 LTS (Long Terms Support), so all instructions are with that in mind.

1. Download count.ly

You can do this from their website. I’ve been told that it should come up on Github sometime soon. You’re basically looking at the web installation. I found mine here – http://count.ly/downloads/release/bundle/countly-bundle-v12.05.zip, but it would be a better idea to get it from their website.

2. Decide where to install the code

I decided to setup nginx (which listens on port 80). It would inturn pass every request over to my node.js installation. Also, I decided to put all node.js projects at /nodes, so I moved the code for countly at /nodes/countly
$ mkdir /nodes
$ cd /nodes
$ sudo aptitude install unzip
$ unzip countly-bundle-v12.05.zip

3. Install Git and create an account at Github

You can install Git by typing
$ sudo aptitude install git-core
You would also need to do a few more operations like setup your SSH keys and add them to your Github account. The instructions for that are at help.github.com

4. Install Node.js

You need to download the latest source code from github, build and install it.
$ cd
$ git clone https://github.com/joyent/node.git
$ cd node

Now you need to find the latest stable version of node, branch out to that version and then build it. To find the latest stable version of node.js, go to https://github.com/joyent/node/tags and search for (stable) with the brackets. Currently, the latest stable version is 0.6.18 which is way down in the list, but that’s okay. We don’t want an unstable node.
$ git checkout -b v0.6.18 v0.6.18
$ git branch
  master
* v0.6.18
$ ./configure
$ make
$ sudo make install

Now you have the latest stable version of node running on your servers.

5. Install nginx

Installing nginx is quite straight forward
$ sudo aptitude install nginx
You also need to setup the configuration for nginx so that it was run multiple node.js installations.
$ cd /etc/nginx/sites-enabled
$ vi default

Here is what a simple nginx config file looks like
server {
  listen 80;
  server_name yourservername.com;
  access_log off;
  location = /i {
    proxy_pass http://127.0.0.1:3001;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Real-IP $remote_addr;
  }
  location = /o {
    proxy_pass http://127.0.0.1:3001;
  }
  location / {
    proxy_pass http://127.0.0.1:6001;
  }
}

Another thing I did was changed the name of the file from default to default_3001_6001 so that I know which port numbers are getting used in there. Now if you have a add a new node.js deployment on the server, you would do the following
$ cd /etc/nginx/sites-enabled/
$ vi test_3010

If your deployment is at /nodes/test and runs at port 3010, you need to add the following in your configuration
server {
  listen 80;
  server_name deploy.vxtindia.com;
  access_log off;
  location / {
    proxy_pass http://127.0.0.1:3010;
  }
}

6. Install mongodb

You need to add a repository to your aptitude’s sources.list and then install normally
$ sudo vi /etc/apt/sources.list
Add the following line at the end, if it isn’t already there
deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen
Now, you need to refresh the aptitude cache and just install
$ sudo aptitude adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
$ sudo aptitude update
$ sudo aptitude install mongodb-10gen

The documentation asks you to install mongodb-server as well, however I didn’t find it in 10.04 LTS.

7. Install npm

This is really simple, and this is something that you’ll instantly fall in love with. The setup is as simple as this
$ curl http://npmjs.org/install.sh | sh

If you haven’t used npm before, you need to understand that you can install everything locally or globally. You can install anything globally by typing “npm install -g packagename”. If you want to install it locally only “npm install packagename”. (If you want the complete list of package names, you can go here – http://search.npmjs.org). Usually if it looks like an important package which you might use across projects, you can install it globally. If you need a package only for one project, it’s better to include it locally. However, when you intall something globally and your script gives you an error when you run “node app.js”, go ahead and install it locally. That always works, and I can’t tell you how many times I have had to do it!

8. Install other required softwares

There are a few other things which are required by count.ly. We will go out and install them now
$ sudo aptitude install python-software-properties imagemagick build-essential

9. Install Supervisor

As you would expect, Supervisor makes sure that your script always keeps running. Here is how to install it
$ sudo aptitude install supervisor

10. Install geoip

Installing geoip should usually be this simple
$ sudo aptitude install libgeoip-dev
$ cd ../api
$ npm install geoip

But if you’re on Ubuntu 10.04, you would need to build geoip. The instructions for the same are (thanks to Onur from count.ly). You would only need to do this, if you get an error like this

$ cd
$ sudo aptitude install wget
$ wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP.tar.gz
$ tar xvf GeoIP.tar.gz
$ cd GeoIP.tar.gz
$ ./configure --prefix=/usr
$ make
$ sudo make install
$ cd ..
$ rm -rf GeoIP*
$ cd /nodes/countly/
$ npm install geoip

11. Install time

This one proved to be very tricky. I’m still not sure how the issue got resolved, but here’s a hint at what to do if you get stuck at the same issue
$ npm install time
I hope it works for you, because for me it ended up with a message like this:

I contacted the original developer for this project, who was very helpful, but I found the resolution in about 10 minutes after mucking around with node-gyp. Here are some of the things that I did
$ npm install node-gyp
$ cd
$ mkdir .node-gyp
$ chmod -R 777 .node-gyp
$ cd .node-gyp
$ mkdir 0.6.18
$ chmod -R 755 0.6.18
$ cd
$ npm install -g time
$ cd /nodes/countly
$ npm install time

This should hopefully fix your issue as well.

12. Setup URL in Javascript

Countly runs everything via Ajax, so it’s really important that you setup the callback path properly, otherwise, you app will end us looking like this –

Setting this up is simple, you need to take the base url that you had setup in nginx (after server_name) and do this
$ cd /nodes/countly/
$ vi frontend/express/public/javascripts/countly/countly.config.js

Replace the existing text with
countlyCommon.READ_API_URL = "http://yourbasepath.com/o"

13. Run Supervisor

Finally, to start the dashboard and the API, you need to do this
$ cd /nodes/countly/bin
$ supervisord -c ./config/supervisord.conf

The configuration file looks something like this (You don’t need to change this at all)
[unix_http_server]
file=/tmp/supervisor.sock
 
[supervisord]
logfile=/var/log/supervisord.log
logfile_maxbytes=50MB
logfile_backups=10
loglevel=warn
pidfile=/var/log/supervisord.pid
nodaemon=false
minfds=1024
minprocs=200
user=root
childlogdir=/var/log/
 
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
 
[group:countly]
programs=countly-dashboard-6001, countly-api-3001
 
[program:countly-dashboard-6001]
command=node ./../frontend/express/app.js
directory=.
autorestart=true
redirect_stderr=true
stdout_logfile=./../log/countly-dashboard.log
stdout_logfile_maxbytes=500MB
stdout_logfile_backups=50
stdout_capture_maxbytes=1MB
stdout_events_enabled=false
loglevel=warn
 
[program:countly-api-3001]
command=node ./../api/api.js 3001
directory=.
autorestart=true
redirect_stderr=true
stdout_logfile=./../log/countly-api.log
stdout_logfile_maxbytes=500MB
stdout_logfile_backups=50
stdout_capture_maxbytes=1MB
stdout_events_enabled=false
loglevel=warn

That is it! You can now go to the browser and start using Count.ly!

We are a Pune, India based firm specializing in building PHP, iPhone and Android applications. You can also catch our latest updates via RSS or follow us on Twitter. To invite us to work on a project, please get in touch via the Contact page and we'll get back to you at the earliest.

Leave a Reply





Social


Find us on Facebook
Follow us on Github
Track us on Basecamp