Railway

Deploy Matomo

Web analytics platform for tracking visitors to your websites

Deploy Matomo

Just deployed

/var/lib/mysql

Just deployed

/var/www/html

Deploy and Host Matomo on Railway

Matomo is the open-source web analytics platform that keeps visitor data on infrastructure you control. Developed since 2007, it is the closest feature-for-feature replacement for Google Analytics: page and event tracking, visitor profiles, acquisition channels, goals and funnels, e-commerce reporting, a tag manager, heatmaps and session recordings. Teams choose it when analytics data cannot leave their jurisdiction, when they want reports that are never sampled, or because they would rather own the raw logs.

Self-host Matomo on Railway and the application server, its MySQL database and its report archiver are wired together on the first deploy. The web service runs Matomo on Apache with PHP 8.4 and keeps /var/www/html on a persistent volume, so the config file, installed plugins and the geolocation database survive redeploys. MySQL runs as a managed Railway database on its own volume. Report archiving — the scheduled job a production Matomo needs so dashboards are not computed inside a page load — runs beside the web server and refreshes reports hourly.

Diagram of the Matomo and MySQL services on Railway

Getting Started with Matomo on Railway

Open the public URL when the deploy finishes and Matomo's setup wizard appears. There are no default credentials to change: the wizard creates the first super user from the details you type. Step through Welcome and System Check, and note that Database Setup is already filled in — host, user, password, database and table prefix come from the template's variables, so you only press Next. Matomo creates its tables, asks for the super user login, email and password, then for the first website you want to measure.

Give that site a name, its URL and a time zone, and Matomo hands you a JavaScript snippet. Paste it before the closing `` tag, or use the server-side HTTP Tracking API or a plugin for WordPress, Drupal or Shopify. Leave the geolocation box ticked on the final screen so Matomo downloads the free DB-IP City database and reports countries and cities rather than "Unknown".

To confirm the deployment works end to end, load a page on the tracked site and open Visitors → Visits Log. A row appears within seconds with the visitor's country, browser, device and the pages viewed. Dashboard reports are built by the archiver rather than on demand, so fresh data lands on the next archiving run; Visits Log and Real-time are always current.

Matomo dashboard with real-time visits and a visitor world map Matomo visits log showing per-visitor pages, cities and goal conversions Matomo acquisition report ranking search, social and direct traffic

About Hosting Matomo

Matomo answers a question analytics SaaS cannot: where does the data live, and who else can read it. Every pageview, event and visitor profile is written to your own MySQL database, so you can query it directly, keep it as long as you like, delete it on request, and satisfy rules about where personal data is stored. Reports come from the whole log, never a sample.

  • Visitor profiles and a full visits log showing each person's path through the site
  • Acquisition reporting across search engines, keywords, social networks and campaigns
  • Goals, funnels and e-commerce tracking with revenue attribution
  • Heatmaps, session recordings, A/B tests and form analytics via the marketplace
  • A tag manager, a REST reporting API and an access-log importer
  • Privacy controls: IP anonymisation, opt-out, cookie-less tracking, retention limits

The Railway architecture is two services. Matomo serves the UI and the tracking endpoint and holds mutable state — config/config.ini.php, marketplace plugins, the geolocation database — on its volume. MySQL stores every visit, action and pre-computed report. Inside the Matomo container a loop runs console core:archive, the job Matomo's docs ask you to add to cron: it turns raw log rows into the aggregated reports dashboards read, so opening a report never triggers a long computation.

Why Deploy Matomo on Railway

Railway removes the server work self-hosting analytics usually implies.

  • MySQL is provisioned, networked privately and backed by its own volume
  • The application volume, HTTPS domain and health check are configured on deploy
  • Report archiving already runs on a schedule — no cron entry to add
  • Scaling is a slider, and the worker count follows the container's memory
  • Logs, metrics and rollbacks are built in

Common Use Cases

  • Replacing Google Analytics on a marketing site, keeping visitor data out of an ad network
  • Measuring funnels and goals with unsampled data you can query in SQL

Dependencies for Matomo

  • Matomo — the official matomo image, Apache variant, built from matomo-org/matomo. Serves the UI, the tracking endpoint and the reporting API, and runs the archiving loop.
  • MySQL — Railway's managed MySQL. Holds every raw visit and action plus the archived report tables. Matomo is write-heavy, so scale this first.

Environment Variables Reference

VariablePurpose
MATOMO_DATABASE_HOSTPrivate hostname of the MySQL service
MATOMO_DATABASE_DBNAMEDatabase Matomo creates its tables in
MATOMO_DATABASE_ADMIN_URLAdministrative URL used once per boot to create the database and account
MATOMO_ARCHIVE_INTERVAL_SECONDSHow often reports are re-archived, 3600 default
MATOMO_SMTP_HOSTOptional relay for password resets and scheduled report emails

Deployment Dependencies

Hardware Requirements for Self-Hosting Matomo

Matomo's own guidance scales with traffic rather than with the number of sites.

ResourceMinimumRecommended
CPU2 vCPU4+ vCPU above 1M pageviews/month
RAM2 GB8 GB above 1M pageviews/month
Storage5 GB volume plus database50 GB+ at 100k pageviews/month, growing with logs
RuntimePHP 8.x, MySQL 5.5+ / MariaDBPHP 8.4, MySQL 8+

Raw log rows dominate storage. Matomo can delete old log data on a schedule from Administration → Privacy once aggregated reports are built, keeping the database flat over time.

Self-Hosting Matomo

The image needs a MySQL database and a persistent directory at /var/www/html. The smallest working Docker Compose setup is two services:

services:
  db:
    image: mysql:8
    environment: {MYSQL_ROOT_PASSWORD: change-me, MYSQL_DATABASE: matomo}
    volumes: [db:/var/lib/mysql]
  matomo:
    image: matomo:latest
    ports: ["8080:80"]
    environment:
      MATOMO_DATABASE_HOST: db
      MATOMO_DATABASE_USERNAME: root
      MATOMO_DATABASE_PASSWORD: change-me
      MATOMO_DATABASE_DBNAME: matomo
    volumes: [matomo:/var/www/html]
volumes: {db: {}, matomo: {}}

A production install must also archive on a schedule rather than letting browser requests trigger it. The crontab entry Matomo documents, run as the web server user, is:

5 * * * * www-data /usr/bin/php /var/www/html/console core:archive --url=https://analytics.example.com/

Pair it with enable_browser_archiving_triggering = 0 in config/config.ini.php. Both are in place here.

Is Matomo Free to Self-Host?

Matomo On-Premise is free and open source under the GPL v3, with unlimited websites, users and hits — no per-pageview charge and no feature gate on the core analytics. Some marketplace plugins are paid, including Heatmaps & Session Recording and A/B Testing, and Matomo sells support bundles and a Cloud plan from €29/month. Self-hosting on Railway costs infrastructure only.

FAQ

What is Matomo? Matomo is an open-source web analytics platform, and the most complete self-hosted alternative to Google Analytics. It records pageviews, events, goals and e-commerce orders into a database you own, and reports on them through a dashboard, a REST API and scheduled emails.

What does this Railway template deploy? Two services: Matomo on Apache with PHP 8.4 on a persistent volume, and a managed MySQL database. The Matomo container also runs the hourly report archiving job a production install normally needs a cron entry for.

Why does the template include a MySQL database? Matomo has no embedded storage option. Every visit, action, goal conversion and pre-computed report table lives in MySQL, which is where the install grows over time.

Why are my reports empty when the Visits Log shows traffic? Reports are pre-computed by the archiving job rather than on page load, which is what Matomo recommends in production. New data appears after the next run — hourly by default, adjustable with MATOMO_ARCHIVE_INTERVAL_SECONDS. Visits Log and Real-time read raw data and are always current.

Does self-hosted Matomo record real visitor IP addresses behind a proxy? Yes. Matomo is configured here to read the client address from the forwarded-for header the platform edge sets, so visits are attributed to real visitors rather than to the proxy. IP anonymisation is still on by default under Administration → Privacy.


Template Content

More templates in this category

View Template
NEW
Betterlytics
Betterlytics is a cookieless analytics platform GDPR-compliant.

Anarchist Manifesto
22
View Template
NEW
Finance Tracker
Private multi-user household finance ledger with budgets and CSV import.

wotonews
0
View Template
Matomo Analytics + MariaDB
Privacy-friendly analytics with MariaDB and persistent volumes.

leodev
1