How to Configure Postfix, Dovecot, Virtual Domains, Virtual Users in CentOS

Step 1: Install Postfix

Install postfix using yum command:

# yum install postfix

Step 2: Run Postfix on Multi-Levels

Make sure run the postfix on multilevels:

# chkconfig postfix on

Step 3: Modify /etc/postfix/ File

Make a copy of both these files &

# cd /etc/postfix
# cp
# cp

Edit and change the following values:

# vi /etc/postfix/
myhostname =
mydomain =
myorigin = $mydomain
inet_interfaces = all
home_mailbox = Maildir/

Step 4: Create Postfix User

Create postfix user “userpostfix” on server with login shell as /sbin/nologin

# useradd -s /sbin/nologin userpostfix

Check the UID:GUID for the userpostfix user in /etc/passwd file

# tail /etc/passwd

Step 5: Configure Virtual domain

Add the following lines at the end of and replace the UID:GUID under virtual_minimum_uid, virtual_maximum_uid, virtual_uid_maps and virtual_gid_maps

# vi /etc/postfix/
virtual_mailbox_domains = /etc/postfix/virtual_domains
virtual_mailbox_base = /var/mail/vhosts
virtual_mailbox_maps = hash:/etc/postfix/vmailbox
virtual_minimum_uid = 1001
virtual_maximum_uid = 1001
virtual_uid_maps = static:1001
virtual_gid_maps = static:1001
virtual_alias_maps = hash:/etc/postfix/virtual

Create /etc/postfix/virtual_domains. It contains all the domains that are pointed on server.

# vi /etc/postfix/virtual_domains

Step 6: Create Mail Directories

Create the mail directory, sub directory for the domains and assign the proper permissions.

# mkdir /var/mail/vhosts
# chgrp -R userpostfix /var/mail
# cd /var/mail/vhosts
# mkdir
# mkdir
# mkdir
# cd ..
# chown -R userpostfix:userpostfix vhosts

Note: Postfix will create the “Maildir” directories automatically and assign the proper permissions.

Step 7: Create /etc/postfix/vmailbox File

Create a file /etc/postfix/vmailbox and add all of the users that will receive e-mails.

# touch /etc/postfix/vmailbox
# vi /etc/postfix/vmailbox

Note: Make sure you end up each line with “/”.
Postfix will automatically create Maildir structure (cur, new, tmp).

Step 7: Execute postmap Command

Create the hashed file (.db) using postmap command.

# postmap /etc/postfix/virtual
# postmap /etc/postfix/vmailbox

Step 8: Check postfix Status

Make sure postfix service is running fine and port 25 is opened for postfix.

# ps -eaf | grep postfix
postfix   1219  1590  0 12:05 ?        00:00:00 pickup -l -t fifo -u
root      1353 30585  0 12:06 pts/0    00:00:00 grep postfix
root      1590     1  0 Mar05 ?        00:01:03 /usr/libexec/postfix/master
postfix  23181  1590  0 Apr13 ?        00:00:07 qmgr -l -t fifo -u
# netstat -an | grep :25
tcp        0      0        *                   LISTEN
tcp        0      0 :::25                       :::*                        LISTEN
tcp        0      0 ::ffff:      ::ffff:   TIME_WAIT

Step 9: Reload postfix

Now reload the postfix service:

# service postfix reload

Step 10: Test Postfix

Test the mail using telnet command:

# telnet localhost smtp
Connected to localhost.
Escape character is '^]'.
220 ESMTP Postfix
ehlo localhost
250-SIZE 10240000
250 DSN
250 2.1.0 Ok
250 2.1.5 Ok
354 End data with .
Test Mail
250 2.0.0 Ok: queued as E7E1F5A1F6
221 2.0.0 Bye
Connection closed by foreign host.

How to Configure Dovecot

Dovecot is an open-source POP and IMAP client.

Step 1: Install Dovecot

Install dovecot using yum command:

# yum install dovecot

Step 2: Configure Dovecot on Multi-Levels

To Configure dovecot on multilevels:

# chkconfig dovecot on

Step 3: Configure Dovecot Files

Then, go to conf.d folder and change the following lines in the following files.

# cd /etc/dovecot/
# vi dovecot.conf
protocols = imap pop3
# cd /etc/dovecot/conf.d/
# vi 10-auth.conf
disable_plaintext_auth = no
#!include auth-system.conf.ext
!include auth-passwdfile.conf.ext
# vi 10-logging.conf
log_path = /var/log/dovecot.log
auth_verbose = no
auth_debug = no
verbose_ssl = no
# vi 10-mail.conf
mail_location = maildir:/var/mail/vhosts/%d/%n
mail_uid = 1001
mail_gid = 1001
mail_privileged_group = userpostfix
# vi 10-master.conf
unix_listener auth-userdb {
  mode = 0600
  user = postfix
  group =  postfix
# Postfix smtp-auth
unix_listener /var/spool/postfix/private/auth {
  mode = 0666
  user = postfix
  group = postfix

Step 4: Reload Dovecot

Now reload the dovecot service:

 # service dovecot reload

Step 5: Test Dovecot

# telnet localhost pop3
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
pass Test123
+OK Logged in.
+OK 1 messages:
1 3845
retr 1
+OK 3845 octets
Return-Path: <>
X-Original-To: user1
Received: from localhost (localhost [IPv6:::1])
by (Postfix) with ESMTP id 117113FF18
for ; Thu, 7 Feb 2013 17:05:32 +0530 (IST)
Message-Id: <>
Date: Thu, 7 Feb 2013 17:05:32 +0530 (IST)
To: undisclosed-recipients:;

+OK Logging out.
Connection closed by foreign host.

How to Configure Squirrelmail

Step 1: Prerequisites

Step 2: Install Squirrelmail

Install EPEL repository and install SquirrelMail package from EPEL repository.

# wget
# rpm -ivh epel-release-6-8.noarch.rpm 
# yum install squirrelmail
# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]

Step 3: Configure Squirrelmail

Configure according to the server as following:

# cd /usr/share/squirrelmail/config/
# ./ 
SquirrelMail Configuration : Read: config.php (1.4.0)
Main Menu --
1.  Organization Preferences
2.  Server Settings
3.  Folder Defaults
4.  General Options
5.  Themes
6.  Address Books
7.  Message of the Day (MOTD)
8.  Plugins
9.  Database
10. Languages
D.  Set pre-defined settings for specific IMAP servers
C   Turn color off
S   Save data
Q   Quit
Command >>2

SquirrelMail Configuration : Read: config.php (1.4.0)
Server Settings
1.  Domain                 :
2.  Invert Time            : false
3.  Sendmail or SMTP       : SMTP
A.  Update IMAP Settings   : localhost:143 (uw)
B.  Update SMTP Settings   : localhost:25
R   Return to Main Menu
C   Turn color off
S   Save data
Q   Quit
Command >> S

Press S to save datas and press Q to exit.

Step 4: Configure Squirrelmail with httpd.conf

Add the following lines in the httpd.conf file at the end.

# vi /etc/httpd/conf/httpd.conf
Alias /squirrelmail /usr/share/squirrelmail
<Directory /usr/share/squirrelmail>
    Options Indexes FollowSymLinks
    RewriteEngine On
    AllowOverride All
    DirectoryIndex index.php
    Order allow,deny
    Allow from all

Restart the httpd service.

# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]

How to Install PHP in Linux

Step 1: Prerequisite

Step 2: Install PHP

Run the yum install command

# yum install php-mysql php-devel php-gd php-pecl-memcache php-pspell php-snmp php-xmlrpc php-xml

Step 3: How to configure PHP

# vi /etc/php.ini
memory_limit = 128M
max_execution_time = 120
max_upload_size = 50M
post_max_size = 50M

Step 4: Create PHP page

Create the /var/www/html/phpinfo.php file with the following text:

# touch /var/www/html/phpinfo.php
# vi /var/www/html/phpinfo.php

Step 5: Restart Apache Server

Now restart Apache Server

# service httpd restart

Step 6: Open Page on Browser

Test the php page on your favorite browser:

How to Install phpmyadmin in CentOS / RedHat / Fedora

Step 1: Prerequisites

Step 2: Download Package

Download rpm package for CentOS / RedHat /Fedora

# rpm -ivh
# yum install
# yum check-update

Step 3: Install phpmyadmin

# yum install phpMyAdmin

Step 4: Reload Apache Service

# service httpd restart

Step 5: Check on Browser

Open your favorite browser and Hit the  URL:


»  #2002 – Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)
The server is not responding (or the local server’s socket is not correctly configured).
( This means your mysql server service is stopped , you must start the service  “service mysql start”)

» You don’t have permission to access /phpMyAdmin/ on this server.
Open /etc/httpd/conf.d/phpMyAdmin.conf file and find the lines “Deny from All” and comment those lines and restart httpd service

vi /etc/httpd/conf.d/phpMyAdmin.conf

» If you are installing phpmyadmin on Redhat 7 you may face this issue:
Error: Package: php-php-gettext-1.0.11-10.el7.noarch (epel)
Requires: php-mbstring
Error: Package: php-tcpdf-6.0.091-1.el7.noarch (epel)
Requires: php-bcmath
Error: Package: phpMyAdmin- (epel)
Requires: php-mbstring >= 5.3.0
Error: Package: php-tcpdf-6.0.091-1.el7.noarch (epel)
Requires: php-mbstring
You could try using –skip-broken to work around the problem
You could try running: rpm -Va –nofiles –nodigest

In order to resolve this issue follow the following steps:

# wget

Install yum replace package and replace entire PHP stack

# rpm -i yum-plugin-replace-0.2.7-1.ius.el7.noarch.rpm 
# yum replace php --replace-with php56u