I’ve just upgraded my Piwik web analytics system this afternoon. It was not a long and complex process however it still have some things you should take note whenever you want to upgrade to a new version.
Piwik is an open source web analytics and it’s the biggest competitor with Google Analytics. And you’re be noticed a new version of Piwik frequently. Therefore, getting familiar with upgrading process is good for all of us.
This tutorial assumes you’re on a Windows Server with an Administrator account. Below are steps I did this afternoon.
1. Stop the Piwik analytics site or Temporary disable Piwik User Interface and Visitor Tracking
To make sure the upgrade process is finished without any concurrent read/write error, it’s recommended to stop the Piwik site and it’s Application Pool if you’re running the analytics service on a separate instance. Or if it’s just a sub directory on your production website, simply temporary disable Piwik User Interface and Visitor Tracking by adding the following in the /config/config.ini.php file:
- 1. Disable Piwik Tracking:
[text] [Tracker] record_statistics = 0
- 2. Disable the Piwik User Interface:
[text] [General] maintenance_mode = 1
2. Backup all your current files and the database
As new version of files should overwrite all your current files so please backup all current files especially your configuration file (/config/config.ini.php) and the Piwik archive script (/misc/cron/archive.windows.ps1 or /misc/cron/archive.sh) as you may made some changes on those files.
And the most important thing is the database. The upgrade process can damage/destroy your database in some how/some way so make sure you make a backup of your Piwik MySQL database. If your websites has more than few thousands visits per day, your database is surely very big so PHPMyAdmin is not a good choice in this case because of execution time and number of rows limitation.
Running the mysqldump command is a better way, for example:[text] C:\xampp\mysql\bin\mysqldump -u your-mysql-user -p your-piwik-database-name > D:\backup-piwik.sql
Don’t forget to replace the mysqldump location and your database detail. BTW, you should create a Schedule to backup your MySQL Database to protect your works.
3. Download the latest version of the Piwik
4. Start upgrading the Piwik
Firstly, restore the configuration file and the Piwik archive script from your backup in step 2. After that, let’s start updating the database with the latest code. I assume that your Piwik database is very big therefore it’s highly recommended to run the database update process in the command line.
Start the Command Prompt in your server and run command below:[text] php D:/path/to/piwik/index.php — "module=CoreUpdater"
This process may take a few minutes depend on how big your Piwik database is so please be patent.
5. Start the Piwik again
Congratulation, you get “The update completed successfully” message, it means all steps have been done. Hands on, we did stop the Piwik in step 1, remember? This final step is just need to start the Piwik website or remove/comment out these lines “record_statistics = 0” and “maintenance_mode = 1” in the /config/config.ini.php file.
If you have any idea/feedback, please leave it in the comments.
Bonus: here is my Piwik database for your reference why I have to run the database upgrade in the command line