Install Matomo Self-Hosted Analytics on cPanel

By on December 26th, 2019

Matomo, formerly known as Piwik, is a free and open-source web analytics application. It runs on a PHP/MySQL webserver. Matomo helps to track online visits on one or more websites and displays reports on these visits for analysis.

Steps to Install Matomo using cPanel

1) Login to cPanel and navigate to the “Files” category and select the “File Manager” to access it.

Install Matamo

2) Download Matomo (PIWIK) from the official site to your local system.

Install Matamo

3) Create a folder named “Analytics” by clicking the “Folder” tab from the cPanel’s “File Manager” menu to store all the Matomo files.

4) Then upload the downloaded Matomo zip file to the created folder.

5) Extract the Matomo zip file by right-clicking the file and selecting the “Extract” option.

6) After extraction, move all the files under the folder “matomo” from /public_html/analytics/matomo to  /public_html/analytics folder.

7) For security reasons, you can now delete these below two files from the /public_html/analytics folder.

How to install Matomo.html

matomo-latest.zip

8) Navigate to the “Databases” category in the cPanel portal and click on “MySQL Databases” to create database and user for the Matomo self-hosted analytics.

Install Matamo

9) Open the browser and point your domain or IP linked to your hosting service along with the folder name (analytics) created in cPanel to install Matomo.

<domain name>/analytics

or

IP-address/analytics

10)  After opening the folder in the browser, you need to set-up the “Wizard of self-hosted Google Analytics PIWIK”. 

Setup Wizard of self-hosted Google Analytics PIWIK

1) Click on the button “Next”.

Install Matamo2) The Wizard checks if the system requires any dependencies to run and install Matomo on your hosting server automatically.

3) Then we need to set up the database details by updating username and password in the respective field and then click “Next”.

Install Matamo

Now, It will create tables in the database and populate the tables if needed.

5) You can create a super or admin user for Matomo under the “SuperUser” tab.

Install Matamo

 

6) Under the “Set up a Website” tab, you can add the website details for which you need to get the tracking details.

7) Under the “JavaScript Tracking Code” tab, you can see a tracking code. In WordPress, you need to follow Appearance -> Theme option and select Header under which a box is available to add the tracking code.

8) Now you can log in to Matomo using the credentials of the super or admin user to open the Matomo dashboard.

 

How to Migrate a Particular Website in Matomo to a Different Matomo Installation

A Matomo plugin can be used to migrate a particular website from one instance to a different one.  After the migration, we need to update the tracking code on our website. Also, ensure that the Matomo URL and Website ID referred are correct.

When we need to migrate a particular website from one Matomo to a different one:

1) If you want to move a customer’s web analytics data to an independent Matomo instance. Then we can set up a new Matomo instance for their website and migrate all their website data to the new Matomo instance. After doing that, you can delete all their data from the old Matomo instance.

2) If you have multiple Matomo instances and need to consolidate all of them into a single Matomo instance for easier maintenance. Then you can migrate all your website data from the multiple instances to the chosen Matomo instance by running the Migration tool on each Matomo that needs to be migrated. After the completion of the migration, we need to update the tracking codes to refer to the new instance URL and Website ID. Then you can uninstall all the other Matomo instances.

How to Migrate Matomo from One Server to Another

If you need to move Matomo from one server to another, then you need to move the whole directory containing Matomo files and database to another MySQL Server. You can follow the following steps to migrate the complete Matomo files and database to another server:

1) First, you need to export your MySQL database in a file using some tools like phpMyAdmin or mysqldump. You can make a full copy of the MySQL database by running the mysqldump command.

$ time mysqldump --extended-insert --no-autocommit --quick --single-transaction MATOMO_DATABASE_NAME -uMATOMO_DATABASE_USERNAME -p > matomo_backup_database.sql

2) Compress this backup before sending it to the backup server.

$ tar zcf matomo-mysql-database-$(date +%Y-%m-%d-%H.%M.%S).sql.tar.gz matomo_backup_database.sql

3)  Import the backup to the new server by using phpMyAdmin or restore the DB backup by running the following command, and this creates Matomo tables in your database:

$ mysql MATOMO_DATABASE_NAME -uMATOMO_DATABASE_USERNAME -p < matomo_backup_database.sql

4) Download the same version of the Matomo on the new server. During installation, specify the MySQL server, login, password, and table prefix so that Matomo can detect the tables, existing websites, and reports automatically.

5) If there is any change in the Matomo domain name, then you need to change the Matomo javascript tags on all the tracked pages.

6) If you have set any auto-archiving crons in the old server, then you need to set up the same cron script on the new server.

Please note that while you are migrating Matomo from one server to another, the visits are not tracked.

 

If you need any further help, please do reach our support department. If you have any questions regarding this tutorial, please let us know in the comment section given below. We are happy to help!

Leave a Reply