Self-host Mautic 7 with Docker: install, email, cron

Mautic is an open source marketing automation platform. It handles contacts, segments, campaigns, forms and email. You run it yourself and send email through a provider of your choice. This guide installs Mautic 7 with Docker Compose and gets it ready to send: email transport, DNS records for deliverability, the background jobs Mautic needs, and backups.

author
Zahara Schaefer
published
updated
read
7 min
tested
Mautic 7.2 with the official mautic/mautic Docker image, MariaDB 11 (requirements and cron commands from docs.mautic.org 7.2)
outline {
  1. What you need
  2. 1. Create the folder and environment file
  3. 2. Write the Compose file
  4. 3. Start it and run the installer
  5. 4. Set the cron jobs
  6. 5. Connect your email provider
  7. 6. Authenticate your domain: SPF, DKIM and DMARC
  8. 7. Back it up
  9. 8. Upgrading
  10. Troubleshooting
  11. References

One thing to know before you start: running your own Mautic means you own deliverability. Your provider sends the mail, but your domain's reputation, list hygiene and DNS records decide whether it lands in the inbox.

What you need

  • A Linux server with Docker Engine and the Compose plugin. Mautic doesn't recommend shared hosting.
  • A domain or subdomain for Mautic, for example m.example.com, with an A record pointing at the server.
  • An account with an email sending provider that supports SMTP or a Symfony Mailer transport (Amazon SES, Postmark, Mailgun, SendGrid, Brevo and others).
  • Access to your domain's DNS.
  • A reverse proxy for HTTPS. The example uses Caddy.

Mautic 7 requires PHP 8.2 to 8.5 and MySQL 8.4+ or MariaDB 10.11+, per the requirements page. The Docker image takes care of PHP.

Step 1: Create the folder and environment file

bash
sudo mkdir -p /opt/mautic && cd /opt/mautic
sudo chown "$USER" /opt/mautic

cat > .env <<ENV
MYSQL_ROOT_PASSWORD=$(openssl rand -hex 24)
MAUTIC_DB_PASSWORD=$(openssl rand -hex 24)
DOMAIN=m.example.com
ENV
chmod 600 .env
mkdir -p cron mautic/config mautic/logs mautic/media/files mautic/media/images

Check it worked: .env exists with mode -rw------- and three filled-in lines.

Step 2: Write the Compose file

The official image runs in one of three roles, set with DOCKER_MAUTIC_ROLE:

  • mautic_web serves the app;
  • mautic_cron runs the scheduled jobs;
  • mautic_worker processes queued messages.

All three share the same volumes.

yaml/opt/mautic/compose.yaml
# /opt/mautic/compose.yaml
x-mautic: &mautic
  image: mautic/mautic:7-apache
  restart: unless-stopped
  environment: &env
    MAUTIC_DB_HOST: db
    MAUTIC_DB_PORT: 3306
    MAUTIC_DB_DATABASE: mautic
    MAUTIC_DB_USER: mautic
    MAUTIC_DB_PASSWORD: ${MAUTIC_DB_PASSWORD}
  volumes:
    - ./mautic/config:/var/www/html/config
    - ./mautic/logs:/var/www/html/var/logs
    - ./mautic/media/files:/var/www/html/docroot/media/files
    - ./mautic/media/images:/var/www/html/docroot/media/images
    - ./cron:/opt/mautic/cron
  depends_on:
    db:
      condition: service_healthy

services:
  db:
    image: mariadb:11.4
    restart: unless-stopped
    environment:
      MARIADB_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      MARIADB_DATABASE: mautic
      MARIADB_USER: mautic
      MARIADB_PASSWORD: ${MAUTIC_DB_PASSWORD}
    volumes:
      - db_data:/var/lib/mysql
    healthcheck:
      test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
      interval: 10s
      retries: 10

  mautic_web:
    <<: *mautic
    environment:
      <<: *env
      DOCKER_MAUTIC_ROLE: mautic_web

  mautic_cron:
    <<: *mautic
    environment:
      <<: *env
      DOCKER_MAUTIC_ROLE: mautic_cron

  mautic_worker:
    <<: *mautic
    environment:
      <<: *env
      DOCKER_MAUTIC_ROLE: mautic_worker

  caddy:
    image: caddy:2
    restart: unless-stopped
    ports: ["80:80", "443:443"]
    environment:
      DOMAIN: ${DOMAIN}
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile:ro
      - caddy_data:/data

volumes:
  db_data:
  caddy_data:

And the Caddyfile:

text
{$DOMAIN} {
	reverse_proxy mautic_web:80
}

7-apache follows the latest 7.x release. For production, pin an exact tag (for example 7.2.x-apache, with the current patch number from Docker Hub), so updates happen when you choose. The mautic_cron role reads /opt/mautic/cron/mautic. Create that file in step 4. If you already started the stack with an empty ./cron, write the file and run docker compose restart mautic_cron.

Check it worked: docker compose config shows no errors.

Step 3: Start it and run the installer

bash
docker compose up -d
docker compose logs -f mautic_web

Open https://m.example.com. The web installer checks the environment, confirms the database settings (already filled in from the environment variables), and asks you to create the admin user.

Check it worked: you can log in, and Settings (cog) > System Info shows the Mautic version and no failed requirements.

Step 4: Set the cron jobs

Mautic does most of its work in the background. Without cron, segments don't update, campaigns don't run, and queued emails don't send. The cron jobs page lists them. The docker-mautic cron role installs /opt/mautic/cron/mautic for the www-data user and expects output on the /tmp/stdout fifo. Create that file on the host (this is ./cron/mautic from the compose mount), spread across the minutes so the jobs don't all start at once:

bash
cat > /opt/mautic/cron/mautic <<'CRON'
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
BASH_ENV=/tmp/cron.env

0,15,30,45 * * * * php /var/www/html/bin/console mautic:segments:update 2>&1 | tee /tmp/stdout
5,20,35,50 * * * * php /var/www/html/bin/console mautic:campaigns:update 2>&1 | tee /tmp/stdout
10,25,40,55 * * * * php /var/www/html/bin/console mautic:campaigns:trigger 2>&1 | tee /tmp/stdout
*/5 * * * * php /var/www/html/bin/console mautic:webhooks:process 2>&1 | tee /tmp/stdout
CRON

If the stack is already running, restart cron so it reloads the file: docker compose restart mautic_cron. On big lists, add --batch-limit to the segment job to control memory use.

Emails sent through the queue are handled by the mautic_worker container, which runs messenger:consume. If you run Mautic without that container, add a cron entry such as php /var/www/html/bin/console messenger:consume email --time-limit=160 2>&1 | tee /tmp/stdout instead.

Check it worked: docker compose logs mautic_cron shows the jobs running. Create a segment with a simple filter; within one cron cycle, its contact count updates. You can also run a job by hand:

bash
docker compose exec -u www-data mautic_web php bin/console mautic:segments:update

Step 5: Connect your email provider

Go to Settings > Configuration > Email Settings. Mautic 7 uses Symfony Mailer, configured with a DSN. For plain SMTP:

text
smtp://USERNAME:PASSWORD@smtp.provider.example:587

Enter the parts in the fields Mautic shows (scheme, host, port, user, password). Several providers have their own transport plugin with API support. Check the Mautic marketplace and your provider's docs.

Set the From name and From address to an address on the domain you'll authenticate in step 6. Then turn on queue sending, if you're running the worker, so sending doesn't block the web app.

Check it worked: click Send test email. It arrives, and the message headers show your provider.

Step 6: Authenticate your domain: SPF, DKIM and DMARC

Without these records, mail from Mautic is likely to land in spam, or be rejected. Your provider gives you the exact values. The shapes look like this:

text
; SPF: authorise your provider to send for the domain (one SPF record per domain)
example.com.       TXT   "v=spf1 include:<provider-spf-domain> ~all"

; DKIM: public key published by your provider
<selector>._domainkey.example.com.   CNAME or TXT   <value from your provider>

; DMARC: start in monitoring mode
_dmarc.example.com.   TXT   "v=DMARC1; p=none; rua=mailto:dmarc@example.com"

Start DMARC with p=none and read the reports for a few weeks. Move to quarantine, then reject, once everything you send passes. Gmail and Yahoo's sender requirements for bulk senders also expect a working one-click unsubscribe. Mautic adds an unsubscribe link and the List-Unsubscribe header, but check that your template keeps it.

Check it worked: send a test to a Gmail address, open it, choose Show original, and confirm SPF: PASS, DKIM: PASS and DMARC: PASS.

Step 7: Back it up

You need the database and the four volume folders. Step 1 made your own user own /opt/mautic; /var/backups is root:root 0755, so a redirect or tar from that user fails with permission denied. Files under mautic/config are owned by the container's www-data, so run the backup as root:

bash
sudo tee /usr/local/sbin/mautic-backup >/dev/null <<'SH'
#!/bin/sh
set -eu
umask 077
cd /opt/mautic
install -d -m 700 /var/backups/mautic
docker compose exec -T db sh -c 'mariadb-dump -u root -p"$MARIADB_ROOT_PASSWORD" --single-transaction mautic' \
  > /var/backups/mautic/mautic-$(date +%F).sql
tar czf /var/backups/mautic/mautic-files-$(date +%F).tar.gz mautic/
SH
sudo chmod 700 /usr/local/sbin/mautic-backup
sudo /usr/local/sbin/mautic-backup

mautic/config holds local.php, which includes the database password and secret key, so treat the archive as sensitive. Copy both files off the server. The 3-2-1-1-0 guide shows one way.

Check it worked: ls -l /var/backups/mautic shows both files as -rw-------. head the SQL file and see CREATE TABLE statements. Once a quarter, restore both into a test stack.

Step 8: Upgrading

Mautic 7 removed upgrading from the web UI. With Docker, read the release notes, take a backup, change the image tag, then:

bash
docker compose pull
docker compose up -d
docker compose exec -u www-data mautic_web php bin/console doctrine:migrations:migrate --no-interaction

The image may run migrations for you on start. Check the docker-mautic README for your tag, and run the command above if the System Info page reports pending migrations.

Troubleshooting

  • Segments never update: cron isn't running. Check docker compose logs mautic_cron.
  • Emails stuck as pending: the worker isn't running, or the queue setting doesn't match your setup.
  • Test email fails with an authentication error: check the DSN user and password. Some providers need an app password or an API key in place of the account password.
  • Mail lands in spam: check SPF, DKIM and DMARC (step 6), warm up new domains slowly, and only send to people who opted in.
  • Upload or memory errors on imports: import in smaller files, or raise PHP limits in a custom image.

References