Mercure Setup
Start and configure Mercure server
Pimcore Studio works with Mercure 0.x and 1.x hubs (see the Mercure docs):
| Hub | Docker image | MERCURE_EXTRA_DIRECTIVES |
|---|---|---|
| 1.x (recommended) | dunglas/mercure:v1 | anonymous; optionally protocol_version_compatibility 8 |
| 0.x | dunglas/mercure:v0.24 | anonymous; never add protocol_version_compatibility 8 |
Since 2026.4. Before 2026.4, Studio speaks only the 0.x protocol: a 1.x hub needs
protocol_version_compatibility 8.
Pin the image to v1 or v0.24. The 0.x protocol is removed in the next major version.
mercure_settings.protocol_version:auto(default) detects the protocol viaGET <hub origin>/.well-known/oauth-protected-resource<hub path>ofhub_url_server, from PHP; let it through proxies.0.xor1.0skip the detection.- Studio sets two cookies with the same token:
mercureAuthorization(0.x) and__Secure-mercure_access_token(1.0).
Mercure configuration
- Add the same JWT key to
MERCURE_PUBLISHER_JWT_KEYandMERCURE_SUBSCRIBER_JWT_KEY - The JWT key needs to be at least 256 bits (32 characters) long
1.x hubs without compatibility mode
issuer(defaulthttps://localhost) must be in the hub'sMERCURE_TRUSTED_ISSUERS.cookie_name: over plain HTTP the cookie ismercure_access_token; addcookie_name mercure_access_tokento the hub.resource_identifier: set it, and the hub'sresource_identifier, when a proxy exposes the hub under another host.
Example Configuration with docker compose
Following there are configuration snippets for a setup with docker compose.
In that case, Mercure is only exposed via nginx reverse proxy that runs under https. Internal communication is handled via http (which is handy when using self-signed certificates in development context).
nginx.conf
Configure reverse proxy in nginx to route Mercure traffic accordingly.
server {
# (...)
location /hub {
proxy_pass http://mercure/.well-known/mercure;
}
# Thumbnails
# (...)
}
docker-compose.yaml
Add Mercure to your docker compose file and make sure to add the configuration for JWT keys and anonymous directives.
# add here all the other necessary containers...
# configure nginx to run under https
nginx:
image: nginx:stable-alpine
ports:
- 443:443
depends_on:
- php
volumes:
- ./studio-demo:/var/www/html:ro
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
# certificates for running nginx (for direct edit to work, system has to run with https)
- ~/.certs:/etc/nginx/certs
mercure:
image: dunglas/mercure:v1
restart: unless-stopped
environment:
# Disable HTTPS
SERVER_NAME: ':80'
MERCURE_PUBLISHER_JWT_KEY: '<your-256-bit-secret-min-32-chars>'
MERCURE_SUBSCRIBER_JWT_KEY: '<your-256-bit-secret-min-32-chars>'
MERCURE_EXTRA_DIRECTIVES: anonymous
expose:
- "80"
volumes:
- pimcore-demo-mercure-data:/data
- pimcore-demo-mercure-config:/config
volumes:
# ...
# Add volumes for mercure
pimcore-demo-mercure-data:
pimcore-demo-mercure-config:
config.yaml
Configure Pimcore application with JWT key as well as the client side and server side URLs for Mercure.
hub_url_server must be set and has no default; it is not checked at boot, but without it no updates are published.
hub_url_client is optional; if it is not set, the scheme and host of the current request plus /hub is used.
pimcore_studio_backend:
mercure_settings:
jwt_key: '<your-256-bit-secret-min-32-chars>'
hub_url_client: 'https://your-app-domain.com/hub'
hub_url_server: 'http://mercure/.well-known/mercure'
If you would like to retrieve the URLs from within the application, you can use the following methods:
getClientSideUrl()to get the client URLgetServerSideUrl()to get the server URL
These methods are available in the Pimcore\Bundle\StudioBackendBundle\Mercure\Service\UrlServiceInterface class interface.
Check if Mercure is running
To see if Mercure is up and available, call https://your-app-domain.com/hub (or hub_url_client
you configured in configuration). This request should return the text
missing "match" subscription parameter
or
Unauthorized
Also execute
curlagainst thehub_url_serveryou configured (e.g.curl http://mercure/.well-known/mercure) from the command line of the server, inside the PHP container if you use Docker, to ensure that the URL is accessible by the server itself. The public/hubURL is not a substitute: it can answer whilehub_url_serveris unreachable from PHP.
Additional Aspects
Multiple application nodes
When Pimcore runs on several application nodes (load balancer, cluster), run one Mercure hub (one logical hub that all nodes share; for a highly available hub see below) for all of them. Do not start one independent hub per node behind a load balancer.
Mercure stores subscriptions and the update history in the hub itself. The free transports (bolt, local) are
single-node, and a load balancer alone does not synchronize hubs. With one hub per node, an update published by node 1
never reaches a browser that is connected to the hub of node 2. See the
Mercure cluster docs.
Recommended setup:
- Run Mercure as a separate service (not co-located with a single application node) and mount a persistent
/datavolume. - Use the same
jwt_keyon all application nodes, and set bothMERCURE_PUBLISHER_JWT_KEYandMERCURE_SUBSCRIBER_JWT_KEYon the hub to that samejwt_keyvalue. - Point
hub_url_serverof every node to that hub, and routehub_url_client(public URL) to it.
One hub is usually enough, as Mercure is lightweight. It only carries live updates. If it is unreachable, publishing errors are logged. If it hangs or is overloaded, publishing requests can block until the HTTP timeout (up to 60 seconds) before failing. Only job progress falls back to polling; other live updates (e.g. the live notification toast and badge, or Direct Edit events) are not delivered while the hub is down. Notifications themselves are stored before they are published, so they still show up after the next reload.
If the hub itself needs to be highly available, Mercure offers clustered editions (Mercure Enterprise with a shared transport, or Mercure Cloud; both are licensed by Mercure, not by Pimcore). Note that these are Mercure 1.x hubs, which need the compatibility mode described at the top of this page, and their compatibility with this bundle's setup has not been verified. Alternatively, restart the single hub quickly with a process supervisor or your orchestrator.
The legacy Direct Edit path (
FileEditControllerTraitofpimcore/direct-edit, deprecated since 2026.3, removal planned for 2027.1) asks the hub which clients are subscribed (subscriptions API). This requires that all clients are connected to the one hub the application asks, with thesubscriptionsdirective enabled. If you run that hub as a cluster, only the Redis/Valkey transport supports subscriptions cluster-wide. This path speaks only the 0.x protocol: with a 1.x hub it needsprotocol_version_compatibility 8.Direct Edit also has its own, deprecated hub settings (
mercure_settings.server_side_url,parameters.mercure.hub.*) that can override the hub URL and key. Remove them or set them to the same values as the hub configured above.
Running Mercure with external URL
When running Mercure as external service with external URL, make sure to configure CSP properly.
Mercure Configuration
Sample based on docker compose, important part is the cors_origins directive.
mercure:
image: dunglas/mercure:v1
restart: unless-stopped
environment:
# All other necessary configs ...
# ...
# Add anonymous directives and cors configuration
MERCURE_EXTRA_DIRECTIVES: |-
anonymous
cors_origins "https://<YOUR_PIMCORE_URL>"
Webserver Reverse Proxy
When you are using Mercure default URLs, you might need to configure a reverse proxy to make sure the Mercure requests are routed correctly to the Mercure instance.
Also, keep in mind, that communication needs to be HTTPS. Thus, it might be useful to place the Mercure server behind a reverse proxy of the actual webserver (who handles the certificates).
Beware that the development UI is not working when using a reverse proxy. (See open ticket https://github.com/dunglas/mercure/issues/951)
Apache Reverse Proxy
For Apache, for example, enable http_proxy in apache and add the following reverse proxy in your apache config:
ProxyPass /hub http://localhost:3000/.well-known/mercure
ProxyPassReverse /hub http://localhost:3000/.well-known/mercure
Nginx Reverse Proxy
For Nginx use following configuration:
location /hub {
proxy_pass http://mercure/.well-known/mercure;
}
Development UI
The development UI can be helpful to develop new features. It is possible to subscribe and publish messages.
With the configuration below, the development UI is available at http://localhost:8080/.well-known/mercure/debug/.
mercure:
image: dunglas/mercure:v1
restart: unless-stopped
environment:
# All other necessary configs ...
# ...
MERCURE_EXTRA_DIRECTIVES: |-
anonymous
debugger
ports:
- "8080:80"
debugger only serves the UI, which uses the token you provide, and is safe in production. playground also mints an
all-access token and relaxes the hub's security settings: use it only for local development.
Please note the trailing slash in the URL, without it the UI will not be available.