On the Net

|Main Blog|Yearning|  

Words of God


About Linux News and OpenSource




and below are my posts....


Thursday, December 01, 2005

Setting up Postfix, PostfixAdmin, Courier, SquirrelMail and Virtual Domain/Users and MYSQL as users Database

I'll try to describe here my Centos 4.2 Mail server running postfix, courier, squrrelmail, and virtual users and domain using Mysql as user database.

If you don't like the way how I described it, you can visit here, the original and more detailed explanation on doing this.

Installing Centos 4.2, with Apache webserver, PHP and Mysql should be done first. I also install PHPMyadmin since I'm not good on Mysql CLI so have to depend on web based interface. After installing and configuring PHPmyadmin, I tried it and test if it does works well. Now that Im sure that PHP and mysql runs correctly, I'll now install Postfix, PostfixAdmin, and Courier-Imap.

Installing postfix:

The default postfix rpm that can be installed by just typing "yum install postfix" does not support mysql, so I have to download postfix.src.rpm from the source rpm mirror and recompile it and enable mysql support.

Here's a little how-to:
  • Download and install postfix source rpm from here.
  • Edit the postfix spec file, the line "%define MYSQL" should be followed by 1, the default is 0
  • Then as root, issue the command "rpmbuild -bb /usr/src/redhat/SPECS/postfix.spec"
  • It will prompt you to install those package needed by rebuilding POstfix, just install them one by one, anyway, you can just remove them after the installation has been rebuild.
  • After the package has been rebuild, install the RPM file located at "/usr/src/redhat/RPMS/i386/"

Ok, make sure that sendmail has been remove before installing Postfix. Then try to configure it and make sure that the host where postfix resides should be able to send an email by using localhost as an smtp server. If it does, then we will proceed to installing courier-imap...

The Courier-Imap that comes with Centos, by default does not support mysql so we have to build Courier-Imap from source to produce RPM package. First, I thought of it as its a hard to do, but I was wrong then, its not that hard.. google and the docs and FAQ from Courier's website really helps. Here's how I did it.

  • Download the only needed Courier-Imap packages. What we need are the courier-imap and courier-authlib packages. You can download from here the needed packages.
  • Build the rpm as a regular user, not as root, follow the steps below, or you can visit this page.
  1. mkdir $HOME/rpmmkdir $HOME/rpm/SOURCES
    mkdir $HOME/rpm/SPECS
    mkdir $HOME/rpm/BUILD
    mkdir $HOME/rpm/SRPMS
    mkdir $HOME/rpm/RPMS
    mkdir $HOME/rpm/RPMS/i386
  2. echo "%_topdir    $HOME/rpm" >> $HOME/.rpmmacros
  3. rpmbuild -ta courier-imap-0.40.tar.bz2   # For RPM 4.1, and higher (Red Hat 8.0)
    rpmbuild -ta courier-authlib-*.tar.bz2
  • After doing what should have to be done, installing those needed additional packages to install and assuming that it has been successfully build, you can find those rpm on your $home/rpm/RPMS/i386/ and install it as root.
Now that we have installed those required packages, we need to install and setup PostfixAdmin. Postfix Admin is a Web Based Management tool created for Postfix. It is a PHP based application that handles Postfix Style Virtual Domains and Users that are stored in MySQL. Below is the content of Install.txt that can be found together with the postfixadmin package.

#
# Postfix Admin
# by Mischa Peters
# Copyright (c) 2002 - 2005 High5!
# License Info: http://www.postfixadmin.com/?file=LICENSE.TXT
#

REQUIRED!!
----------
- You are using Postfix 2.0 or higher.
- You are using Apache 1.3.27 or higher.
- You are using PHP 4.1 or higher.
- You are using MySQL 3.23 or higher.


READ THIS FIRST!
----------------
When this is an upgrade from Postfix Admin 1.5.4 please read UPGRADE.TXT!!

If you need to setup Postfix to be able to handle Virtual Domains and Virtual
Users check out http://high5.net/howto/


1. Unarchive new Postfix Admin
------------------------------
Make sure that you are in your WWW directory and then unarchive the
Postfix Admin archive (whatever the filename is):

$ tar -zxvf postfixadmin-2.0.0.tgz


2. Change permissions
----------------------
Since the database password is stored in the config.inc.php it's a good idea
to have change the permissions for Postfix Admin.

$ cd /usr/local/www/postfixadmin
$ chmod 640 *.php *.css
$ cd /usr/local/www/postfixadmin/admin/
$ chmod 640 *.php .ht*
$ cd /usr/local/www/postfixadmin/images/
$ chmod 640 *.gif *.png
$ cd /usr/local/www/postfixadmin/languages/
$ chmod 640 *.lang
$ cd /usr/local/www/postfixadmin/templates/
$ chmod 640 *.tpl
$ cd /usr/local/www/postfixadmin/users/
$ chmod 640 *.php


3. Create the Database Tables
--------------------------
In DATABASE_MYSQL.TXT you can find the table structure for MySQL that you need
in order to configure Postfix Admin and Postfix in general to work with
Virtual Domains and Users.

In DATABASE_PGSQL.TXT you can find the table structure for PostgreSQL.


4. Configure
------------
Check the config.inc.php file. There you can specify settings that are
relevant to your setup.

Postfix Admin contains 3 views of administration.
There is the Site Admin view, located at http://domain.tld/postfixadmin/admin/.
There is the Domain Admin view, located at http://domain.tld/postfixadmin/.
And there is the User Admin View, located at http://domain.tld/postfixadmin/users/.

In order to do the initial configuration you have to go to the Site Admin view.

The default password for the Site Admin view of Postfix Admin is admin/admin.

This is specified in the .htpasswd file in the /admin directory. Make sure
that the location of the .htpasswd file matches your path.


5. Done
-------
This is all that is needed. Fire up your browser and go to the site that you
specified to host Postfix Admin.


6. More information
-------------------
For more information you can go to the Postfix Admin forums.
http://forums.high5.net/index.php?showforum=22

Now assuming that postfix admin has been installed successfully, we will now try to reconfigure postfix for it to work as been expected.

Edit "/etc/postfix/main.cf" and add the txt below:

virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_gid_maps = static:89
virtual_mailbox_base = /home/virtualmail
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_mailbox_limit = 51200000
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_minimum_uid = 89
virtual_transport = virtual
virtual_uid_maps = static:89

# Additional for quota support
virtual_create_maildirsize = yes
virtual_mailbox_extended = yes
virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf
virtual_mailbox_limit_override = yes
virtual_maildir_limit_message = Sorry, the user's maildir has overdrawn his diskspace quota, please try again later
virtual_overquota_bounce = yes

Notes:
  • "virtual_mailbox_base = /home/virtualmail" - The "virtualmail" folder under /home should be created manually. Also it is not necessarily that the folder should be inside the /home, It could also be at /var or /var/mail
  • The uid that has an 89 value is the same as the usi of user postfix.
Then, we have to manually create the file "myql_virtual_alias_maps.cf" and the others as defined on the main.cf file under /etc/postfix. Below are the entries that we should put on those files.

#filename:mysql_virtual_alias_maps.cf, and below are the contents of this file
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = alias
select_field = goto
where_field = address

#mysql_virtual_domains_maps.cf
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = domain
select_field = description
where_field = domain

#mysql_virtual_mailbox_maps.cf
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = mailbox
select_field = maildir
where_field = username

#mysql_virtual_mailbox_limits_maps.cf
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = mailbox
select_field = quota
where_field = username

Now that we've finished creating those files, we need to reload postfix to apply those changes we made.. (#/etc/init.d/postfix restart). We shall now try to open the url where we can access the postfixadmin page. If we won't encounter any problem at all, we should be able to add any virtual domain and virtual users. Those individual folders will be automatically created under the "/home/virtualmail" directory.

Opps! when encountered a problem during adding a domain, thus that postfix admin will just prompt that the domain already exist, try to edit the php.ini file. The line that contains "magic_quote_gpc" should be changed to "ON". The default is off. Then try to reboot. If you can't afford to reboot, reload all the services that uses PHP.

Now we will make some changes on /etc/authlib/authdaemonrc.

The default is the commented authmodulelist below. I changed it to the value of the uncommented one, thus that contains only "authpam and authmysql"

#///////////////////////////////
#/etc/authlib/authdaemonrc
#authmodulelist="authuserdb authpam authpgsql authldap authmysql authcustom authpipe"
authmodulelist="authmysql authcustom authpam"
#if authpam is not included here, your local users wont be able to access IMAP or POP3 server
authmodulelistorig="authuserdb authpam authpgsql authldap authmysql authcustom authpipe"
#///////////////////////////////

Then edit /etc/authlib/authmysqlrc the same as described below.
#/etc/authlib/authmysqlrc
##NAME: LOCATION:0
# The server name, userid, and password used to log in.
MYSQL_SERVER localhost
MYSQL_USERNAME postfix
MYSQL_PASSWORD postfix
MYSQL_SOCKET /var/lib/mysql/mysql.sock
#MYSQL_PORT 3306
MYSQL_OPT 0
MYSQL_DATABASE postfix
MYSQL_USER_TABLE mailbox
MYSQL_CRYPT_PWFIELD password
#MYSQL_CLEAR_PWFIELD password
MYSQL_UID_FIELD '89'
MYSQL_GID_FIELD '89'
MYSQL_LOGIN_FIELD username
MYSQL_HOME_FIELD '/home/virtualmail'
MYSQL_NAME_FIELD name
MYSQL_MAILDIR_FIELD maildir
# MYSQL_QUOTA_FIELD quota
Note:
I assign the name postfix as mysql username and the password is also postfix, so you can change it to any name you like as long as you gave that name enough rights to access the database postfix on your mysql database.


Ok, after installing those described above, I then install and configure squirrelmail to test that my webserver really run as I want it to be... I got my domain from http://dyndns.org. I point several subdomain to the IP assigned to the host act as the mail server and manage the the multiple subdomains and virtual email accounts via postfixadmin.

--




0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home