Self-hosting Matomo to share Ghost's MySQL database

This Matomo Analytics tip is for those self-hosting Ghost on a VPS with limited resources.

Both Matomo and Ghost use MySQL, but the official docs for Matomo advise setting up a private instance of MySQL for Matomo. That’s good for isolation, but also uses some extra precious memory which could be saved if Matomo and Ghost were set to share the same database.

Here’s how I set up Matomo running in a container with podman to share the MySQL database running on the host:

Note that for MySQL to bind to the private IP address 10.88.0.1, first the matomo service has to started, which triggers Podman to create this private network. So until Matomo starts, MySQL will refuse to start because it can’t bind to the 10.88.0.1 address because it hasn’t been created yet.

Suggestions are welcome on a better way to set this up! Ideally, MySQL would not rely on Matomo being started to run!