Postfix Admin is a PHP-based web front-end that allows us to configure and manage a Postfix email server. You can easily add, remove and manage domains, email users, aliases and disk quotas from your web browser. Postfix Admin supports Virtual Mailboxes, Forwarders, Domain to Domain forwarding, Quota, Backup MX and Mailbox limits per domain. PostfixAdmin comes with a rich set of features including, MySQL/PostgreSQL database support, Web-based administrator panel, Fetchmail support, Roundcube/Squirrelmail integration and many more.
In this tutorial, we will show you how to install and configure Postfix Admin with Nginx on Ubuntu 18.04 server.
Requirements
• A server running Ubuntu 18.04 with postfix installed.
• A valid domain name or sub-domain name is pointed with your server IP address.
• A valid DNS MX record is pointed with your server IP address.
Getting Started
Before starting, it is recommended to update your server’s package repository with the latest version. You can update it with the following command:
# apt-get update -y
# apt-get upgrade -y
Once your system is up-to-date, you can proceed to the next step.
Next, you will need to set up proper hostname of your server. You can do it with the following command:
# hostnamectl set-hostname test.linuxbuz.com
Next, run the following command to apply the changes:
# hostname -f
Install Nginx, PHP and MariaDB
PostfixAdmin runs on a web server, written in the PHP and uses MariaDB to store their data. So you will need to install Nginx, MariaDB, PHP and other modules to your system. You can install all of them by running the following command:
# apt-get install nginx mariadb-server php7.2-fpm php7.2-cli php7.2-imap php7.2-json php7.2-mysql php7.2-opcache php7.2-mbstring php7.2-readline unzip -y
Once all the packages are installed, you can proceed to the next step.
Create a PostfixAdmin Database
Next, you will need to create a database and user for PostfixAdmin. To do so, first login to MariaDB shell with the following command:
# mysql -u root -p
Enter your root password when prompt then create a database and user with the following command:
MariaDB [(none)]> CREATE DATABASE postfixadmin;
MariaDB [(none)]> GRANT ALL ON postfixadmin.* TO 'postfixadmin'@'localhost' IDENTIFIED BY 'admin@123';
Next, flush the privileges and exit from the MariaDB shell with the following command:
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;
Configure PostfixAdmin
First, you will need to download the latest version of PostfixAdmin from Sourceforge website. You can download it with the following command:
# wget -q https://downloads.sourceforge.net/project/postfixadmin/postfixadmin/postfixadmin-3.2/postfixadmin-3.2.tar.gz
After downloading, extract the downloaded file with the following command:
# tar -xvzf postfixadmin-3.2.tar.gz
Next, move the extracted directory to Nginx web root directory:
# mv postfixadmin-3.2 /var/www/html/postfixadmin
Next, change the ownership of postfixadmin directory to www-data:
# chown -R www-data: /var/www/html/postfixadmin/
Next, create a new PostfixAdmin configuration file named config.local.php with the following command:
# nano /var/www/html/postfixadmin/config.local.php
Add the following content:
<?php
$CONF['configured'] = true;
$CONF['database_type'] = 'mysqli';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'postfixadmin';
$CONF['database_password'] = 'admin@123';
$CONF['database_name'] = 'postfixadmin';
$CONF['default_aliases'] = array (
'abuse' => 'abuse@linuxbuz.com',
'hostmaster' => 'hostmaster@linuxbuz.com',
'postmaster' => 'postmaster@linuxbuz.com',
'webmaster' => 'webmaster@linuxbuz.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';
?>
Replace domain name and database settings with your settings. Save and close the file when you are finished. Then, create the schema for the PostfixAdmin database with the following command:
# sudo -u www-data php /var/www/html/postfixadmin/public/upgrade.php
Next, you will need to create a superadmin user using the postfixadmin-cli tool.
You can create it with the following command:
# bash /var/www/html/postfixadmin/scripts/postfixadmin-cli admin add
You will be asked to provide superadmin name, password and domain name. Provide all the information and type y to activate the superadmin as shown below:
Welcome to Postfixadmin-CLI v0.2
---------------------------------------------------------------
Admin:
> superadmin@linuxbuz.com
Password:
> admin@123
Password (again):
> admin@123
Super admin:
(Super admins have access to all domains, can manage domains and admin accounts.) (y/n)
> y
Domain:
> linuxbuz.com
Active: (y/n)
> y
The admin superadmin@linuxbuz.com has been added!
---------------------------------------------------------------
Configure Nginx for PostfixAdmin
Next, you will need to create a new virtual host file for PostfixAdmin. You can create it with the following command:
# nano /etc/nginx/sites-available/test.linuxbuz.com.conf
Add the following lines:
server {
listen 80;
root /var/www/html/postfixadmin/public;
index index.html index.htm index.php;
server_name test.linuxbuz.com;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.2-fpm.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;
}
}
Save and close the file when you are finished. Then, enable the Nginx virtual host with the following command:
# ln -s /etc/nginx/sites-available/test.linuxbuz.com.conf /etc/nginx/sites-enabled/
Finally, restart Nginx and PHP-FPM service to apply the configuration changes:
# systemctl restart nginx
# systemctl restart php7.2-fpm
Access PostfixAdmin Web Interface
Now, open your web browser and type the URL http://test.linuxbuz.com. You will be redirected to the PostfixAdmin web interface as shown below:
Provide your admin username, password and click on the Login button. You should see the PostfixAdmin dashboard in the following screen:
Under domain list menu, click on the Add Domain button to add your domain to PostfixAdmin. You should see the following screen:
Provide your domain name, Mail boxes, Quota and click on the Add Domain button. Once the domain is added, you should see the following screen:
Conclusion
Congratulations! you have successfully installed and configured PostfixAdmin on Ubuntu 18.04 server. You can now easily manage Postfix mail server with PostfixAdmin web interface 🙂