READ THE DOCS

HOW TO INSTALL PICOSTATS ON YOUR OWN SERVER

PicoStats Installation


Please notice that this tutorial is intended for advanced technical users who want to install Open Source version of PicoStats on their own server. Everybody else can use our free SaaS version, PicoStats Premium or contact us (in footer) for a managed solution.

There are two ways to install PicoStats on your own server: Docker and full manual installation. Of course, both of them have their pros and cons, but we're letting you decide about that. Both our tutorials are intended for Ubuntu Server.

Docker Installation

This one is simple. First you need to pull PicoStats Docker image:

docker pull picostats/picostats

And then you run it in background:

docker run -d picostats/picostats

After that, you can use this to get your container's IP address (replace YOUR_CONTAINER_ID with your actual container ID or first few letters of it):

docker inspect YOUR_CONTAINER_ID | grep IPAddress\"

And now you just open that IP address in your web browser and finish the simple installation process.

If you would like to expose that container to the outside network (Internet), which you probably do, then you should run it like this:

docker run -d --network=host picostats/picostats

Manual Installation

General

First we need to install all the packages that we need:

sudo apt install nginx postgresql redis-server supervisor

PostgreSQL

The we login to PostgreSQL server to add user and database and grant permissions:

sudo -u postgres psql

Create our user (replace MYPASSWORD with your actual password):

CREATE USER picostats WITH PASSWORD 'MYPASSWORD';

Create the database:

CREATE DATABASE picostats;

Grant the privileges:

GRANT ALL PRIVILEGES ON DATABASE picostats to picostats;

nginx

Now let's go with nginx. First we will backup the old default vhost:

sudo mv /etc/nginx/sites-available/default /etc/nginx/sites-available/default.bak

Create and edit new default vhost:

sudo vim /etc/nginx/sites-available/default

And this is what we'll add to it:

server {
    listen 80 default_server;

    server_name _;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header  X-Forwarded-Host $remote_addr;
        proxy_pass http://127.0.0.1:8080;
    }
}

Restart the service and we can move on to setting up PicoStats:

sudo service nginx restart

PicoStats

First we need to download latest release of PicoStats:

wget https://github.com/picostats/picostats/releases/download/v1.0.0beta/picostats-v1.0.0-beta.tar.gz

Extract it:

tar -xzf picostats-v1.0.0-beta.tar.gz

Copy dist config file to the actual one:

cp picostats/config.json.dist picostats/config.json

And edit it. Replace MYPASSWORD with PostgreSQL password you created and generate encryption key with something like pwgen (32 chars long) and put it under encryption_key in your json file.

vim picostats/config.json

We are ready to test it:

cd picostats && ./picostats

You should see something like this:

2017/03/20 21:34:54 [db.go] pg: user=picostats password=MYPASSWORD dbname=picostats sslmode=disable

And that's it regarding PicoStats.

Supervisor

Now we only need to configure Supervisor in order to keep PicoStats running.

Create and edit new Supervisor config file:

sudo vim /etc/supervisor/conf.d/picostats.conf

Add this to it:

[program:picostats]
command=/root/picostats/picostats
stderr_logfile=/root/picostats/picostats.err
stdout_logfile=/root/picostats/picostats.log
directory=/root/picostats
autostart=true
autorestart=true

Start Supervisor and make sure that it's running on boot:

sudo systemctl start supervisor && sudo systemctl enable supervisor

And that's it, we're done, now you can open your public IP address and finish the installation process using the interface. Plese notice that this type of installation is not exactly secure since we're installing PicoStats to be running as a root user, that should be changed and we will do our best to update this tutorial accordingly.

start tracking visits on your website right away

Sign Up Now