웹사이트 검색

Debian 11에 Matomo Web Analytics를 설치하는 방법


이 튜토리얼은 다음 OS 버전에 대해 존재합니다.

  • 데비안 11(불스아이)
  • 데비안 9(스트레치)

이 페이지에서

  1. 전제 조건
  2. Apache, MariaDB 및 PHP 설치
  3. Matomo용 MariaDB 데이터베이스 생성
  4. 마토모 다운로드
  5. Matomo용 Apache 구성
  6. Matomo 웹 UI 액세스
  7. Lets Encrypt SSL로 Matomo 보호\n
  8. 결론

이전에 Piwik으로 알려진 Matomo는 개발자 커뮤니티에서 개발한 무료 오픈 소스 웹 분석 애플리케이션입니다. 이것은 귀하의 웹사이트를 추적하고 그들이 사용한 검색 엔진과 키워드, 그들이 사용하는 언어, 그들이 좋아하는 페이지, 그들이 다운로드한 파일 등을 포함하여 귀하의 웹사이트와 방문자에 대한 자세한 정보를 제공하는 데 사용됩니다. Google 애드워즈, Facebook 광고, Yahoo, 검색 마케팅, 추적 및 보고 API, 클릭당 비용(CPC) 등 많은 기능을 제공합니다.

이 튜토리얼에서는 Apache2 웹 서버와 무료 Lets Encrypt SSL 인증서를 사용하여 Debian 11에 Matomo를 설치하는 방법을 보여줍니다.

전제 조건

  • Debian 11을 실행하는 서버.\n
  • 서버 IP를 가리키는 유효한 도메인 이름입니다.\n
  • 루트 암호는 서버에서 구성됩니다.\n

Apache, MariaDB 및 PHP 설치

먼저 Apache 웹 서버, MariaDB 데이터베이스 서버, PHP 및 기타 PHP 확장을 서버에 설치해야 합니다. 다음 명령을 실행하여 모두 설치할 수 있습니다.

apt-get install apache2 mariadb-server php libapache2-mod-php php-cli php-fpm php-fpm php-json php-json php-common php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath curl unzip -y

모든 패키지를 설치한 후 다음 명령을 사용하여 Apache 및 MariaDB 서비스를 시작하고 활성화합니다.

systemctl start apache2 mariadb
systemctl enable apache2 mariadb

완료되면 다음 단계로 진행할 수 있습니다.

Matomo용 MariaDB 데이터베이스 생성

Matomo는 MariaDB를 데이터베이스 백엔드로 사용합니다. 따라서 Matomo에 대한 데이터베이스와 사용자를 생성해야 합니다.

먼저 다음 명령을 사용하여 MariaDB에 로그인합니다.

mysql

로그인한 후 다음 명령을 사용하여 데이터베이스와 사용자를 생성합니다.

MariaDB [(none)]> CREATE DATABASE matomodb;
MariaDB [(none)]> CREATE USER 'matomo'@'localhost' IDENTIFIED BY 'password';

다음으로 다음 명령을 사용하여 Matomo 데이터베이스에 모든 권한을 부여합니다.

MariaDB [(none)]> GRANT ALL ON matomodb.* TO 'matomo'@'localhost' WITH GRANT OPTION;

그런 다음 권한을 플러시하고 다음 명령을 사용하여 MariaDB 셸을 종료합니다.

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

MariaDB 데이터베이스를 구성한 후 다음 단계를 진행할 수 있습니다.

마토모 다운로드

그런 다음 Matomo 공식 웹 사이트를 방문하여 다음 명령을 사용하여 최신 버전의 Matomo를 다운로드하십시오.

wget http://builds.matomo.org/matomo-latest.zip

다운로드가 완료되면 다음 명령을 사용하여 다운로드한 파일의 압축을 풉니다.

unzip matomo-latest.zip

다음으로 추출된 디렉터리를 Apache 웹 루트 디렉터리로 이동합니다.

mv matomo /var/www/html/matomo

다음으로 Matomo 디렉토리의 소유권과 권한을 변경합니다.

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

완료되면 다음 단계로 진행할 수 있습니다.

Matomo용 Apache 구성

다음으로 인터넷에서 Matomo를 호스팅하기 위해 Apache 가상 호스트 구성 파일을 생성해야 합니다. 다음 명령으로 만들 수 있습니다.

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

다음 줄을 추가합니다.

<VirtualHost *:80>

ServerAdmin 
ServerName matomo.example.com
DocumentRoot /var/www/html/matomo/

<Directory /var/www/html/matomo>
DirectoryIndex index.php
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>

<Files "console">
Options None
Require all denied
</Files>

<Directory /var/www/html/matomo/misc/user>
Options None
Require all granted
</Directory>

<Directory /var/www/html/matomo/misc>
Options None
Require all denied
</Directory>

<Directory /var/www/html/matomo/vendor>
Options None
Require all denied
</Directory>

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


</VirtualHost>

완료되면 파일을 저장하고 닫은 후 다음 명령을 사용하여 Matomo 가상 호스트 및 Apache 재작성 모듈을 활성화합니다.

a2ensite matomo.conf
a2enmod rewrite

다음으로 Apache 서비스를 다시 시작하여 변경 사항을 적용합니다.

systemctl restart apache2

다음 명령을 사용하여 Apache 상태를 확인할 수도 있습니다.

systemctl status apache2

다음과 같은 결과가 표시됩니다.

? apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2022-03-06 06:33:24 UTC; 5s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 55482 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 55486 (apache2)
      Tasks: 6 (limit: 4679)
     Memory: 12.4M
        CPU: 108ms
     CGroup: /system.slice/apache2.service
             ??55486 /usr/sbin/apache2 -k start
             ??55487 /usr/sbin/apache2 -k start
             ??55488 /usr/sbin/apache2 -k start
             ??55489 /usr/sbin/apache2 -k start
             ??55490 /usr/sbin/apache2 -k start
             ??55491 /usr/sbin/apache2 -k start

Mar 06 06:33:24 debian11 systemd[1]: Starting The Apache HTTP Server...
Mar 06 06:33:24 debian11 apachectl[55485]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 209>
Mar 06 06:33:24 debian11 systemd[1]: Started The Apache HTTP Server.

Matomo 웹 UI에 액세스

이제 웹 브라우저를 열고 URL http://matomo.example.com을 사용하여 Matomo 웹 인터페이스에 액세스하십시오. 다음 페이지로 리디렉션됩니다.

다음 버튼을 클릭합니다. PHP 구성 확인 페이지가 표시되어야 합니다.

모든 구성이 올바른지 확인한 후 NEXT 버튼을 클릭합니다. MariaDB 데이터베이스 설정 페이지가 표시되어야 합니다.

데이터베이스 서버, 사용자 이름, 데이터베이스 이름, 암호를 제공하고 NEXT 버튼을 클릭합니다. 다음 페이지가 표시됩니다.

다음 버튼을 클릭합니다. 수퍼유저 생성 페이지가 표시되어야 합니다.

관리자 사용자 이름, 비밀번호, 이메일을 제공하고 다음 버튼을 클릭합니다. 웹사이트 설정 페이지가 표시됩니다.

웹사이트 이름, URL, 시간대를 제공하고 다음 버튼을 클릭합니다. 다음 페이지가 표시됩니다.

다음 버튼을 클릭합니다. 구성 확인 페이지가 표시됩니다.

CONTINUE TO MATOMO를 클릭합니다. Matomo 로그인 페이지가 표시됩니다.

관리자 사용자 이름, 비밀번호를 제공하고 로그인 버튼을 클릭합니다. 다음 페이지에 Matomo 대시보드가 표시됩니다. 이제 위 이미지에 표시된 추적 코드를 복사하여 웹사이트의 모든 페이지에 붙여넣을 수 있습니다.

Lets Encrypt SSL로 Matomo 보호

다음으로 웹사이트에 Lets Encrypt SSL을 설치하려면 Certbot 클라이언트를 설치해야 합니다. 다음 명령으로 설치할 수 있습니다.

dnf install epel-release -y dnf install certbot python3-certbot-apache

그런 다음 다음 명령을 사용하여 lets 도메인에 대한 SSL 인증서를 가져와 설치합니다.

certbot --apache -d matomo.example.com

이메일 주소를 제공하고 서비스 약관에 동의하라는 메시지가 표시됩니다.

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Enter email address (used for urgent renewal and security notices)
 (Enter 'c' to cancel): 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Account registered.
Requesting a certificate for matomo.example.com
Performing the following challenges:
http-01 challenge for matomo.example.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/httpd/conf.d/matomo.conf
Redirecting all traffic on port 80 to ssl in /etc/httpd/conf.d/matomo.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://matomo.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Subscribe to the EFF mailing list (email: ).


IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/matomo.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/matomo.example.com/privkey.pem
   Your certificate will expire on 2022-05-09. To obtain a new or
   tweaked version of this certificate in the future, simply run
   certbot again with the "certonly" option. To non-interactively
   renew *all* of your certificates, run "certbot renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

결론

축하합니다! Debian 11에 Matomo를 성공적으로 설치했습니다. 이제 웹사이트에 추적 코드를 추가하고 Matomo 대시보드에서 모니터링을 시작할 수 있습니다. 궁금한 점이 있으면 언제든지 문의해 주세요.