Matomo: Full CLI Automation Workflow
Start Matomo, retrieve its credentials, and modify its configuration programmatically using the Stackhero CLI
👋 Welcome to the Stackhero documentation!
Stackhero offers a Matomo cloud solution that simplifies web analytics:
- Unlimited websites, members, segments, goals, and data retention: analyse everything you need, for as long as you require.
- Effortless updates: keep your analytics platform up to date with a single click.
- Custom domain name with HTTPS: run Matomo at a secure, branded URL, such as https://analytics.your-company.com.
- High performance and enhanced security: your data is hosted on private, dedicated infrastructure to ensure reliability and confidentiality.
With Stackhero, you can deploy Matomo analytics in just a few minutes and manage all your sites from a single location. Try our Matomo cloud hosting to simplify your analytics and focus on what matters most.
This guide explains how to create a Matomo service, access its credentials, and update its configuration entirely via the command line, without any interaction with the dashboard. This approach is ideal for scripts, CI pipelines, and AI agents.
We will use the Stackhero CLI for all operations. If you have not already installed it, you can do so with:
curl -fsSL https://www.stackhero.io/install.sh | sh
1. Authenticate
The simplest way to get started is to log in through your browser. When you run the login command, the CLI opens a web page where you can grant access. No passwords or 2FA codes are entered into the CLI itself.
stackhero login
Once logged in, your credentials are stored locally and will be used automatically for subsequent CLI commands.
For fully automated environments such as scripts or CI pipelines, you may prefer a non-interactive access token. You can generate one from your dashboard (Account > Access tokens), then export it as an environment variable. The CLI and any scripts you run will automatically use it.
export STACKHERO_TOKEN="usr-xxxxxx:your-token"
2. Locate the Matomo service store
Next, you will want to list the available Matomo service stores for your account. The CLI accepts the store name (matomo) directly, so there is no need to look up or copy any IDs.
# List Matomo service stores (add --organization if you manage more than one)
stackhero services-store-list --name="matomo"
You can use the store name matomo in subsequent commands. It always refers to the latest stable version.
3. Select an instance size and a region
# List instance sizes for your service store (use the NAME column for --instance)
stackhero instances-store-list --service-store=matomo
# List available regions (names such as "europe")
stackhero regions-list
4. Create the service
Below is an example script that creates a stack, adds your Matomo service to it, waits for it to start, retrieves its configuration (including generated credentials), and then applies a new configuration.
#!/bin/bash
set -e
export STACKHERO_TOKEN="usr-xxxxxx:your-token"
serviceStore="matomo" # The Matomo service store name (see step 2)
instance="..." # An instance size from step 3
region="europe" # A region name from step 3
# Create a stack for your service (uses your default organisation; add --organization if needed)
stackId=$(stackhero --format=script stack-create \
--name="My Matomo stack")
echo "Stack created: ${stackId}"
# Add Matomo to the stack (names are resolved automatically)
serviceId=$(stackhero --format=script service-add \
--stack="My Matomo stack" \
--service-store="${serviceStore}" \
--instance="${instance}" \
--region="${region}")
echo "Service added: matomo"
# Wait for the service to be fully operational (this may take a few minutes)
stackhero service-wait-for --service="matomo"
# Retrieve the service configuration, including generated credentials
stackhero service-configuration-get --service="matomo" --format=json
5. Retrieve credentials
The service-configuration-get command returns the complete configuration for your service, including auto-generated passwords and connection details. The output is in JSON format, making it straightforward to use in scripts and automation.
stackhero service-configuration-get --service=svc-xxxxxx --format=json
6. Update the configuration
You can review an example configuration schema and then apply your own settings. When you update the configuration, the service may restart to apply the changes.
# View the configuration schema and an example for your service
stackhero service-configuration-example --service=svc-xxxxxx
# Apply a custom configuration (the service restarts if required)
stackhero service-configuration-set \
--service=svc-xxxxxx \
--configuration='{ "...": "..." }'
# Wait for the new configuration to be applied
stackhero service-wait-for --service=svc-xxxxxx
7. Keep your service up to date
When a new version of Matomo is available, you can view and install it from the command line as well:
# Show the current version, available updates, and their severity
stackhero service-updates-list --service=svc-xxxxxx
# Install the next update (a backup is taken first), then wait for the service to be operational again
stackhero service-update --service=svc-xxxxxx --confirm
stackhero service-wait-for --service=svc-xxxxxx
That is the complete process. You have now seen the full lifecycle: start a service, retrieve its credentials, reconfigure it, and keep it up to date, all in a scriptable, automated manner. To learn more, refer to the full CLI documentation, which also covers the non-interactive STACKHERO_TOKEN authentication shown here. To run your tests against a real Matomo in GitHub Actions or GitLab CI, see Start services for your CI tests.