Content
- page: Overview of basic terms and preparation for Matomo hosting
- page: Download and install Matomo
- page: Placing tracking code on WordPress pages
- page: Placing tracking code on Drupal pages
- page: Placing and customizing tracking code on custom pages
- page: Make important settings after installation
- page: Installation of GeoIP 2 (PHP) based geolocation system
- page: Matomo migration of a complete system to PHP-FPM based server API operation
The 1. page content
Introductory
I finally had some time to write this longer description, where I can introduce the Matomo (formerly Piwik) is a web analytics software preparation, steps, and use for installation. I have been using this web statistics system for about a year and a half, it does a very good service. For me, for example, it has almost completely replaced Google Analytics. Here are some of the main reasons I recommend everyone to use it:
- Points
- overview
- It has a convenient interface
- It contains spectacular panels
- Highly skilled (includes a variety of queries, variable cross sections, etc.)
- The data I collect remains with me, not on other companies' servers
- You can track statistics for any web page
- Regular updates that can be installed by clicking 2.
- Integrates with a wide range of CMS systems and web shop engines
So if you run a website, whether you own it or your client, this is a must! Their official website: here.
Matomo's system can be used in two ways: they provide the background on a cloud basis - similar to Google Analytics and other services - or we install the free downloaded software package on our server and run it ourselves to measure our websites. In this description, we will use the latter way: we will install it on an existing server, which will then provide us with accurate statistics about the traffic of the websites running on the server. The software is installed in one Apache web server we need it.
This description is not only about installing the Matomo (Piwik) system, but also about its preparations and the precise execution of the necessary settings (eg cron, log file management, GeoIP configuration, building custom tracking codes, PHP-FPM configuration, etc.), therefore very long. I have tried to compile all my own experience and information in this multi-page post, which I also gathered during my nearly two years of using Matomo, so that I can provide more than just a simple installation guide, as you would normally find on the internet. This statistical system is constantly doing me an excellent service, so I want it to benefit others as well.
basic Conditions
- Debian 8 (Jessie) LAMP Server v1.0 ( Installation guide | ready server download )
- Debian 8 (Jessie) perfect server v1.0 ( Installation guide | ready server download )
- Debian 8 (Jessie) perfect server v1.1 ( ready server download )
- Debian 9 (Stretch) LAMP Server v1.0 ( Installation guide | ready server download )
- Debian 9 (Stretch) is the perfect server for v1.0 ( Installation guide | ready server download ) (offer)
- Debian 10 (Buster) perfect server v1.0 ( Installation guide | ready server download )
- Ubuntu 18.04 LTS (Bionic Beaver) LAMP Server v1.0 ( Installation guide | ready server download )
So these servers are all installed with Apache web server and contain the components needed by Matomo, so any one of them is suitable for writing this description.
Matomo (Piwik) System Requirements
And the software to be installed is you need the following, if you do not choose the base machine from the above servers:
- Apache or Nginx Web Server (this is done with Apache, so you will only need it now).
- PHP 5.5.9 or later with the following extensions: pdo and pdo_mysql vagy mysqli, gd, xml, curl, and mbsting. PHP version 7.x is recommended.
- MySQL 5.5 or later or equivalent MariaDB. MySQL 5.7+ recommended.
- In addition, it is a good idea to have a web page (of any kind) where you can link your Matomo tracking code to test web stats.
So you need at least one Debian 8 LAMP server or a machine with a similar installation.
Preparations
Luggage database and package updates
We don't do such in-depth work on the server right now, but it's always a good idea to upgrade to our luggage and our packages so we can use the latest version of everything. To do this, run shellin the appropriate apt-get commands as root:
apt-get update
apt-get -y upgrade
Creating a database and user
There are still two ways to create a database: from the command line or if one exists phpMyAdmin on the server, then with that. Now we are doing the command line method, which is faster than phishing in phpMyAdmin. To do this, run the mysql command as root or sudo and also log in to mySQL as root:
sudo mysql -u root -p
You will be prompted to enter your MySQL root password and enter it.
After successful login, we find ourselves in the console of our database server. Here we do the following:
- Create a new database called "matomo"
- Assign all database privileges to the newly created user named "matomo" with the password "matomo_db"
- Clear authorization cache
- Exit
For these, execute the following four command lines one by one in the console, of course you can choose the database name, user and password as desired (but it is advisable to choose the appropriate names consistently):
create database matomo;
GRANT ALL ON matomo.* TO 'matomo' IDENTIFIED BY 'matomo_db';
FLUSH PRIVILEGES;
exit;
Don't forget the semicolons at the end of the lines!
Normally, it looks like this:
Alternatively, if you want to verify the success of this operation from phpMyAdmin, please log in with the user you just created:
And you can see that the user you created can log in and the associated database is displayed on the left.
Hosting
In this step, we create the physical storage for the Matomo (Piwik) system from which the system will run. This is created in a directory that is also available in any server configuration.
As root, create a subdirectory, say under / opt:
mkdir /opt/matomo
Create a php file in your directory to test PHP and the required PHP plugins and settings:
nano /opt/matomo/phpinfo.php
And add the following lines:
1 2 3 <?PHP phpinfo(); ?>
Save it, we'll have more work on that soon.
Configuring Apache Configuration
In this section, we set up a global Apache configuration that will allow the Matomo web analytics system to be accessed from under the web pages on the server. Thus, even customers can release their own domain their statistical accesses under their names.
Create a new Apache configuration file as root:
nano /etc/apache2/conf-available/matomo.conf
Then, include the following content:
Alias /matomo /opt/matomo <Directory /opt/matomo> Options +FollowSymLinks Options -Indexes AllowOverride All Require all granted DirectoryIndex index.php index.html # <IfModule mod_php5.c> <IfModule mod_php7.c> AddType application/x-httpd-php .php php_flag display_errors On php_value session.gc_maxlifetime 3600 # A következő beállítás a Matomo-nak kell: #php_value always_populate_raw_post_data -1 # Ha gondok vannak a működéssel (php hibák) javasolják az opcache kikapcsolását. #php_flag opcache.enable Off </IfModule> </Directory>
The configuration file - which is almost like one anyway Virtual hosting file - its lines mean the following:
- Alias: This directive allows content placed in a local file structure outside the root of the document to be accessed from the outside. In this case, it will serve the content in the / opt / matomo / directory from the / matomo (virtual) directories under the web pages.
- : Here we define a block in which the settings apply to the specified directory.
- Options + FollowSymLinks: Symbolic links tracking in web content.
- Options -Indexes: This disables the list of directories that do not contain index.php, index.html, etc. files. This increases safety.
- AllowOverride All: This allows the settings in the .htaccess files in the directories to override the global Apache configuration settings. Many systems use .htaccess files, so you should enable it.
- Require all granted: This allows anyone to access this web content from the outside (for example, we do not require HTTP authentication, etc.).
- DirectoryIndex index.php index.html: Load order of index file types. It looks for index.php first, then for html.
- # : Define another block in which the settings are evaluated when the mod_php5 module is loaded. On systems with PHP5 (eg Debian 8 based systems) we use this and comment on the following.
- : Same as the previous one, except this monitors the existence of the PHP7 Apache module. On newer systems (like Debian 9 or Ubuntu 18.04) we use this and comment on the previous one.
- AddType application / x-httpd-php .php: We assign the .php extension to the appropriate MIME type. Based on this, Apache will know what to do with the .php files.
- php_flag display_errors On: PHP Directive: Enable Error Display. We'll leave this at the beginning, and then once we've tested the Matomo and everything works properly, comment it out. While off, we can track PHP errors in the appropriate log files, but we can immediately notice errors in the browser.
- php_value session.gc_maxlifetime 3600: PHP Global Variable: This is what I use to get exactly 1 hours of sessions. I do not like the factory default 20 minute setting. Of course, everyone should set the right value for them, there is no requirement here.
- php_value always_populate_raw_post_data -1: PHP Global Variable: I found this in one of Matomo's descriptions that he needs this option. However, this global PHP variable has already been removed from PHP 7.0, so it only plays a role in PHP5.
- #php_flag opcache.enable Off: PHP directive: By default it is commented out here. Earlier versions of Matomo had problems with the PHP opcache. In this case, error messages appeared in the AJAX panels of the statistics, and only an Apache restart solved the problem. If this happened, this directive could be used to disable PHP opcache at Matomo (documentation about this). It's been a long time since then, I think they could fix it, and I went through the PHP-FPM based Matomo configuration, which works differently (about this at the end of this tutorial). So in a live environment, since then, I haven't been able to re-trigger or test the problem. If the error persists during operation, remove the comment from the directive.
So these would be the settings for this Apache configuration, I hope I could provide some useful info to help everyone fine-tune their own settings if needed.
In essence, this is a simple configuration that runs PHP as an Apache module, which is the default run mode for virtually any Apache + PHP installation. At the end of the description, we’ll review how we can port all of this to PHP-FPM for greater performance and efficiency.
Once you have finished configuring and saving the file, enable this configuration below a2andconf command:
a2enconf matomo
If no fatal error occurs, it returns the following output:
Enabling conf matomo. To activate the new configuration, you need to run: systemctl reload apache2
apachectl configtest
For me on this ISPConfig server, it will output:
AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/apache2/sites-enabled/000-ispconfig.conf:73 Syntax OK
Here at ISPConfig there is a warning that we are not dealing with (this does not appear on LAMP servers) and then write Syntax OK. So basically the enabled configurations are good, so now you can also restart Apache a systemctl command:
systemctl reload apache2
It does not output when successful.
Testing your hosting
Finally, let's test our newly designed hosting, which includes the functionality of the Apache configuration and the appropriate PHP settings. Open the previously created phpinfo.php file in your browser.
There are several ways to access this storage on your server:
- http://192.168.1.120/matomo/phpinfo.php
- http://www.weboldal1.tld/matomo/phpinfo.php
- http://www.weboldal2.tld/matomo/phpinfo.php
- etc. ...
So on the one hand the server is available IP addresses / matomo directory, and if there are web pages on the server, it can be accessed from any of the / matomo subdirectories. After loading our php file, the output of the phpinfo () PHP function normally accepts us:
On this server before a WordPress page has been installed, whose domain name I have set in my hosts file, so this page comes to me.
Here you will see the "Apache 2.0 Handler" at the beginning of the Server API section, which means that this php file runs as an Apache module, and scroll down to check other PHP settings.
A next page we continue with the installation of the Matomo (formerly known as Piwik) web analytics system.
- Encyclopedia - Matomo (Piwik) web analytics
- How to upgrade our Matomo (formerly Piwik) web analytics system to version 4.x.
- Encyclopedia - Apache HTTP Server
- Matomo.org
- Matomo.org - Installation
- Encyclopedia - Apache HTTP server
- What should we do if our Matomo web analytics system generates "AH01630: client denied by server configuration" type Apache errors that causes Fail2Ban to block our IP address?
- Server monitoring with Munin on Debian 9 (Stretch) and Debian 10 (Buster)
Navigation
- To post registration and login required
- 314 views