We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

Learn how to – Configure Mail Server with PostfixAdmin on CentOS 7|8

Learn how to – Configure Mail Server with PostfixAdmin on CentOS 7|8.

PostfixAdmin is a web-based interface based on PHP that allows users to manage their electronic mails. It is a popular mail server nowadays because it makes it easy to manage your postfix service, domains, mail aliases, adding and removing mail users, disk quotas e.t.c through a web interface.

PostfixAdmin is a free and open-source software licensed under the GNU General Public License as published by the Free Software Foundation.

Features of PostfixAdmin

PostfixAdmin is highly preferred due to the following amazing features:

  • It supports fetchmail integration.
  • It has the Squirrelmail plugin
  • It allows users to manage their own mailbox (change alias, password and vacation message).
  • It makes it easy to manage mailboxes, virtual domains and aliases
  • Allows one to receive vacation/out-of-office messages through the web interface.
  • It has a commandline client postfixadmin-cli for those who don’t want to click around in a web interface.
  • It displays used quota

In this guide, we will systematically go through how to configure a Mail Server with PostfixAdmin on CentOS 7|CentOS 8.

Getting Started.

For this guide, you will require the following:

  1. CentOS 7/8 installed on your machine.
  2. a user with sudo privileges

Then ensure that your system is up-to-date and the required packages installed

sudo yum -y update
sudo yum install vim wget

Step 1 – Install LEMP Stack

A LEMP server stands for Linux, Nginx, MariaDB, and PHP, which can all be installed on CentOS 7| 8 using the below command.

First, add the EPEL repository to your system.

sudo yum install epel-release

Install Nginx PHP and MariaDB on CentOS 7| 8.

sudo yum install nginx mariadb-server mariadb php php-mysqlnd php-fpm php-opcache php-cli php-gd php-curl

Since PHP runs by default using the user apache, we will change to Nginx as below.

sudo vim /etc/php-fpm.d/www.conf

Edit the file as below.

user = nginx
group = nginx
listen = /run/php-fpm/www.sock
listen.owner = nginx
listen.group = nginx

Now assign the correct permissions to /var/lib/php directory as below.

sudo chown -R nginx:nginx /var/lib/php

Restart and enable PHP FPM to run on boot.

sudo systemctl enable php-fpm
sudo systemctl start php-fpm

Start and enable the Nginx web server.

sudo systemctl enable nginx
sudo systemctl start nginx

Step 2 – Configure MariaDB for PostfixAdmin

After the installation of MariaDB, it is still not secure. We are therefore required to harden it by setting the root password as below.

First, start and enable MariaDB.

sudo systemctl enable --now mariadb.service

Then proceed to harden it.

sudo mysql_secure_installation

Proceed as below.

Enter current password for root (enter for none): Press Enter
Set root password? [Y/n] y
New password: Enter Password
Re-enter new password: Re-Enter Password
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y
Thanks for using MariaDB!

Login to the MariaDB shell and create a Postfix user and database.

mysql -u root -p

Enter the set password and proceed as below.

CREATE DATABASE postfixadmin;
GRANT ALL PRIVILEGES ON postfixadmin.* TO 'postfixadmin'@'%' IDENTIFIED BY 'StrongDBPassw0rd';

Step 3 – Install PostfixAdmin

We will download the latest version of PostfixAdmin from the official PostfixAdmin download page. You can also use Wget to pull the archive as below.

wget https://sourceforge.net/projects/postfixadmin/files/postfixadmin-3.3.8/PostfixAdmin%203.3.8.tar.gz -O PostfixAdmin-tar.gz

Extract the downloaded file.

tar -xvf PostfixAdmin-tar.gz

Now move the extracted file to the /var/www/html/ directory.

sudo mv postfixadmin-postfixadmin-* /var/www/html/postfixadmin

Create a directory for PostfixAdmin installation.

sudo mkdir /var/www/html/postfixadmin/templates_c

Change the ownership of the directory to Nginx as below.

sudo chown -R nginx:nginx /var/www/html/postfixadmin/

Now create the mail configuration file and make the below adjustments.

sudo vim /var/www/html/postfixadmin/config.local.php

Edit the file as below.

$CONF['configured'] = true;
$CONF['database_type'] = 'mysqli';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'postfixadmin';
$CONF['database_password'] = 'StrongDBPassw0rd';
$CONF['database_name'] = 'postfixadmin';

$CONF['default_aliases'] = array (
 'abuse' => 'abuse@example.com',
 'hostmaster' => 'hostmaster@example.com',
 'postmaster' => 'postmaster@example.com',
 'webmaster' => 'webmaster@example.com'
$CONF['fetchmail'] = 'NO';
$CONF['show_footer_text'] = 'NO';
$CONF['quota'] = 'YES';
$CONF['domain_quota'] = 'YES';
$CONF['quota_multiplier'] = '1024000';
$CONF['used_quotas'] = 'YES';
$CONF['new_quota_table'] = 'YES';
$CONF['aliases'] = '0';
$CONF['mailboxes'] = '0';
$CONF['maxquota'] = '0';
$CONF['domain_quota_default'] = '0';

Create the schema for the PostfixAdmin database.

sudo -u nginx php /var/www/html/postfixadmin/public/upgrade.php

Sample Output:

<p>updating to version 1 (MySQL)...
 &nbsp; done
<p>updating to version 2 (MySQL)...
 &nbsp; done
<p>updating to version 3 (MySQL)...
 &nbsp; done
<p>updating to version 4 (MySQL)...
 &nbsp; done
<p>updating to version 5 (MySQL)...
 &nbsp; done
<p>updating to version 79 (MySQL)...
 &nbsp; done
<p>updating to version 81 (MySQL)...
<p>updating to version 1839 (all databases)...
 &nbsp; done
<p>updating to version 1840 (MySQL and PgSQL)...
 &nbsp; done
<p>updating to version 1842 (all databases)...
 &nbsp; done
<p>updating to version 1843 (all databases)...
 &nbsp; done

Create a super admin account for PostfixAdmin using the command.

sudo bash /var/www/html/postfixadmin/scripts/postfixadmin-cli admin add

Sample Output:

Welcome to Postfixadmin-CLI v0.3

> admin@example.com

> Passw0rd12

Password (again):  
> Passw0rd12

Super admin:
(Super admins have access to all domains, can manage domains and admin accounts.) (y/n) 
> y

> example.com

Active: (y/n) 
> y

The admin admin@example.com has been added!


Step 4 – Configure Nginx for PostfixAdmin

Next, we will create a virtual host file for PostfixAdmin.

sudo vim /etc/nginx/conf.d/postfixadmin.conf

In the file, add the below lines, replacing appropriately, if you do not have an FQDN, replace mail.example.com with your valid domain or subdomain for PostfixAdmin.

server {
        listen 80;
        root /var/www/html/postfixadmin/public;
        index index.html index.htm index.php;
        server_name mail.example.com;

        location ~ .php$ {
          fastcgi_split_path_info ^(.+.php)(/.+)$;
          fastcgi_pass unix:/var/run/php-fpm/www.sock;
          fastcgi_index index.php;
          include fastcgi_params;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          fastcgi_intercept_errors off;
          fastcgi_buffer_size 16k;
          fastcgi_buffers 4 16k;
          fastcgi_connect_timeout 600;
          fastcgi_send_timeout 600;
          fastcgi_read_timeout 600;

   location / {
       try_files $uri $uri/ =404;



  • mail.example.com is the name of subdomain configured for PostfixAdmin

Validate nginx configurations syntax:

$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Restart Nginx.

sudo systemctl restart nginx

Check the status of the service.

$ systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
  Drop-In: /usr/lib/systemd/system/nginx.service.d
   Active: active (running) since Thu 2021-10-21 07:33:09 EDT; 8s ago
  Process: 26634 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 26631 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 26629 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 26636 (nginx)
    Tasks: 2 (limit: 14608)
   Memory: 4.0M
   CGroup: /system.slice/nginx.service
           ├─26636 nginx: master process /usr/sbin/nginx
           └─26637 nginx: worker process

Oct 21 07:33:09 mail.example.com systemd[1]: Stopped The nginx HTTP and reverse proxy server.
Oct 21 07:33:09 mail.example.com systemd[1]: Starting The nginx HTTP and reverse proxy server...
Oct 21 07:33:09 mail.example.com nginx[26631]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Oct 21 07:33:09 mail.example.com nginx[26631]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Oct 21 07:33:09 mail.example.com systemd[1]: nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argument
Oct 21 07:33:09 mail.example.com systemd[1]: Started The nginx HTTP and reverse proxy server.

Allow HTTP service through the firewall.

sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --reload

Set SELinux in Permissive mode.

sudo setenforce 0
sudo sed -i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/selinux/config

Step 5 – Access PostfixAdmin Web Interface

Now that everything has been configured accordingly, access the PostfixAdmin web interface on your preferred browser using the URL http://mail.example.com. You will be granted this login window.

Login using the credentials for the super admin account as below.

On successful login, you should see this PostfixAdmin dashboard.

From this dashboard, there is a couple of activities you can perform such as Adding alias, adding mailboxes, sending mails e.t.c.

The first activity we will perform is adding a domain. This is done by clicking on Domain List then New Domain as below.

Enter your valid domain name then click add domain when done. On the domain list, your new domain should appear as shown.

Under the Virtual list, you can add alias, mailboxes and alias domains. Add a mailbox as below.

There is an option of sending emails using PostfixAdmin.

Lastly, check logs in PostfixAdmin by clicking on view log on the far right and view activities as below.

Step 6 – Install Postfix on CentOS 8|7

With the mail server set up, we might be interested in installing Postfix which is a free and open-source mail transfer agent (MTA) that routes and delivers electronic mail from one server to another over the internet.

Postfix can be used to handle the sending and delivery of emails from our mail server. Since it is available in the default CentOS repositories, install it with the command.

sudo yum install postfix

Edit the postfix configuration file.

sudo vi /etc/postfix/main.cf

In the file, add your hostname and domain as below.

##Add your hostname
myhostname = smtp.example.com
##Uncomment the lines below
mydomain = example.com
myorigin = $mydomain

##Edit the lines below(to all)
inet_interfaces = all
inet_protocols = all
#Comment the line as below
# mydestination = $myhostname, localhost.$mydomain, localhost,

##Add your IP range.
mynetworks =,
##Uncomment the line below.
home_mailbox = Maildir/

In the file, replace example.com with your domain name, w2ith your IP range.

Restart and enable Postfix.

sudo systemctl restart postfix
sudo systemctl enable postfix

Allow the required Postfix ports through the firewall.

sudo firewall-cmd --permanent --add-port=25/tcp
sudo  firewall-cmd --permanent --add-port=587/tcp
sudo  firewall-cmd --reload

Now you can send and receive emails from your setup mail server using Postfix. Test Postfix using the command.

mail -s “Local Outbound SMTP Test” test@example.com < /dev/null

That is it for now! I hope you enjoyed this guide on how to configure Mail Server with PostfixAdmin on CentOS 7|CentOS 8. In case you find any trouble while configuring PostfixAdmin, let us know.

Interested in more?


Your Cart is Empty

Back To Shop