Install and Configure Postfix, PostfixAdmin, RoundCubeMail and Dovecot with mysql backend




Install and Configure PostfixAdmin



It is needed to install httpd,mysql and php for PostfixAdmin.

# yum install mysql-server php php-mysql php-imap php-mbstring -y

Once all the above packages were installed, make sure httpd and mysqld services are running.

It is needed to create db, db user for PostfixAdmin. Here i am using the following db details. Change the following details as you prefered.

DB: postfix
DB User: postfix
Password: postfix

The following command will create the DB for postfix. You can also execute these queries directly in the mysql console.

# mysql -e "CREATE DATABASE postfix;"
# mysql -e "CREATE USER postfix@localhost IDENTIFIED BY 'postfix';"
# mysql -e "GRANT ALL PRIVILEGES ON postfix.* TO postfix;"



To download and fix permissions of PostfixAdmin.

# yum install -y subversion
# cd /usr/local/

The following command will download latest PostfixAdmin package. The 'svn' command is available in the package 'subversion' which we have already installed.

# svn co http://svn.code.sf.net/p/postfixadmin/code/trunk postfixadmin
# chmod 777 /usr/local/postfixadmin/templates_c

Edit the postfixadmin configuration file, /usr/local/postfixadmin/config.inc.php and update the following lines as shown below.

 $CONF['configured'] = true;
 $CONF['postfix_admin_url'] = '/postfixadmin';
 $CONF['database_type'] = 'mysqli';
 $CONF['database_host'] = 'localhost';
 $CONF['database_user'] = 'postfix';
 $CONF['database_password'] = 'postfix';
 $CONF['database_name'] = 'postfix';
 $CONF['domain_path'] = 'YES';
 $CONF['domain_in_mailbox'] = 'NO';
 $CONF['encrypt'] = 'cleartext';
 $CONF['emailcheck_resolve_domain] = 'NO';


Once you have done the above changes, you have to create the following entry in httpd.conf to access postfixadmin via browser.

Alias /postfixadmin /usr/local/postfixadmin


Restart httpd service

# /etc/init.d/httpd restart


Now you can access postfixadmin using the following url. Setup the postfixadmin as per the given instructon in there.

http://<IP>/postfixadmin/setup.php

Once the setup is completed successsfully, it is time to install and configure postfix service.


Install and Configure Postfix


There will be a postfix package initiallly in the default installation. Here i am removing it and i am using Postfix-2.9.7. Depending upon the version and architecture, select the postfix version from http://packages.oostergo.net/

To download and install postfix
# rpm -Uvh http://packages.oostergo.net/postfix-2.9/el6/postfix-2.9.7-1.el6.x86_64.rpm

The following commands will made the changes in /etc/postfix/main.cf. We have to setup it initially.

To set postfix's hostname.
# postconf -e "myhostname = mail.sudosu.in"
# postconf -e "mydomain = sudosu.in"

# postconf -e "myorigin = "'$'"mydomain"

inet_interfaces initially set for listening from localhost only. We need to change it to listen on all interfaces.
# postconf -e "inet_interfaces = all"

# postconf -e "inet_protocols = ipv4"

# postconf -e "home_mailbox = Maildir/"

# postconf -e "smtpd_banner = "'$'"myhostname ESMTP"

To limit an email size 10M
# postconf -e "message_size_limit = 10485760"

To limit mailbox 1G
# postconf -e "mailbox_size_limit = 1073741824"

# postconf -e "mydestination = "'$'"myhostname, localhost."'$'"mydomain, localhost"



Create a user 'vmail' for creating virtual users(mail boxes)
# groupadd -g 5000 vmail
# useradd -g vmail -u 5000 vmail -d /home/vmail -m


It is needed to create some configuration files to map the domains and mailboxs from mysql. Here are those configuration files.

# cat /etc/postfix/mysql-domains.cf
hosts = localhost
user = postfix
password = postfix
dbname = postfix
table = domain
select_field = domain
where_field = domain
additional_conditions = and backupmx = '0' and active = '1'

# cat /etc/postfix/mysql-users.cf
hosts = localhost
user = postfix
password = postfix
dbname = postfix
table = mailbox
select_field = maildir
where_field = username
additional_conditions = and active = '1'
result_format = %sMaildir/

# cat /etc/postfix/mysql-aliases.cf
hosts = localhost
user = postfix
password = postfix
dbname = postfix
table = alias
select_field = goto
where_field = address
additional_conditions = and active = '1'


The above configuration files and 'vmail' user need to map with postfix.

# postconf -e "virtual_mailbox_domains = mysql:/etc/postfix/mysql-domains.cf"
# postconf -e "virtual_mailbox_maps = mysql:/etc/postfix/mysql-users.cf"
# postconf -e "virtual_alias_maps = mysql:/etc/postfix/mysql-aliases.cf"
# postconf -e "virtual_mailbox_base = /home/vmail"
# postconf -e "virtual_uid_maps = static:5000"
# postconf -e "virtual_gid_maps = static:5000"

Restart or reload postfix

# postfix reload

or

# /etc/init.d/postfix restart


Install and Configure Dovecot


# yum install dovecot dovecot-mysql -y

Check if postfix support dovecot authentication. Check if dovecot is listed in the result.

# postconf -a
cyrus
dovecot

Postfix configuration for Dovecot SMTP-Auth settings

# postconf -e "smtpd_sasl_local_domain = $myhostname"
# postconf -e "smtpd_sasl_auth_enable = yes"
# postconf -e "broken_sasl_auth_clients = yes"
# postconf -e "smtpd_sasl_type = dovecot"
# postconf -e "smtpd_sasl_path = private/auth"
# postconf -e "smtpd_sasl_security_options = noanonymous"
# postconf -e "smtpd_sender_restrictions = permit_mynetworks, permit_sasl_authenticated,  reject_unauth_destination, permit"
# postconf -e "smtpd_recipient_restrictions =  permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination"


Create dovecot-mysql.conf file as follows.

[root@server ~]# cat /etc/dovecot/dovecot-mysql.conf
driver = mysql
connect = host=localhost dbname=postfix user=postfix password=postfix
default_pass_scheme = PLAIN
password_query = SELECT password FROM mailbox WHERE username = '%u' AND active = '1'


Create dovecot.conf file as follows.

[root@server ~]# cat /etc/dovecot/dovecot.conf

auth_debug = yes
auth_mechanisms = plain login
auth_username_format = %Lu
auth_verbose = yes
mbox_write_locks = fcntl
passdb {
  driver = pam
}
passdb {
  driver = pam
}
passdb {
  args = /etc/dovecot/dovecot-mysql.conf
  driver = sql
}
service auth {
  unix_listener /var/spool/postfix/private/auth {
    group = postfix
    mode = 0660
    user = postfix
  }
  user = root
}
ssl_cert = </etc/pki/dovecot/certs/dovecot.pem
ssl_key = </etc/pki/dovecot/private/dovecot.pem
userdb {
  driver = passwd
}
userdb {
  driver = passwd
}
userdb {
  args = uid=5000 gid=5000 home=/home/vmail/%d/%n
  driver = static
}


Once the above settings has been completed, restart postfix and dovecot and verify the installation using telnet.

# /etc/init.d/dovecot restart
# /etc/init.d/postfix restart



Install and Configure RoundCubeMail


Download RoundCubeMail code

You can install latest roudcube using git.

# yum install git -y

# cd /usr/local
# git clone git://github.com/roundcube/roundcubemail.git

You can find a directory named 'roundcubemail' after the above step.

Install Necessary Packages

Install the following packages for the working if roundcube.

# yum install httpd php php-common php-json php-xml php-mbstring php-imap php-pear php-mysql mysql mysql-server

You have to add the following entries in the httpd.conf to access roundcube via browser.

Alias /roundcube /usr/local/roundcubemail

Restart httpd service.

# /etc/init.d/httpd restart


Necessary DataBase setup

Here i am using the following details for the DB setup. You can change it as you like.

DB: roundcubemail
DB User: roundcubemail
Password: roundcube_pass

# mysql -e "CREATE DATABASE roundcubemail;"
# mysql -e "GRANT ALL PRIVILEGES ON roundcubemail.* TO roundcube@localhost IDENTIFIED BY 'roundcube_pass';"
# mysql roundcubemail < /usr/local/roundcubemail/SQL/mysql.initial.sql


You can now access roundcube using the following url. You have to follow the instruction to complete the installation.

http://<IP>/roundcube/installer/

Once the installation completed, http://<IP>/roundcube allow you to login to the mail accounts.


Reference:
http://www.server-world.info/en/

Leave a Reply