Matomo on CentOS 7
Installing Matomo
Matomo, formerly known as Piwik, is an open source web analytics application. It rivals Google Analytics and includes even more features and allows you to brand your brand and send out custom daily, weekly, and monthly reports to your clients.
First let’s start by ensuring your system is up-to-date and has the needed repositories.
yum -y install epel-release
yum -y install https://centos7.iuscommunity.org/ius-release.rpm
yum clean all
yum -y update
reboot # if kernel updated
Install needed packages
yum -y install wget mariadb mariadb-server mysql httpd openssl mod_ssl php72u-json mod_php72u php72u-gd php72u-imap php72u-ldap php72u-odbc pear1u php72u-xml php72u-xmlrpc php72u-mbstring php72u-mysqlnd php72u-snmp php72u-soap php72u-tidy curl curl-devel mcrypt
Configure MySQL
systemctl restart mariadb.service # Start MySQL service
mysql_secure_installation # Set root password
mysql -u root -p # Enter root password
Add the database and user.
CREATE DATABASE IF NOT EXISTS matomodb DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
GRANT ALL PRIVILEGES ON matomodb.* TO 'matomouser'@'localhost' IDENTIFIED BY 'YourAwesomePassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;
quit
Installing Matomo on CentOS 7.
cd /var/www
wget https://builds.matomo.org/piwik.zip
Unpack the Matomo archive to the document root directory on your server.
unzip piwik.zip -d /var/www/html/
mv /var/www/html/piwik/ /var/www/html/matomo/
Update owner on Matomo files and folders
chown -R apache:apache /var/www/html/matomo
Configure Apache
Create Apache virtual host for Matomo . First create ‘/etc/httpd/conf.d/vhosts.conf’ file
vim /etc/httpd/conf.d/vhosts.conf
IncludeOptional vhosts.d/*.conf
Create the virtual host.
mkdir /etc/httpd/vhosts.d/
vim /etc/httpd/vhosts.d/yourdomain.com.conf
Add the following to the new vhost config.
<VirtualHost YOUR_SERVER_IP:80>
ServerAdmin webmaster@yourdomain.com
DocumentRoot /var/www/html/matomo
ServerName yourdomain.com
ServerAlias www.yourdomain.com
ErrorLog "/var/log/httpd/yourdomain.com-error_log"
CustomLog "/var/log/httpd/yourdomain.com-access_log" combined
<Directory "/var/www/html/matomo/">
DirectoryIndex index.html index.php
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Start Apache
systemctl start httpd
Verify that Apache is running by checking the status of the service:
systemctl status httpd
Install certbot to handle SSL
yum install -y mod_ssl python-certbot-apache
Run Certbot to secure the Apache site
certbot --apache -d site.example.com
Enable services and reboot the server and make sure it works.
systemctl enable httpd mariadb
reboot
Browse to https://your.sitename.com and follow the Matomo setup steps.
For details see https://matomo.org/docs/installation/
Installing libmaxminddb
Install git and PHP development libraries.
yum -y install php72u-devel git automake autoconf libtool
To install the library you need to download it’s latest tar ball and extract it, or clone their git repository
git clone --recursive https://github.com/maxmind/libmaxminddb
When cloning from git, run ./bootstrap
from the libmaxminddb directory and then run the commands.
./configure
make
sudo make install
sudo ldconfig
You can find more details about installing the library in their README
Installing Extension
After successfully installing libmaxmindb, you need to download or checkout MaxMind-DB-Reader-php.
Then run the following commands from the top-level directory of this distribution:
cd ext
phpize
./configure
make
sudo make install
You then must load your extension. The recommend method is to add the following to your php.ini file:
extension=maxminddb.so
Now restart the webserver and the GeoIP 2 PHP provider should mention if the extension is loaded in Matomo (Piwik) > Settings > Geolocation.
Note: You may need to install the PHP development package on your OS such as php5-dev for Debian-based systems or php-devel for RedHat/Fedora-based ones.
If after installing, you receive an error that libmaxminddb.so.0
is missing you may need to add the lib
directory in your prefix
to your library path. On most Linux distributions when using the default prefix (/usr/local
), you can do this by running the following commands:
echo /usr/local/lib >> /etc/ld.so.conf.d/local.conf
ldconfig
Download the GeoIP database and copy it to Matomo’s path/to/matomo/misc/ subdirectory.
wget https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz
cp GeoLite2-City_20190312/GeoLite2-City.mmdb /path/to/matomo/misc/
No Comments