As I explained in [this previous tutorial](https://www.captainark.net/setting-up-a-mail-server.html), I've been running my own mail server without any issue for some time now.
However, every time I've wanted to add a domain, create a new mailbox or change a user's password, I've had to do it manually from a SQL shell. As fun as it may be, it does get old very fast, so I've decided to install a web frontend to manage this database.
After a bit a googling, I've settled on [Postfix Admin](http://postfixadmin.sourceforge.net/).
The latest stable version of Postfix Admin was released in 2009. Version 3.0 has been in the works for some time now and the project can be cloned from their [Github repo](https://github.com/postfixadmin/postfixadmin).
I've also tried [ViMbAdmin](http://www.vimbadmin.net/), but it felt a little heavy considering what I was going to use it for.
You'll need a web server with PHP support to run Postfix Admin. I personnaly run nginx with php5-fpm, but I won't explain how to configure it here. I'll simply explain how to migrate your current database to one managed with Postfix Admin with as little downtime as possible.
# Creating a new database
Since the database managed by Postfix Admin does not use the same schema as the one we've created in my previous tutorial, we'll have to create a new one. We will give all privileges on that database to the same user as before, `'mail'@'localhost'`.
```sql
CREATE DATABASE mailnew;
GRANT SELECT ON mailnew.* TO 'mail'@'localhost';
FLUSH PRIVILEGES;
```
At this point, you can clone the Postfix Admin project from Github and go through the installation process.
While editing the config.inc.php file (or config.local.php file if you've decided to copy it), make sure that the `database_name` option is set to use the `mailnew` database we've just created.
Also, make sure that the `encrypt` option is set to `dovecot:SHA512-CRYPT`.
The installation process will create all the necessary tables in the database.
**At this point, you'll have to recreate all domains, mailboxes and aliases that you have configured in your current mail database using the Postfix Admin interface.**
# Postfix configuration
Once you're done with Postfix Admin, it's time to configure Postfix to use its schema.
First thing first, let's backup our current configuration :
```
mkdir /etc/postfix/mysql-backup
cp -a /etc/postfix/mysql-virtual* /etc/postfix/mysql-backup/
At this point, Postfix and Dovecot are using the Postfix Admin schema in the mail database.
The last thing we have to do is to edit Postfix Admin's config.inc.php file to use the mail database as well instead of the mailnew database that it should be currently using.
# Cleanup
Once you've confirmed that everything is working properly, you can delete the backup files we've created :
```bash
rm -rf /etc/postfix/mysql-backup
rm /etc/dovecot/sql.conf.bak
```
You can drop the mailnew database as well :
```sql
DROP DATABASE mailnew;
```
# Conclusion
That's all ! As always, please do leave a comment if this article has been of any use to you !