GNU/Linux >> Tutoriales Linux >  >> Cent OS

Cómo instalar Matomo (Piwik) Web Analytics en CentOS 8

Matomo, anteriormente conocido como Piwik, es una aplicación de análisis de código abierto para el sistema operativo Linux. Es muy similar a Google Analytics que lo ayuda a rastrear y mostrar la ubicación de las visitas de los usuarios. Fue desarrollado por un equipo de desarrolladores internacionales que se ejecuta en un servidor web PHP/MySQL. Ofrece muchas características, algunas de ellas se enumeran a continuación:

  • Flexibilidad, confiabilidad y seguridad
  • Alojamiento propio, simple y fácil de usar
  • 100 % de propiedad de los datos
  • Cumplimiento del RGPD
  • Análisis web y móvil

En este tutorial, le mostraremos cómo instalar y configurar la aplicación de análisis Piwik en el servidor CentOS 8.

Requisitos

  • Un servidor que ejecuta CentOS 8.
  • Un nombre de dominio válido apuntado con la IP de su servidor.
  • Se ha configurado una contraseña raíz en su servidor.

Instalar servidor LAMP

Piwik se ejecuta en un servidor LAMP, por lo que deberá instalar Apache, MariaDB, PHP y otras extensiones de PHP en su sistema. Puede instalarlos todos con el siguiente comando:

dnf install httpd mariadb-server php php-mysqlnd php-fpm unzip wget php-json php-dom php-gd php-mbstring -y

Una vez que todos los paquetes estén instalados, edite el archivo php.ini y establezca algunos valores deseados:

nano /etc/php.ini

Cambie los siguientes valores:

upload_max_filesize = 10M
post_max_size = 10M
max_execution_time = 300
max_input_time = 300
memory_limit = 256M

Guarde y cierre el archivo, luego inicie el servicio Apache y MariaDB y habilítelos para que se inicien al reiniciar el sistema:

systemctl start mariadb
systemctl start httpd
systemctl enable mariadb
systemctl enable httpd

Crear una base de datos para Piwik

A continuación, deberá crear una base de datos y un usuario para Piwik. Primero, inicie sesión en MariaDB con el siguiente comando:

mysql

Una vez que inicie sesión, cree una base de datos y un usuario con el siguiente comando:

mysql> CREATE DATABASE matomo;
mysql> CREATE USER `matomo`@`localhost` IDENTIFIED BY 'password';

A continuación, otorgue todos los privilegios a la base de datos con el siguiente comando:

mysql> GRANT ALL ON matomo.* TO `matomo`@`localhost`;

A continuación, elimine los privilegios y salga de MariaDB con el siguiente comando:

mysql> FLUSH PRIVILEGES;
mysql> EXIT;

Instalar Piwik

A continuación, deberá descargar la última versión de Piwik desde su sitio web oficial. Primero, cambie el directorio a la raíz web de Apache con el siguiente comando:

cd /var/www/html

A continuación, descargue Piwik usando el siguiente comando:

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

Una vez completada la descarga, descomprima el archivo descargado con el siguiente comando:

unzip matomo-latest.zip

A continuación, establezca el permiso y la propiedad adecuados para la raíz web con el siguiente comando:

chown -R apache:apache /var/www/html/matomo
chmod -R 775 /var/www/html/matomo

Una vez que haya terminado, puede continuar con el siguiente paso.

Configurar SELinux y Firewall

A continuación, deberá permitir los puertos 80 y 443 a través del firewall. Puede permitirlos con el siguiente comando:

firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https

A continuación, vuelva a cargar el cortafuegos para aplicar los cambios:

firewall-cmd --reload

A continuación, también deberá configurar SELinux para Piwik. Puede configurarlo con el siguiente comando:

chcon -R -t httpd_sys_rw_content_t /var/www/html/matomo/
setsebool httpd_can_network_connect on -P

Una vez que haya terminado, puede continuar con el siguiente paso.

Configurar Apache para Piwik

A continuación, deberá configurar el servidor web Apache para alojar el sitio web de Piwik. Puede hacerlo creando un nuevo archivo de configuración de host virtual de Apache:

nano /etc/httpd/conf.d/piwik.conf

Agregue las siguientes líneas:

<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/var/www/html/matomo"
ServerName piwik.example.com
<Directory "/var/www/html/matomo/">
Options MultiViews FollowSymlinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
TransferLog /var/log/httpd/matomo_access.log
ErrorLog /var/log/httpd/matomo_error.log

</VirtualHost>

Guarde y cierre el archivo cuando haya terminado. Luego, reinicie el servidor web Apache para aplicar los cambios:

systemctl restart httpd

Ahora puede comprobar el estado de Apache con el siguiente comando:

systemctl status httpd

Deberías obtener el siguiente resultado:

? httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
  Drop-In: /usr/lib/systemd/system/httpd.service.d
           ??php-fpm.conf
   Active: active (running) since Sun 2020-12-27 05:38:29 EST; 5s ago
     Docs: man:httpd.service(8)
 Main PID: 4228 (httpd)
   Status: "Started, listening on: port 80"
    Tasks: 213 (limit: 12523)
   Memory: 36.8M
   CGroup: /system.slice/httpd.service
           ??4228 /usr/sbin/httpd -DFOREGROUND
           ??4229 /usr/sbin/httpd -DFOREGROUND
           ??4230 /usr/sbin/httpd -DFOREGROUND
           ??4231 /usr/sbin/httpd -DFOREGROUND
           ??4232 /usr/sbin/httpd -DFOREGROUND

Dec 27 05:38:28 centos8 systemd[1]: Stopped The Apache HTTP Server.
Dec 27 05:38:28 centos8 systemd[1]: Starting The Apache HTTP Server...

Una vez que haya terminado, puede continuar con el siguiente paso.

Acceder a la interfaz web de Piwik

Ahora, abra su navegador web y acceda a la interfaz web de Piwik usando la URL http://piwik.example.com . Será redirigido a la siguiente página:

Haga clic en SIGUIENTE , debería ver la página de comprobación del sistema:

Haga clic en SIGUIENTE , debería ver la página de configuración de la base de datos:

Proporcione el nombre de usuario de su base de datos, el nombre de la base de datos, la contraseña y haga clic en SIGUIENTE , debería ver la siguiente página:

Haga clic en SIGUIENTE , debería ver la página de creación de usuario administrador:

Proporcione su nombre de usuario, contraseña y correo electrónico de administrador y luego haga clic en SIGUIENTE . Debería ver la página de configuración del sitio web:

Proporcione los detalles de su sitio web y haga clic en SIGUIENTE . Debería ver su código de seguimiento en la siguiente página:

Haga clic en SIGUIENTE . Una vez finalizada la instalación. Debería ver la siguiente página:

Haga clic en CONTINUAR A MATOMO . Debería ver la página de inicio de sesión de MATOMO:

Proporcione su nombre de usuario y contraseña de administrador y haga clic en INICIAR SESIÓN . Debería ver el tablero de MATOMO en la siguiente página:

Asegure Matomo con Let's Encrypt SSL

A continuación, deberá instalar la utilidad Certbot en su sistema para descargar e instalar Let's Encrypt SSL para su sitio web de Piwik.

Puede instalar el cliente Certbot con el siguiente comando:

wget https://dl.eff.org/certbot-auto
mv certbot-auto /usr/local/bin/certbot-auto
chown root /usr/local/bin/certbot-auto
chmod 0755 /usr/local/bin/certbot-auto

Luego, obtenga e instale un certificado SSL para su sitio web de Mantis con el siguiente comando:

certbot-auto --apache -d piwik.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): [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 piwik.example.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/httpd/conf.d/piwik.conf

A continuación, deberá elegir si desea redirigir o no el tráfico HTTP a HTTPS, como se muestra a continuación:

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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

Escriba 2 y presione Entrar para continuar. Una vez finalizada la instalación, debería ver el siguiente resultado:

Redirecting all traffic on port 80 to ssl in /etc/httpd/conf.d/piwik.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://piwik.example.com

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

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/piwik.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/piwik.example.com/privkey.pem
   Your cert will expire on 2020-03-23. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot-auto
   again with the "certonly" option. To non-interactively renew *all*
   of your certificates, run "certbot-auto 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

En este punto, su sitio web está protegido con Let's Encrypt SSL.

Conclusión ¡Felicidades! ha instalado y configurado con éxito Piwik con Apache y Let's Encrypt SSL en CentOS 8. Ahora puede agregar su código de seguimiento en su sitio web y comenzar a monitorear a los visitantes de su sitio web desde el panel de control de Piwik. Siéntase libre de preguntarme si tiene alguna pregunta.


Cent OS
  1. Cómo instalar MongoDB en CentOS 8

  2. Cómo instalar el panel web de CentOS en CentOS 6

  3. Cómo instalar XWiki en CentOS 7

  4. Cómo instalar el panel web de CentOS en CentOS 8

  5. Cómo instalar Matomo Web Analytics en Ubuntu 20.04

Cómo instalar Open Web Analytics en CentOS 7

Cómo instalar Piwik en CentOS 7

Cómo instalar Matomo en CentOS 7

Cómo instalar el servidor web Hiawatha en CentOS 7

Cómo instalar el panel web de CentOS en CentOS 7

Cómo instalar Matomo en CentOS 8