Install and Update Open Web Analytics on Docker
Here’s the problem: I want to use Open Web Analytics (OWA), but I want to install it in a Docker container. With no official Docker image to draw from, I’m left with poorly maintained alternatives. In this article, I’ll take you through how you might use an older docker image, update it and get the newest version of Open Web Analytics working.
It’s important to note, there are few images available, and I chose to use vladk1m0/docker-owa. Your mileage may vary with others at docker hub. A warning, if you update or recreate your container after the work we do, the changes will be lost and your install reverted. Keep good notes.
So, to the preamble: Make sure you have a Linux machine with docker running. I’m going to use docker-compose, so make sure that’s installed. Create a public DNS hostname for yourself too: I’ll call it analytics.domain.tld for examples in this article. Password and usernames listed here are examples, aren’t real, and should be changed in a production environment.
Setup the OWA container
1. Start by grabbing the example docker-compose file from Github – place it in a working folder:
$ curl -fsSL -o docker-compose.yml https://raw.githubusercontent.com/vladk1m0/docker-owa/master/docker-compose.yml
2. Edit that file to suit your environment. If you change the absolute minimum, change the database values in the MySQL environment section to match the typical syntax (pay attention to the whitespace in your docker-compose.yml):
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: database
MYSQL_USER: user
MYSQL_PASSWORD: password
3. Run the command to create the containers and start them and view the logs:
$ docker-compose up -d && docker-compose logs -f
4. Finally, you should have a working installation of OWA on port 8080 of your Docker server. Take note that the version will be older, 1.62.:
You could just leave it at this and use an old version, but it’s better to have the newest, isn’t it?
Upgrade from inside the container.
1. Find the ID of your OWA container and connect to a shell for it:
$ docker exec -it -u root caa33581d06f /bin/sh
2. Upgrade OWA’s basic files and set permissions:
/var/www/html # cd /tmp
/tmp # OWA_VERSION=1.7.1
/tmp # curl -fsSL -o /tmp/owa.tar.gz "https://github.com/padams/Open-Web-Analytics/archive/$OWA_VERSION.tar.gz"
/tmp # tar -xzf /tmp/owa.tar.gz -C /tmp
/tmp # mv /var/www/html /var/www/html--
/tmp # mkdir /var/www/html
/tmp # mv /tmp/Open-Web-Analytics-$OWA_VERSION/* $WEBROOT_DIR
/tmp # chown -R $OWA_USER:$OWA_GROUP $WEBROOT_DIR/
/tmp # chmod -R 0775 $WEBROOT_DIR/
3. Now, open your site again on port 8080, and you should see the footer has changed from showing the version to nothing. The next screen also has more options.
4. An important requirement, Composer needs to be installed with further dependencies. Do this with these commands:
/tmp # apk --update add php5-cli
/tmp # cd /var/www/html
/var/www/html # php5 -v
/var/www/html # php5 -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
/var/www/html # php5 -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
/var/www/html # php5 -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
/var/www/html # php5 composer-setup.php
/var/www/html # php5 composer.phar install
You can now run through the installation wizard and connect OWA to your database. This could be in the above sample or an existing database on your internal Docker network.
Other things to note
The image uses php5 () and may well require an upgrade for later versions of OWA. For now, it works. Also, the Maxmind GeoIP module may not work without changes there, I haven’t tested that yet. You’ll find logs for OWA in the cd /var/www/html/owa-data/logs directory inside your container.
You might also want to place the /var/www/html and hosts file outside of the container using statements like the following in your docker-compose.yml:
volumes:
- /data/owa/hosts:/etc/hosts
- /data/owa/html:/var/www/html
And that’s it. All goes well, you’ll have the newest version of OWA and can start collecting stats. At the very least, you’ll see the pure potential of this great open-source tool and deploy it elsewhere as needed. Also, don’t forget that you can run through this on a temporary system at Play With Docker – give it a try.