Website Vidya
Linux & ServersStep-by-Step Guide

How to Set Up PostfixAdmin on Ubuntu 24.04

Complete tutorial to set up PostfixAdmin on Ubuntu 24.04 LTS with Nginx, PHP 8.3-FPM, and MariaDB database backend to manage virtual mail domains securely.

RR
Rajesh RayLead Systems Educator
Published:
6 min read
PDF Cheat Sheet
How to Set Up PostfixAdmin on Ubuntu 24.04
AI Executive SummaryWebsiteVidya AI

6 min read

Complete tutorial to set up PostfixAdmin on Ubuntu 24.04 LTS with Nginx, PHP 8.3-FPM, and MariaDB database backend to manage virtual mail domains securely.

Key Highlights
  • Prerequisites and Supported Releases
  • Step 1: Updating System Repositories and Installing LEMP Stack
  • Step 2: Creating and Securing the MariaDB Database
Grounded in full engineering runbookWebsiteVidya AI Engine

Interactive Builder for this Guide

Build your custom nginx syntax (How to Set Up PostfixAdmin on Ubuntu 24.04)

Generated Config Output
server {
    listen 80;
    listen [::]:80;
    server_name app.example.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name app.example.com;

    ssl_certificate /etc/letsencrypt/live/app.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/app.example.com/privkey.pem;

    add_header X-Frame-Options "SAMEORIGIN" always;
    add_header X-Content-Type-Options "nosniff" always;
    add_header Referrer-Policy "strict-origin-when-cross-origin" always;

    gzip on;
    gzip_types text/plain text/css application/json application/javascript application/xml;

    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}
Production Nginx reverse proxy -> 127.0.0.1:3000 for app.example.com.
Flag-by-Flag Breakdown
server_nameBinds this virtual host to app.example.com
return 301 https://...Redirects all plain HTTP requests permanently to TLS/HTTPS
proxy_pass http://127.0.0.1:3000Forwards HTTP + WebSocket requests to local application server
X-Content-Type-Options / X-Frame-OptionsProtects users against MIME sniffing and clickjacking

Managing multi-domain email infrastructure directly through manual flat configuration files like /etc/postfix/virtual_mailbox_domains quickly becomes cumbersome and error-prone as organizations expand. When you set up postfixadmin on ubuntu 24.04, you deploy a mature, battle-tested graphical administration panel that stores domains, mailboxes, aliases, quota rules, and vacation auto-responders inside a relational database backend like MariaDB or PostgreSQL.

Postfix and Dovecot query this centralized relational database in real time to route incoming SMTP traffic, authenticate IMAP/POP3 clients, and enforce storage quotas. PostfixAdmin provides granular access controls, separating full superadministrators from domain-level administrators who manage only their respective sub-organizations.

This technical guide details the complete installation lifecycle on Ubuntu 24.04 LTS. You will configure the LEMP stack (Nginx, MariaDB, and PHP 8.3-FPM), deploy the latest PostfixAdmin release, create localized configuration files, generate secure setup password hashes, and apply security controls to lock down administrative access.

Advertisement

Prerequisites and Supported Releases

This guide is thoroughly verified on Ubuntu 24.04 LTS (Noble Numbat) & Ubuntu 22.04 LTS. The instructions apply cleanly to cloud instances (AWS EC2, Google Compute Engine, DigitalOcean, Hetzner), bare-metal servers, and local virtual machines.

Before proceeding, ensure you have the following requirements satisfied:

  • A server running Ubuntu 24.04 LTS with at least 1 GB RAM and 10 GB disk space.
  • A non-root user account with active sudo administrative privileges.
  • A fully qualified domain name (FQDN) like mailadmin.example.com with DNS A record pointing to your server IP.
  • An active Internet connection for installing repository packages.

Step 1: Updating System Repositories and Installing LEMP Stack

PostfixAdmin is a PHP application that requires a web server and a relational database. Ubuntu 24.04 LTS provides PHP 8.3, Nginx, and MariaDB in its default upstream universe repositories.

First, refresh your APT package lists and install Nginx, MariaDB Server, PHP 8.3-FPM, and all necessary PHP extensions required for database connectivity, internationalized domain handling, IMAP mailbox management, and string operations.

Advertisement
# Refresh package repository metadata
sudo apt update && sudo apt upgrade -y

# Install Nginx, MariaDB server, and PHP 8.3 runtime stack
sudo apt install -y nginx mariadb-server php8.3-fpm php8.3-mysql php8.3-curl \
  php8.3-intl php8.3-mbstring php8.3-imap php8.3-xml php8.3-zip tar wget curl

Step 2: Creating and Securing the MariaDB Database

Initialize MariaDB security settings using mariadb-secure-installation to disable remote root logins, remove anonymous accounts, and eliminate the test database. Then, log into the MariaDB shell to provision a dedicated database and database user for PostfixAdmin.

Assign a strong, randomized password and grant full administrative privileges exclusively on the postfixadmin database.

# Secure the default MariaDB installation
sudo mariadb-secure-installation

# Log into MariaDB administrative console
sudo mariadb -u root -p

Step 3: Provisioning Database Schema Privileges

Execute the following SQL statements within the MariaDB interactive prompt to create the database and user account. Replace StrongPostfixAdminPassword123! with a high-entropy secret.

Flush the privilege cache and exit the database prompt.

Advertisement
-- Create dedicated database with UTF-8 character encoding
CREATE DATABASE postfixadmin CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- Create dedicated database user
CREATE USER 'postfixadmin'@'localhost' IDENTIFIED BY 'StrongPostfixAdminPassword123!';

-- Grant required permissions on postfixadmin database
GRANT ALL PRIVILEGES ON postfixadmin.* TO 'postfixadmin'@'localhost';

-- Apply privilege tables
FLUSH PRIVILEGES;
EXIT;

Step 4: Downloading and Installing PostfixAdmin

Download the latest stable release tarball directly from the official PostfixAdmin GitHub repository. Extract the archive into your web root directory at /var/www/postfixadmin.

Ensure that web assets reside cleanly in the target directory and remove temporary downloaded archives.

# Fetch the latest release tarball
cd /tmp
wget https://github.com/postfixadmin/postfixadmin/archive/refs/tags/postfixadmin-3.3.13.tar.gz

# Extract contents into /var/www/
sudo tar -zxvf postfixadmin-3.3.13.tar.gz -C /var/www/

# Rename the extracted folder to a standardized directory name
sudo mv /var/www/postfixadmin-postfixadmin-3.3.13 /var/www/postfixadmin

# Clean up archive
rm -f postfixadmin-3.3.13.tar.gz

Step 5: Configuring PostfixAdmin via config.local.php

PostfixAdmin includes a base configuration file config.inc.php. Never edit config.inc.php directly; instead, create a localized override file named config.local.php in the /var/www/postfixadmin/ directory. This ensures your customized settings survive future software upgrades.

Configure the database parameters and setup password hash within /var/www/postfixadmin/config.local.php using your favorite text editor.

# Create and edit config.local.php
sudo nano /var/www/postfixadmin/config.local.php

Step 6: Setting Up Configuration Directives and File Permissions

Paste the following PHP configuration code into /var/www/postfixadmin/config.local.php, updating the database password to match the MariaDB user configured in Step 3.

PostfixAdmin also requires a compiled template cache directory templates_c. Create this directory and grant ownership of the entire PostfixAdmin tree to the www-data web server user.

<?php
// PostfixAdmin Local Overrides for Ubuntu 24.04
$CONF['configured'] = true;
$CONF['setup_password'] = 'changeme_after_setup_hash';

// Database connection parameters
$CONF['database_type'] = 'mysqli';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'postfixadmin';
$CONF['database_password'] = 'StrongPostfixAdminPassword123!';
$CONF['database_name'] = 'postfixadmin';

// Mailbox configuration defaults
$CONF['default_aliases'] = array (
    'abuse' => '[email protected]',
    'hostmaster' => '[email protected]',
    'postmaster' => '[email protected]',
    'webmaster' => '[email protected]'
);

$CONF['page_size'] = '20';
$CONF['theme'] = 'default';
?>

Step 7: Creating Template Cache and Setting Directory Permissions

Configure the Smarty template engine cache directory and restrict filesystem permissions so only the www-data user can read and execute files.

Run the following permission commands in your terminal:

# Create Smarty template cache directory
sudo mkdir -p /var/www/postfixadmin/templates_c

# Set ownership to web server user and group
sudo chown -R www-data:www-data /var/www/postfixadmin

# Set secure directory permissions
sudo chmod -R 755 /var/www/postfixadmin
sudo chmod -R 775 /var/www/postfixadmin/templates_c

Step 8: Configuring Nginx Server Block for PostfixAdmin

Create a dedicated Nginx virtual host configuration file at /etc/nginx/sites-available/postfixadmin. Note that on Ubuntu 24.04, the PHP-FPM UNIX domain socket is located at /run/php/php8.3-fpm.sock.

Write the server block configuration pointing to /var/www/postfixadmin/public as the document root.

server {
    listen 80;
    listen [::]:80;
    server_name mailadmin.example.com;

    root /var/www/postfixadmin/public;
    index index.php index.html;

    access_log /var/log/nginx/postfixadmin_access.log;
    error_log /var/log/nginx/postfixadmin_error.log;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.3-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

Step 9: Enabling Site and Validating Nginx Configuration

Enable the newly created virtual host by creating a symbolic link in /etc/nginx/sites-enabled/. Test the Nginx syntax for configuration errors before reloading the daemon.

Once syntax validation succeeds, reload Nginx to apply changes.

# Enable the Nginx site configuration
sudo ln -s /etc/nginx/sites-available/postfixadmin /etc/nginx/sites-enabled/

# Validate Nginx syntax
sudo nginx -t

# Reload Nginx daemon
sudo systemctl reload nginx

Step 10: Initializing Database Schema and Superadmin Account

Open your web browser and navigate to http://mailadmin.example.com/setup.php. The PostfixAdmin setup wizard performs automated pre-flight checks, creates all database tables, and prompts you to specify a Setup Password.

Enter your desired master setup password and click Generate password hash. The page generates a hashed string (e.g., $2y$10$...). Copy this hash, open /var/www/postfixadmin/config.local.php, and paste it into $CONF['setup_password'].

Refresh setup.php, enter your newly hashed setup password in the form, and create your primary Superadmin email address and administrator password. Once created, log into the dashboard at http://mailadmin.example.com/login.php.

Troubleshooting and Common Errors

When configuring Ubuntu servers, unexpected permission errors, network timeouts, or lock contention can occur. Review these common issues and verified resolutions:

Database connection failed or 'Table postfixadmin.config does not exist'

Resolution: Verify MariaDB credentials in /var/www/postfixadmin/config.local.php. Test manual database connectivity via mysql -u postfixadmin -p postfixadmin. Ensure you visit http://mailadmin.example.com/setup.php to trigger automatic table creation.

502 Bad Gateway error when accessing PostfixAdmin in browser

Resolution: Check the status of PHP-FPM service using sudo systemctl status php8.3-fpm. Verify that the FastCGI pass path in your Nginx configuration points to /run/php/php8.3-fpm.sock.

Smarty error: unable to write file /var/www/postfixadmin/templates_c

Resolution: Ensure the templates_c directory exists and has write permissions for the web server user: sudo chown -R www-data:www-data /var/www/postfixadmin/templates_c && sudo chmod -R 775 /var/www/postfixadmin/templates_c.

Security Best Practices and Hardening

Always restrict public access to /setup.php by disabling it or blocking it in Nginx (location = /setup.php { deny all; }) once initial superadmin setup is complete.

Deploy SSL/TLS certificates via Let's Encrypt Certbot (sudo certbot --nginx -d mailadmin.example.com) to encrypt administrative login credentials over public networks.

Store database credentials with restricted read permissions (0640 owned by www-data:www-data) on /var/www/postfixadmin/config.local.php.

Limit administrative access to PostfixAdmin using IP whitelisting or VPN tunnels to protect mail administration portals from brute-force attacks.

Deepen your Linux system administration skills with our related production-tested guides:

Authoritative References and Official Documentation

Frequently Asked Questions

Quick answers to common questions and configurations

3 FAQs
No. PostfixAdmin is purely a management interface. The actual mail handling is performed by Postfix (MTA), Dovecot (MDA/IMAP), and SpamAssassin/Rspamd.
Yes. PostfixAdmin fully supports PostgreSQL. You simply configure $CONF['database_type'] = 'pgsql' and install php8.3-pgsql.
Install Certbot (sudo apt install certbot python3-certbot-nginx) and run sudo certbot --nginx -d mailadmin.example.com to provision an automated Let's Encrypt TLS certificate.
RR
Written byVerified Author

Rajesh Ray

I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.

SPAM-FREE MODERATED DISCOURSE

Join the Conversation & Perspective

Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.

AT
MP
JV
+2

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

Featured Infrastructure PartnerUp to 75% OFF + 3 Months Free

Supercharge Your Linux & Cloud Workloads with Hostinger

Deploy high-speed NVMe KVM VPS, Docker containers, and LiteSpeed-accelerated WordPress servers in under 60 seconds with full root access, dedicated IPv4, and 24/7 technical support.

Pure NVMe SSD StorageFull Root Access & SSHFree Domain & Unlimited SSL99.9% Uptime SLA
Plans from$2.99/mo
Claim Hostinger DealAffiliate link • Special discount applied at checkout