Are you looking for a powerful web analytics application to track and analyze online visits to your website? Look no further! In this tutorial, we will guide you step by step on how to install Matomo with LAMP Stack on Debian 12. Matomo, formerly known as Piwik, is a free and open-source tool developed by a team of international developers. With its user-friendly interface and robust features, Matomo is a popular choice for businesses of all sizes.

Prerequisites

Before we dive into the installation process, let’s ensure that you have all the necessary prerequisites in place:

  • A system running Debian 12 with root access.
  • LAMP Stack installed and running on your system. If you haven’t set up LAMP Stack yet, you can refer to our comprehensive guide on installing LAMP Stack on Debian.
  • Basic knowledge of working with the command line.

Now that you have everything ready, let’s proceed with the installation and configuration of Matomo.

Step 1: Create a Database

To begin, we need to create a database and a user for Matomo. Open your terminal and execute the following commands:

mysql -u root
CREATE DATABASE matomo_db;
CREATE USER 'matomo_user'@'localhost' IDENTIFIED BY 'YOUR-PASSWORD-HERE';
GRANT ALL PRIVILEGES ON matomo_db.* TO 'matomo_user'@'localhost';
FLUSH PRIVILEGES;
QUIT

Make sure to replace ‘YOUR-PASSWORD-HERE’ with a strong and secure password.

Step 2: Install Let’s Encrypt SSL Certificate

Securing your Matomo installation with an SSL certificate is crucial for protecting sensitive data. Let’s install a Let’s Encrypt SSL certificate using the following commands:

apt update
apt install -y snapd
snap install core && sudo snap refresh core
snap install --classic certbot
ln -s /snap/bin/certbot /usr/bin/certbot

Step 3: Download and Extract Matomo

Now, let’s download and extract the Matomo files onto your system. Execute the following commands:

apt install unzip
cd /var/www
wget https://builds.matomo.org/matomo.zip && unzip matomo.zip
rm matomo.zip
cd matomo
mkdir tmp

Step 4: Set File Permissions

To ensure proper functioning, we need to set the correct file permissions for Matomo. Execute the following commands:

chown -R www-data:www-data /var/www/matomo
chmod -R 755 /var/www/matomo

Step 5: Configure Apache Virtual Host

Next, we need to configure the Apache virtual host for your Matomo installation. Create a new Apache configuration file with the following command:

vi /etc/apache2/sites-available/matomo.conf

Add the following lines to the file:

<VirtualHost *:80>
ServerName your-domain.com
ServerAdmin admin@your-domain.com
DocumentRoot /var/www/matomo

ErrorLog ${APACHE_LOG_DIR}/matomo_error.log
CustomLog ${APACHE_LOG_DIR}/matomo_access.log combined

<Directory /var/www/matomo/>
Options FollowSymlinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

Replace ‘your-domain.com’ with your actual domain name. Save the file and exit the text editor.

Step 6: Enable PHP Extensions

To enable the necessary PHP extensions for Matomo, open the PHP configuration file with your preferred text editor:

nano /etc/php/8.1/apache2/php.ini

Add the following lines at the end of the file:

extension=mysqli.so
extension=pdo.so
extension=pdo_mysql.so

Save the file and exit the text editor.

Step 7: Enable the Virtual Host and Restart Apache

Disable the default Apache configuration and enable the Matomo virtual host with the following commands:

a2dissite 000-default.conf
a2ensite matomo.conf

Now, restart the Apache service to apply the changes:

systemctl restart apache2
systemctl status apache2

Step 8: Configure Matomo

Finally, it’s time to configure Matomo and complete the installation process. Open your browser and enter the following URL:

http://your-domain.com

Replace ‘your-domain.com’ with your actual domain name.

Follow the on-screen instructions to input the database details you created earlier. Once you have completed the configuration, you have successfully installed Matomo with LAMP Stack on Debian 12!

Conclusion

Congratulations on successfully installing Matomo with LAMP Stack on Debian 12! With Matomo’s powerful web analytics capabilities, you can now track and analyze your website’s performance effectively. Remember to regularly update and maintain your Matomo installation to ensure optimal security and performance.

To explore more advanced features and optimize your Matomo installation further, consider utilizing the services of Shape.host. Shape.host offers reliable and scalable Cloud VPS solutions, backed by 24/7 in-house customer support. With Shape.host, you can focus on your business while ensuring your Matomo installation is in safe hands.

So, what are you waiting for? Start analyzing your website’s data with Matomo today and make data-driven decisions to boost your online presence!