GNU/Linux >> Linux の 問題 >  >> Ubuntu

Ubuntu20.04にMatomoWebAnalyticsをインストールする方法

以前はPiwikとして知られていたMatomoは、無料のオープンソースWeb分析アプリケーションであり、Webサイトのオンライン訪問者を追跡するのに役立ちます。これは、サードパーティのソリューションを使用せずに独自のWebサイト分析とデータを完全に制御できるGoogleAnalyticsソフトウェアの代替手段です。訪問、ダウンロード、目標コンバージョン率、キーワードなどの主要業績評価指標を追跡するために使用できる中小企業向けに設計されています。

このチュートリアルでは、NginxとLet'sEncryptSSLを使用してUbuntu20.04にMatomoWeb分析ソフトウェアをインストールする方法を示します。

前提条件
  • Ubuntu20.04を実行しているサーバー。
  • サーバーIPで指定された有効なドメイン名。
  • ルートパスワードがサーバーに設定されます。
はじめに

まず、システムパッケージを最新バージョンに更新することをお勧めします。次のコマンドを実行して更新できます:

apt-get update -y

すべてのパッケージが更新されたら、次のコマンドを実行して、他の必要な依存関係をインストールします。

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

必要なパッケージをすべてインストールしたら、次の手順に進むことができます。

LEMPサーバーをインストールする

Matomoは、PHPで記述されたWebサーバー上で実行され、データベースに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をダウンロード

まず、次のコマンドを使用して、Matomoの最新バージョンを公式WebサイトからNginxWebルートディレクトリにダウンロードします。

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にサービスを提供するように構成されています。これで、次のステップに進むことができます。

SSLを暗号化してLet'sで安全なMatomo

Let'sEncryptSSLを使用してWebサイトを保護することは常に良い考えです。まず、次のコマンドを使用して、CertbotLet'sEncryptクライアントをサーバーにインストールします。

apt-get install python3-certbot-nginx -y

インストールしたら、次のコマンドを実行して、Let'sEncryptSSLでWebサイトを保護します。

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): [email protected]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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.

これで、MatomoWebサイトはLet'sEncryptSSLで保護されました。

アクセスMatomoアナリティクス

次に、Webブラウザーを開き、URLhttps://matomo.linuxbuz.comを入力します。 Matomoのウェルカム画面にリダイレクトされます:

次へをクリックします ボタン。 Matomoの前提条件チェック画面が表示されます:

次へをクリックします ボタン。 matomoデータベース設定画面が表示されます:

データベースの詳細を入力し、次へをクリックします ボタン。次の画面が表示されます。

次へをクリックします ボタン。管理者ユーザー設定画面が表示されます:

管理者のユーザー名、パスワード、メールアドレスを入力し、次へをクリックします ボタン。ウェブサイトの設定画面が表示されます:

ウェブサイトの詳細を入力し、次へをクリックします ボタン。次の画面が表示されます。

次へをクリックします ボタン。インストールが完了すると、次の画面が表示されます。

CONTINUE TO MATOMOをクリックします 。 Matomoのログイン画面にリダイレクトされます:

管理者のユーザー名とパスワードを入力し、サインインをクリックします ボタン。次の画面にMatomoダッシュボードが表示されます。

結論

おめでとう!これで、Ubuntu20.04にNginxとLet'sEncryptを使用してMatomoアナリティクスが正常にインストールおよび構成されました。これで、あなたのWebサイトをMatomoと統合し、Webサイトの追跡を開始できます。ご不明な点がございましたら、お気軽にお問い合わせください。


Ubuntu
  1. Ubuntu18.04にLogstashをインストールする方法

  2. Ubuntu20.04にMatomoWebAnalyticsをインストールする方法

  3. Ubuntu18.04にRをインストールする方法

  1. Ubuntu18.04にChromiumWebブラウザをインストールする方法

  2. Debian9にMatomoWebAnalyticsをインストールする方法

  3. Ubuntu18.04にPloneCMSをインストールする方法

  1. Ubuntu18.04LTSにMatomoWebAnalyticsをインストールする方法

  2. Ubuntu20.04LTSにMetabaseBusinessAnalyticsをインストールする方法

  3. CentOS 8にMatomo(Piwik)WebAnalyticsをインストールする方法