Create a highly scalable web mail system instance under apache

Source: Internet
Author: User
Tags imap ldap php software php tutorial require openldap

1.2 Requirements
This document mentions three servers: web server, imap server, and LDAP server. These servers can be deployed on an independent host or several independent machines (for example, 23 web servers, 5 LDAP servers, and 10 IMAP servers ), or a single server. At the same time, you must have the basic knowledge of installing software from the source code in a Linux environment.

1.3 software used
Building the system requires the following software packages: Apache 1.3.6 or later http://www.apache.org/PHP 3.0.12 requires compilation of IMAP and LDAP support in OpenLDAP 1.2 Cyrus 1.5.19 (note: Do not use 1.6) postfix 19990627 pwcheck_ldap patch (for cyrus 1.5) IMP (2.0.4, 2.0.10, and 2.1.3-dev) uw imap (for c-client) note: the cyrus 1.6 Tree uses a different method called SASL. The pwcheck_ldap patch is not designed for this method. However, the sasl ldap patch is being designed. You can visit this homepage to obtain the latest information.

1.4 Special Notes
This system has a poor scalability: IMP is used to save session data, parameters, and address book SQL servers.

2. Install software 2.1 Web server
On the web server, the administrator needs to install the following software packages: Apache, PHP, postfix, OpenLDAP, uw imap, and IMP. it is easy to install Apache and PHP. The installation guide for specific steps in the PHP software package is described in detail. When installing PHP, you need to compile the support for LDAP and IMAP. For details about how to install the postfix, refer to the installation guide of the accompanying software package. Pay special attention to the LDAP_README file.

2.2 install the LDAP server
Install OpenLDAP software to build the LDAP server. You need to determine a root dn and add the settings to the LDAP db accordingly.

2.3 Installation of the IMAP server
On the IMAP server, you will need to install the LDAP, postfix, Cyrus, and cyrus pwcheck_ldap patches. You must add ldap support when compiling postfix. Install Cyrus according to the software installation documents, but modify pwcheck_ldap.c according to the pwcheck_ldap patch documents. In addition, you need to modify pwcheck_ldap.c to provide ldap server and root dn information. Similarly, if you run the IMAP server on a linux server, you need to make the following correction in the file pwcheck_ldap.c: add a line: # include <linux/stddef. h> In addition, some other syntax modifications are required, which can be found during compilation. Run the following command to configure cyrus:

./Configure -- with-login = unix_pwcheck -- with-pwcheck = ldap

Later compilation and installation are based on cyrus documents;

3. How to configure the server to work collaboratively with the configuration of the 3.1 LDAP server
Each mail user information in the LDAP database tutorial requires the following content except for other information you want to provide: (assume that your root dn is o = someorg, c = US ):

Dn: uid = someuser, o = someorg, c = us
Uid: someuser
Userpassword: somepassword
Maildrop: fulladdress@machine.dom.ain
Mailacceptinggeneralid: someuser
Mailacceptinggeneralid: somealias

Similarly, you must select a user with the cyrus management permission. Management issues need to be considered only when cyrus needs to be configured on the imap server. In addition, it is recommended that you do not add administrative permissions to an existing user. This may cause security issues or the user cannot view his/her emails.

3.2 imap server configuration
The postfix configured on the IMAP server uses ldap for alias matching. This issue is described in LDAP_README. For Cyrus, follow the installation instructions file of the software package. Similarly, do not forget to activate pwcheck and add Management Users in imap. conf.

3.3 web Server
In this step, the web server is also the front-end of the receiving email gateway. Configure postfix to use ldap for alias matching. In this way, check the LDAP maildrop table item and forward the email to the maildrop address. Therefore, the full mail name is required in maildrop. For example, you can allocate 700,000 users to each server, with an average of 10000 users per server. The Mail destination address is the user1@dom.ain of the mail will be connected to a WEB server, and the Mail will be forwarded to the address according to the maildrop attribute, and the mail sent to user657 will be forwarded to user657 @ mail34. Moreover, the maildrop attribute can be used as a forwarding address at the same time, for example, the email to user302 is forwarded to the someuser@somewhereelse.com ">

For example, you can allocate 700,000 users to each server, with an average of 10000 users per server. The Mail destination address is a user1@dom.ain of mail that will be connected to a WEB server that will be forwarded to the address according to the maildrop attribute, and the mail sent to user657 will be forwarded to user657 @ mail34. Furthermore, the maildrop attribute can also be used as a forward address, for example, a mail to user302 is forwarded to the someuser@somewhereelse.com.

The configuration of IMP is generally based on the software documentation. After the configuration is complete, you need to make the following modifications: add the following content in config/defaults. php Tutorial 3:

/* LDAP/IMAP Server Default */$ default-> LDAP_server = 'ldap. dom. ain '; $ default-> LDAP_dn = 'o = someorg, c = us'; $ default-> LDAP_search_field = 'uid'; $ default-> ldap_choose_server = true;
To mailbox. php3 apply the following patch:

Index: mailbox. php3 =================================================== ======================================== cross file: /home/cvs/imp/mailbox. php3, v retrieving revision 2.29 diff-c-r2.29 mailbox. php3 *** mailbox. php3 07:20:00 2.29 --- mailbox. php3 18:04:10 ********************** 29,34 ***** --- 29,51 ---- require '. /lib/mimetypes. lib '; require '. /config/defaults. php3 '; +/************* LDAP ************ **/++ If ($ default-> ldap_choose_server) {+ $ ldapconnect = ldap_connect ($ default-> LDAP_server); + if ($ ldapconnect) {+ print ("YES! "); + $ Ldapbind = ldap_bind ($ ldapconnect); + $ ldaps tutorial earch = ldap_search ($ ldapconnect, $ default-> LDAP_dn, $ default-> LDAP_search_field. "= ". $ imapuser, array ("maildrop"); + $ ldapget = ldap_get_entries ($ ldapconnect, $ ldapsearch); + $ ldapspl = explode ("@", $ ldapget [0] ["maildrop"] [0]); + $ server = $ ldapspl [1]; + $ port = $ default-> port; +}

+/*********** End ldap ************/++/* Html styles configuration */require '. /config/html. php3 ';/* Mailbox configuration */After all configurations are completed, a highly scalable web mail system will be available.
Note: In July August 1999, the new version of IMP already contains the content of these patches. Therefore, you do not need to add these patches if you use the new version.


4. Miscellaneous 4.1 Adding Users

Here is a short section to add user code to the LDAP server and add an email user to cyrus. This is designed for the IMAP server, but you can modify it to adapt to other environments.

<? Php
$ Ldapconn = ldap_connect ("ldap. dom. ain ");
$ Machine = "mail01 ";
If ($ ldapconn)
{
$ Ldhb = ldap_bind ($ ldapconn, "cn = cyrusadmin, o = someorg, c = US", "password ");
$ Dn = "uid =". $ username. ", o = someorg, c = US ";
$ Info ["uid"] = $ username;
$ Info ["userpassword"] = $ password;
$ Info ["objectclass"] = "account ";
$ Info ["maildrop"] = $ username. "@". $ machine. ". dom. ain ";
$ Info ["mailacceptinggeneralid"] = $ username;
$ Ldhb = ldap_add ($ ldapconn, $ dn, $ info );
Ldap_close ($ ldapconn );
}
$ Imapconn = imap_open ("{". $ machine. ". dom. ain: 143}", "cyrusadmin", "password ");
If ($ imapopen)
{
Imap_createmailbox ($ imapconn, "{". $ machine. "dom. ain: 143} user.". $ username );
Imap_close ($ imapconn );
}
?>

Note: Due to a bug, the plaintext password is used here.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.