![見出し画像](https://assets.st-note.com/production/uploads/images/159269098/rectangle_large_type_2_074d9def0f9180bf297d0cffeda54d1f.png?width=1200)
[#11] matomoのインストール オンプレ版
皆さんはホームページの解析に何を使っていますか
・GoogleAnalytics
・ページに解析ロジックを埋め込む
今回はGoogleAnalyticsの代替になるアクセス解析ソフトである、オープンソースのmatomoのご紹介
CentOS系へのインストール メモ
https://ja.linux-console.net/?p=2951#gsc.tab=0
[@hare1 ~]$ cd /var/www/html
[@share1 html]$ wget https://builds.matomo.org/matomo-latest.zip
--2023-08-31 10:45:38-- https://builds.matomo.org/matomo-latest.zip
builds.matomo.org (builds.matomo.org) をDNSに問いあわせています... 185.31.40.177, 2a00:b6e0:1:200:177::1
builds.matomo.org (builds.matomo.org)|185.31.40.177|:443 に接続しています... 接 続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 21945363 (21M) [application/zip]
matomo-latest.zip: 許可がありません
`matomo-latest.zip' へ書き込めません(許可がありません)。
[@share1 html]$ su
パスワード:
[root@share1 html]# wget https://builds.matomo.org/matomo-latest.zip
--2023-08-31 10:46:00-- https://builds.matomo.org/matomo-latest.zip
builds.matomo.org (builds.matomo.org) をDNSに問いあわせています... 185.31.40.177, 2a00:b6e0:1:200:177::1
builds.matomo.org (builds.matomo.org)|185.31.40.177|:443 に接続しています... 接 続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 21945363 (21M) [application/zip]
`matomo-latest.zip' に保存中
matomo-latest.zip 95%[==================> ] 19.91M 110KB/s 時間 7m 12s
2023-08-31 10:53:13 (47.2 KB/s) - 20875940 バイトで接続が終了しました。 再試行しています。
--2023-08-31 10:53:14-- (試行: 2) https://builds.matomo.org/matomo-latest.zip
builds.matomo.org (builds.matomo.org)|185.31.40.177|:443 に接続しています... 接 続しました。
HTTP による接続要求を送信しました、応答を待っています... 206 Partial Content
長さ: 21945363 (21M), 1069423 (1.0M) 残っています [application/zip]
`matomo-latest.zip' に保存中
matomo-latest.zip 100%[+++++++++++++++++++>] 20.93M 43.6KB/s 時間 36s
2023-08-31 10:53:53 (28.8 KB/s) - `matomo-latest.zip' へ保存完了 [21945363/21945363]
[root@share1 html]# chown -R apache:apache /var/www/html/matomo
[root@share1 html]# chmod -R 775 /var/www/html/matomo
[root@share1 html]# cd /etc/httpd/conf.d/
次に、matomo用のデータベースとユーザーを作成する必要があります。まず、次のコマンドで MariaDB にログインします。
mysql
ログインしたら、次のコマンドを使用してデータベースとユーザーを作成します。
mysql> CREATE DATABASE matomo;
mysql> CREATE USER `matomo`@`localhost` IDENTIFIED BY 'password';
次に、次のコマンドを使用して、データベースにすべての権限を付与します。
mysql> GRANT ALL ON matomo.* TO `matomo`@`localhost`;
次に、特権をフラッシュし、次のコマンドで MariaDB を終了します。
mysql> FLUSH PRIVILEGES;
mysql> EXIT;
解析したいページへ==============================
<!-- Matomo -->
<script>
var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//172.20.11.XX/matomo/"; <--ここを書き込むIPに変更
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '1']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<!-- End Matomo Code -->
![](https://assets.st-note.com/img/1725518496-gim3cVnT51bsJylXAFhr6WNB.png?width=1200)