Ubuntu 18.04 LTS에 Matomo 웹 분석을 설치하는 방법
이 튜토리얼은 다음 OS 버전에 대해 존재합니다.
- Ubuntu 20.04(Focal Fossa)
- Ubuntu 18.04(Bionic Beaver)
이 페이지에서
- 요구 사항\n
- 전제 조건
- 초기 단계
- 1단계 - MySQL 설치 및 Matomo용 데이터베이스 생성
- 2단계 - PHP 및 필요한 PHP 확장 설치\n
- 3단계 -
acme.sh
클라이언트를 설치하고 Let">을 얻습니다.\n - 3단계 - NGINX 설치 및 Matomo용 NGINX 구성
- 4단계 - Matomo Analytics 설치
- 5단계 - Matomo Analytics 설정 완료
- 링크
Matomo(이전 Piwik) 는 PHP/MySQL 웹서버에서 실행되는 국제 개발자 팀이 개발한 무료 오픈소스 웹 분석 애플리케이션입니다. 하나 이상의 웹사이트에 대한 온라인 방문을 추적하고 분석을 위해 이러한 방문에 대한 보고서를 표시합니다. Google 애널리틱스의 대안으로 생각할 수 있습니다. Matomo는 오픈소스이며 해당 코드는 Github에서 공개적으로 사용할 수 있습니다. A/B 테스트, 히트맵, 유입경로, 추적 및 보고 API, Google 애드워즈, Facebook 광고, Bing 광고, CPC(클릭당 비용) 등의 기능이 있습니다. 이 자습서에서는 Matomo를 설치하는 방법을 보여줍니다. Nginx를 웹 서버로 사용하는 Ubuntu 18.04 LTS 시스템이며 Lets Encrypt SSL 인증서로 웹사이트를 보호합니다.
요구 사항
Ubuntu 시스템에서 Matomo(Piwik)를 실행하려면 몇 가지가 필요합니다.
- Apache, Nginx, IIS와 같은 웹 서버.
- pdo 및 pdo_mysql 또는 mysqli, gd, xml, curl 및 mbsting 확장 프로그램이 있는 PHP 버전 5.5.9 이상. PHP 7+를 권장합니다.\n
- MySQL 버전 5.5 이상 또는 동등한 MariaDB 버전. MySQL 5.7+가 권장됩니다.
전제 조건
- Ubuntu 18.04를 실행하는 운영체제입니다.\n
- sudo 권한이 있는 루트가 아닌 사용자.\n
초기 단계
Ubuntu 버전 확인:
lsb_release -ds
# Ubuntu 18.04.1 LTS
시간대 설정:
sudo dpkg-reconfigure tzdata
운영 체제 패키지(소프트웨어)를 업데이트합니다. 이는 운영 체제 기본 소프트웨어 패키지에 대한 최신 업데이트 및 보안 수정 사항이 있는지 확인하기 때문에 중요한 첫 번째 단계입니다.
sudo apt update && sudo apt upgrade -y
Ubuntu 운영체제의 기본 관리에 필요한 몇 가지 필수 패키지를 설치합니다.
sudo apt install -y curl wget vim git unzip socat
1단계 - MySQL 설치 및 Matomo용 데이터베이스 생성
Matomo는 MySQL 및 MariaDB 데이터베이스를 지원합니다. 이 가이드에서는 MySQL을 데이터베이스 서버로 사용합니다.
MySQL 데이터베이스 서버 설치:
sudo apt install -y mysql-server
MySQL 버전 확인:
mysql --version
# mysql Ver 14.14 Distrib 5.7.24, for Linux (x86_64) using EditLine wrapper
mysql_secure 설치
스크립트를 실행하여 MySQL 보안을 개선하고 MySQL 루트
사용자의 비밀번호를 설정합니다.
sudo mysql_secure_installation
각 질문에 답하십시오.
Would you like to setup VALIDATE PASSWORD plugin? N
New password: your_secure_password
Re-enter new password: your_secure_password
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y
루트 사용자로 MySQL 셸에 연결합니다.
sudo mysql -u root -p
# Enter password
빈 MySQL 데이터베이스 및 Matomo 사용자를 만들고 자격 증명을 기억하세요.
mysql> CREATE DATABASE dbname;
mysql> GRANT ALL ON dbname.* TO 'username' IDENTIFIED BY 'password';
mysql> FLUSH PRIVILEGES;
MySQL에서 종료:
mysql> exit
dbname
, username
및 password
를 자신의 이름으로 바꾸세요.
2단계 - PHP 및 필요한 PHP 확장 설치
PHP와 필요한 PHP 확장을 설치합니다.
sudo apt install -y php7.2 php7.2-cli php7.2-fpm php7.2-common php7.2-curl php7.2-gd php7.2-xml php7.2-mbstring php7.2-mysql
PHP 버전 확인:
php --version
# PHP 7.2.10-0ubuntu0.18.04.1 (cli) (built: Sep 13 2018 13:45:02) ( NTS )
# Copyright (c) 1997-2018 The PHP Group
# Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
# with Zend OPcache v7.2.10-0ubuntu0.18.04.1, Copyright (c) 1999-2018, by Zend Technologies
PHP-FPM 서비스는 Ubuntu 18.04 시스템에서 재부팅 시 자동으로 시작되고 활성화되므로 수동으로 시작하고 활성화할 필요가 없습니다. Lets Encrypt CA에서 무료 SSL 인증서를 받는 다음 단계로 넘어갈 수 있습니다.
3단계 - acme.sh 클라이언트 설치 및 Lets Encrypt 인증서 받기(선택사항)
HTTPS로 웹 사이트를 보호할 필요는 없지만 사이트 트래픽을 보호하는 것이 좋습니다. Lets Encrypt에서 TLS 인증서를 얻기 위해 Acme.sh 클라이언트를 사용합니다. Acme.sh는 종속성이 없는 Lets Encrypt에서 TLS 인증서를 얻기 위한 순수 유닉스 셸 소프트웨어입니다.
Acme.sh 다운로드 및 설치:
sudo mkdir /etc/letsencrypt
git clone https://github.com/Neilpang/acme.sh.git
cd acme.sh
sudo ./acme.sh --install --home /etc/letsencrypt --accountemail
cd ~
Acme.sh 버전 확인:
/etc/letsencrypt/acme.sh --version
# v2.8.0
도메인/호스트 이름에 대한 RSA 및 ECC/ECDSA 인증서 받기:
# RSA 2048
sudo /etc/letsencrypt/acme.sh --issue --standalone --home /etc/letsencrypt -d example.com --keylength 2048
# ECDSA
sudo /etc/letsencrypt/acme.sh --issue --standalone --home /etc/letsencrypt -d example.com --keylength ec-256
위 명령어를 실행하면 인증서 및 키가 다음 위치에 있게 됩니다.
- RSA의 경우:
/etc/letsencrypt/example.com
디렉토리. - ECC/ECDSA의 경우:
/etc/letsencrypt/example.com_ecc
디렉토리.
3단계 - NGINX 설치 및 Matomo용 NGINX 구성
Matomo는 널리 사용되는 여러 웹 서버 소프트웨어와 잘 작동합니다. 이 튜토리얼에서는 Nginx를 선택했습니다.
Ubuntu 리포지토리에서 Nginx의 최신 메인라인 릴리스를 다운로드하여 설치합니다.
sudo apt install -y nginx
Nginx 버전 확인:
sudo nginx -v
# nginx version: nginx/1.14.0
다음을 실행하여 Matomo용 Nginx를 구성합니다.
sudo vim /etc/nginx/sites-available/matomo.conf
그리고 다음 구성으로 파일을 채웁니다.
server {
listen [::]:443 ssl http2;
listen 443 ssl http2;
listen [::]:80;
listen 80;
server_name example.com;
root /var/www/matomo/;
index index.php;
ssl_certificate /etc/letsencrypt/example.com/fullchain.cer;
ssl_certificate_key /etc/letsencrypt/example.com/example.com.key;
ssl_certificate /etc/letsencrypt/example.com_ecc/fullchain.cer;
ssl_certificate_key /etc/letsencrypt/example.com_ecc/example.com.key;
location ~ ^/(index|matomo|piwik|js/index).php {
include snippets/fastcgi-php.conf;
fastcgi_param HTTP_PROXY "";
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
location = /plugins/HeatmapSessionRecording/configs.php {
include snippets/fastcgi-php.conf;
fastcgi_param HTTP_PROXY "";
fastcgi_pass unix:/var/run/php/php7.2-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;
}
}
참고: Matomo에 대한 완전한 프로덕션 준비 Nginx 구성을 보려면 https://github.com/matomo-org/matomo-nginx를 방문하세요.
파일을 sites-enabled
디렉토리에 연결하여 새로운 matomo.conf
구성을 활성화합니다.
sudo ln -s /etc/nginx/sites-available/matomo.conf /etc/nginx/sites-enabled
구문 오류에 대한 Nginx 구성을 확인하십시오.
sudo nginx -t
Nginx 서비스 다시 로드:
sudo systemctl reload nginx.service
4단계 - Matomo Analytics 설치
/var/www
디렉토리 만들기:
sudo mkdir -p /var/www/
/var/www
디렉토리로 이동합니다.
cd /var/www/
wget을 통해 최신 릴리스 Matomo를 다운로드하고 압축을 풉니다.
sudo wget https://builds.matomo.org/matomo.zip && sudo unzip matomo.zip
다운로드한 matomo.zip
파일을 제거합니다.
sudo rm matomo.zip
/var/www/matomo
디렉토리의 소유권을 www-data
user:
로 변경합니다.
sudo chown -R www-data:www-data /var/www/matomo
5단계 - Matomo Analytics 설정 완료
웹 브라우저에서 사이트를 열고 Matomo 웹 설치 마법사를 따릅니다.
먼저 Matomo 환영 메시지가 나타납니다. "다음" 버튼을 클릭합니다:

그러면 \시스템 검사\ 페이지가 나타납니다. 빠진 것이 있으면 경고가 표시됩니다. 모든 항목에 녹색 확인 표시가 있으면 "다음" 버튼을 클릭하여 다음 단계로 진행합니다.

그런 다음 데이터베이스 세부정보를 입력하고 "다음" 버튼을 클릭합니다.

데이터베이스 설정에 모든 것이 순조롭게 진행되었다면 "Tables created with successful!" 메시지가 표시되어야 합니다.

Matomo 슈퍼 사용자 계정을 만들고 "다음" 버튼을 클릭합니다.

다음으로 Matomo로 추적하고 분석할 첫 번째 웹사이트를 설정합니다. 나중에 Matomo로 추적할 사이트를 더 추가할 수 있습니다.

다음으로 추적을 시작하기 위해 추가해야 하는 사이트의 JavaScript 추적 코드가 제공됩니다.

다음으로 Matomo 설치가 완료된 것을 볼 수 있습니다.

축하합니다! Matomo 설치가 완료되었습니다.
연결
- https://matomo.org/
- https://github.com/matomo-org/matomo-nginx