PostfixAdmin is the long-running PHP admin UI for Postfix + Dovecot virtual-domain deployments. This article is the install we run when a client has more than one domain on a single Postfix and doesn’t want a docker-bundled stack like mailcow-self-hosted-stack — a MariaDB-backed schema, virtual domains and mailboxes managed via a web UI, and Postfix + Dovecot pulling identities from SQL.
How to verify
Before installing, check what is already wired.
dpkg -l | grep -E 'postfixadmin|postfix-mysql|dovecot-mysql|mariadb'
sudo postconf | grep -E 'virtual_mailbox|virtual_alias|virtual_transport'
sudo doveconf -n | grep -E 'auth|driver'
ss -ltnp | grep -E ':(3306|443)\b'
A Postfix that already has virtual_mailbox_domains set as a flat file does not interoperate cleanly with the SQL schema PostfixAdmin needs — plan the migration.
What’s happening
PostfixAdmin owns a relational schema with tables for admin, alias, alias_domain, domain, mailbox, vacation, and log. The admin UI is PHP; the backend is MariaDB/MySQL/PostgreSQL. The trick is that Postfix and Dovecot also speak to the same SQL backend — Postfix via mysql: lookup tables for virtual_alias_maps, virtual_mailbox_maps, etc., and Dovecot via the SQL passdb/userdb drivers.
The data flow per inbound message:
- Postfix receives
RCPT TO: alice@example.com. virtual_mailbox_maps = mysql:/etc/postfix/sql/virtual-mailbox.cfqueries themailboxtable forusername='alice@example.com'.- If the row exists, Postfix accepts; routes to
virtual_transport = lmtp:unix:private/dovecot-lmtp. - Dovecot’s LMTP receives, looks up the user via the SQL userdb, and stores the message under the right Maildir path.
The admin UI lets a tenant administrator create mailboxes, aliases, and quotas without touching /etc/. The whole config-as-data pattern is what makes PostfixAdmin worth the install on multi-domain boxes.
The procedure
-
Install MariaDB and the SQL-aware mail packages:
sudo apt update sudo apt install -y mariadb-server postfix-mysql dovecot-mysql postfixadminThe
postfixadminDebian package drops PHP files under/usr/share/postfixadmin/. You’ll point a webserver vhost at it. -
Create the database and user:
sudo mariadb <<SQL CREATE DATABASE postfix CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; CREATE USER 'postfix'@'localhost' IDENTIFIED BY 'pa-db-pw'; CREATE USER 'postfixadmin'@'localhost' IDENTIFIED BY 'pa-admin-pw'; GRANT SELECT ON postfix.* TO 'postfix'@'localhost'; GRANT ALL PRIVILEGES ON postfix.* TO 'postfixadmin'@'localhost'; FLUSH PRIVILEGES; SQLTwo users — the
postfixuser has read-only for the daemons; thepostfixadminuser has write for the admin UI. Least privilege. -
Configure PostfixAdmin. Edit
/etc/postfixadmin/config.local.php:<?php $CONF['configured'] = true; $CONF['database_type'] = 'mysqli'; $CONF['database_host'] = 'localhost'; $CONF['database_user'] = 'postfixadmin'; $CONF['database_password'] = 'pa-admin-pw'; $CONF['database_name'] = 'postfix'; $CONF['encrypt'] = 'dovecot:ARGON2ID'; $CONF['default_aliases'] = ['abuse' => 'postmaster', 'hostmaster' => 'postmaster', 'webmaster' => 'postmaster']; $CONF['domain_path'] = 'YES'; $CONF['domain_in_mailbox'] = 'YES'; $CONF['maildir_format'] = 'maildir';The
dovecot:ARGON2IDencryption scheme means PostfixAdmin will hash passwords using Dovecot’sdoveadm pwhelper — the same hash Dovecot validates against. -
Initialize the schema via the setup page. Browse to
https://mail.example.com/postfixadmin/setup.php. The page runs the migrations and prompts for a setup password and the first super-admin user. Once setup finishes, deletesetup.phpor rename it — leaving it accessible is an attack surface. -
Configure Postfix to read from SQL. Create
/etc/postfix/sql/:sudo mkdir -p /etc/postfix/sql sudo chmod 750 /etc/postfix/sqlThen write three lookup configs:
/etc/postfix/sql/virtual-mailbox-domains.cf:user = postfix password = pa-db-pw hosts = 127.0.0.1 dbname = postfix query = SELECT domain FROM domain WHERE domain='%s' AND active='1'/etc/postfix/sql/virtual-mailbox.cf:user = postfix password = pa-db-pw hosts = 127.0.0.1 dbname = postfix query = SELECT maildir FROM mailbox WHERE username='%s' AND active='1'/etc/postfix/sql/virtual-alias.cf:user = postfix password = pa-db-pw hosts = 127.0.0.1 dbname = postfix query = SELECT goto FROM alias WHERE address='%s' AND active='1'Then in
/etc/postfix/main.cf:virtual_mailbox_domains = mysql:/etc/postfix/sql/virtual-mailbox-domains.cf virtual_mailbox_maps = mysql:/etc/postfix/sql/virtual-mailbox.cf virtual_alias_maps = mysql:/etc/postfix/sql/virtual-alias.cf virtual_mailbox_base = /var/vmail virtual_minimum_uid = 5000 virtual_uid_maps = static:5000 virtual_gid_maps = static:5000 virtual_transport = lmtp:unix:private/dovecot-lmtpLock down permissions on the SQL files:
sudo chown root:postfix /etc/postfix/sql/*.cf sudo chmod 640 /etc/postfix/sql/*.cf -
Configure Dovecot to read from SQL. Edit
/etc/dovecot/conf.d/auth-sql.conf.extand the main10-auth.confto include it:passdb { driver = sql args = /etc/dovecot/dovecot-sql.conf.ext } userdb { driver = sql args = /etc/dovecot/dovecot-sql.conf.ext }Then
/etc/dovecot/dovecot-sql.conf.ext:driver = mysql connect = host=127.0.0.1 dbname=postfix user=postfix password=pa-db-pw default_pass_scheme = ARGON2ID password_query = SELECT username AS user, password, '/var/vmail/%d/%n' AS userdb_home, 5000 AS userdb_uid, 5000 AS userdb_gid FROM mailbox WHERE username='%u' AND active='1' user_query = SELECT '/var/vmail/%d/%n' AS home, 5000 AS uid, 5000 AS gid FROM mailbox WHERE username='%u' AND active='1' -
Reload, verify, add a domain through the UI. Reload Postfix and Dovecot:
sudo postfix check && sudo systemctl reload postfix sudo systemctl reload dovecotBrowse to
/postfixadmin/, log in, Domain List → New Domain, fill inexample.com. Then Virtual List → New Mailbox, createalice@example.com. Send a test message; confirm it lands in/var/vmail/example.com/alice/Maildir/new/.
Common pitfalls
- The Dovecot SQL passdb returns rows with the password column missing or wrong-cased —
default_pass_schemeis set but the column is empty; check themailbox.passwordfield after a UI create. - Postfix logs
warning: dict_mysql:/etc/postfix/sql/virtual-mailbox.cf: table lookup failurebecause thepostfixMySQL user wasn’t grantedSELECTon the right tables —SHOW GRANTS FOR 'postfix'@'localhost';is the diagnostic. setup.phpis left in the webroot — an attacker can re-run the install wizard against a live DB; delete or 403-protect it.- The
virtual_minimum_uid = 5000andvirtual_uid_maps = static:5000match thevmailuser from a manual install; PostfixAdmin uses these UIDs by default, but if you previously used a different UID, the Maildir tree won’t be readable. - The SQL files in
/etc/postfix/sql/are world-readable on a default install — they contain the DB password;chmod 640 root:postfixis the fix.
Stack Harbor stands up PostfixAdmin as the admin layer for multi-tenant Postfix in the engagements we run — SQL schema initialized from version-controlled DDL, Postfix and Dovecot pointed at it, the UI behind authenticated Nginx with setup.php removed before handing the box back. If you have a Postfix that has grown to a dozen virtual domains all in flat files, that consolidation work is part of our Managed Operations practice.