웹사이트 검색

Ubuntu 20.04에 Matomo 웹 분석을 설치하는 방법


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

  • 우분투 18.04(바이오닉 비버)

이 페이지에서

  1. 전제 조건
  2. 시작하기\n
  3. LEMP 서버 설치
  4. Matomo 데이터베이스 생성
  5. 마토모 다운로드
  6. Matomo용 Nginx 구성
  7. Lets Encrypt SSL로 Matomo 보호\n
  8. Matomo 분석에 액세스
  9. 결론

이전에 Piwik으로 알려진 Matomo는 웹사이트에서 온라인 방문자를 추적하는 데 도움이 되는 무료 오픈 소스 웹 분석 애플리케이션입니다. 타사 솔루션을 사용하지 않고도 자신의 웹사이트 분석 및 데이터를 완벽하게 제어할 수 있는 Google Analytics 소프트웨어의 대안입니다. 방문, 다운로드, 목표 전환율, 키워드 등과 같은 핵심 성과 지표를 추적하는 데 사용할 수 있는 중소기업용으로 설계되었습니다.

이 튜토리얼에서는 Nginx 및 Lets Encrypt SSL을 사용하여 Ubuntu 20.04에 Matomo 웹 분석 소프트웨어를 설치하는 방법을 보여줍니다.

전제 조건

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

시작하기

먼저 시스템 패키지를 최신 버전으로 업데이트하는 것이 좋습니다. 다음 명령을 실행하여 업데이트할 수 있습니다.

apt-get update -y

모든 패키지가 업데이트되면 다음 명령을 실행하여 다른 필수 종속성을 설치합니다.

apt-get install curl wget vim git unzip socat gnupg2 -y

필요한 패키지를 모두 설치한 후 다음 단계로 진행할 수 있습니다.

LEMP 서버 설치

Matomo는 PHP로 작성된 웹 서버에서 실행되며 데이터베이스에 MySQL을 사용합니다. 따라서 서버에 LEMP 스택을 설치해야 합니다. 다음 명령으로 설치할 수 있습니다.

apt-get install nginx mariadb-server php7.4 php7.4-cli php7.4-fpm php7.4-common php7.4-curl php7.4-gd php7.4-xml php7.4-mbstring php7.4-mysql -y

LEMP 스택이 설치되면 다음 단계를 진행할 수 있습니다.

Matomo 데이터베이스 생성

Matomo는 분석 데이터를 저장하기 위해 데이터베이스가 필요합니다. 따라서 Matomo에 대한 데이터베이스와 사용자를 생성해야 합니다.

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

mysql

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

MariaDB [(none)]> CREATE DATABASE matomodb;
MariaDB [(none)]> GRANT ALL ON matomodb.* TO 'matomo' IDENTIFIED BY 'password';

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

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

데이터베이스가 생성되면 다음 단계로 진행할 수 있습니다.

마토모 다운로드

먼저 다음 명령을 사용하여 최신 버전의 Matomo를 공식 웹 사이트에서 Nginx 웹 루트 디렉터리로 다운로드합니다.

cd /var/www/html/
wget https://builds.matomo.org/matomo.zip

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

unzip matomo.zip

다음으로 matomo의 소유권을 www-data로 변경합니다.

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

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

Matomo용 Nginx 구성

다음으로 Matomo를 제공할 새 Nginx 가상 호스트 구성 파일을 생성해야 합니다.

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

다음 줄을 추가합니다.

server {

  listen 80;
  server_name matomo.linuxbuz.com;
  root /var/www/html/matomo/;
  index index.php;

  location ~ ^/(index|matomo|piwik|js/index).php {
    include snippets/fastcgi-php.conf;
    fastcgi_param HTTP_PROXY ""; 
    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; 
  }
  
  location = /plugins/HeatmapSessionRecording/configs.php {
    include snippets/fastcgi-php.conf;
    fastcgi_param HTTP_PROXY "";
    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
  }

  location ~* ^.+\.php$ {
    deny all;
    return 403;
  }

  location / {
    try_files $uri $uri/ =404;
  }
  
  location ~ /(config|tmp|core|lang) {
    deny all;
    return 403;
  }

  location ~ \.(gif|ico|jpg|png|svg|js|css|htm|html|mp3|mp4|wav|ogg|avi|ttf|eot|woff|woff2|json)$ {
    allow all;
  }

  location ~ /(libs|vendor|plugins|misc/user) {
    deny all;
    return 403;
  }

}

파일을 저장하고 닫은 후 다음 명령을 사용하여 가상 호스트를 활성화합니다.

ln -s /etc/nginx/sites-available/matomo.conf /etc/nginx/sites-enabled/

다음으로 다음 명령을 사용하여 구성 오류가 있는지 Nginx를 확인합니다.

nginx -t

다음 출력이 표시되어야 합니다.

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

마지막으로 Nginx 서비스를 다시 시작하여 변경 사항을 적용합니다.

systemctl restart nginx

이 시점에서 Nginx는 Matomo를 지원하도록 구성됩니다. 이제 다음 단계를 진행할 수 있습니다.

Lets Encrypt SSL로 Matomo 보호

Lets Encrypt SSL로 웹 사이트를 보호하는 것은 항상 좋은 생각입니다. 먼저 다음 명령을 사용하여 서버에 Certbot Lets Encrypt 클라이언트를 설치합니다.

apt-get install python3-certbot-nginx -y

설치가 완료되면 다음 명령을 실행하여 Lets Encrypt SSL로 웹 사이트를 보호하십시오.

certbot --nginx -d matomo.linuxbuz.com

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

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
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 at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing 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
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for matomo.linuxbuz.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/matomo.conf

다음으로, 아래와 같이 HTTP 트래픽을 HTTPS로 리디렉션할지 여부를 선택합니다.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

2를 입력하고 Enter 키를 눌러 설치를 마칩니다. 다음 출력이 표시되어야 합니다.

Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/matomo.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://matomo.linuxbuz.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=matomo.linuxbuz.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/matomo.linuxbuz.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/matomo.linuxbuz.com/privkey.pem
   Your cert will expire on 2020-10-30. 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"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - 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

 - We were unable to subscribe you the EFF mailing list because your
   e-mail address appears to be invalid. You can try again later by
   visiting https://act.eff.org.

이제 귀하의 Matomo 웹사이트는 Lets Encrypt SSL로 보호됩니다.

Matomo 분석에 액세스

이제 웹 브라우저를 열고 URL https://matomo.linuxbuz.com을 입력하십시오. Matomo 시작 화면으로 리디렉션됩니다.

다음 버튼을 클릭합니다. Matomo 전제 조건 확인 화면이 표시되어야 합니다.

다음 버튼을 클릭합니다. matomo 데이터베이스 구성 화면이 표시되어야 합니다.

데이터베이스 세부 정보를 제공하고 다음 버튼을 클릭합니다. 다음 화면이 표시됩니다.

다음 버튼을 클릭합니다. 관리자 사용자 설정 화면이 표시되어야 합니다.

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

웹사이트 세부 정보를 제공하고 NEXT 버튼을 클릭합니다. 다음 화면이 표시됩니다.

다음 버튼을 클릭합니다. 설치가 완료되면 다음 화면이 표시됩니다.

CONTINUE TO MATOMO를 클릭합니다. Matomo 로그인 화면으로 리디렉션됩니다.

관리자 사용자 이름, 비밀번호를 제공하고 로그인 버튼을 클릭합니다. 다음 화면에 Matomo 대시보드가 표시되어야 합니다.

결론

축하합니다! Ubuntu 20.04에서 Nginx 및 Lets Encrypt를 사용하여 Matomo 분석을 성공적으로 설치 및 구성했습니다. 이제 웹사이트를 Matomo와 통합하고 웹사이트 추적을 시작할 수 있습니다. 궁금한 점이 있으면 언제든지 문의해 주세요.