Author Topic: Server 2003 R2, PHP5, MySQL5, hMailServer, RoundCube 552, Active Directory Setup  (Read 11655 times)

Offline Bcrosswize

  • Jr. Member
  • **
  • Posts: 10
Round Cube Webmail // give me a min.. need to catch my breath… “WoW… just WoW” Great Job you guys.

This tutorial assumes you have Server 2003 R2, Apache, PHP5, MySQL5, hMailServer, and Active Directory already setup.

Notes: On my server I have 2 harddrives.
     HD1 is split into 2 partitions… C: and D:
     HD2 E:

C:= windows OS
D:= installed 3 party programs (IE: D:\PHP5, D:\www for apache etc) You may need to change the D: references according to your setup.
E:= mail storage.


We have 2 different computers.
Machine 1(referred to as “PDC” in this tutorial: Primary Domain Controller) has an address of This is the ldap3 or Active Directory server.

Machine 2(referred to as “Mail Machine”): This machine runs www, mail, Round Cube, MySQL, and has an internal address of It also has an external address that DNS and MX records point to. Thats 2 network cards. :) I will be accessing Active Directory on "PDC"( remote machine) from "Mail Machine"( local machine)

Lets say my domain is for an elementary school.
Webpage is // DNS points to my external address of "Mail Machine"
My mail comes to // MX records point to external address of "Mail Machine"

"PDC" (Server 2003) Domain:= // The "PDC" Machine
Added a container to Active Directory:= Southtown School District
Added containers to the Active Directory Southtown School District container:= Management, Instructors, Tech Dept, Students
Added users to each of these new containers.
Containers and users in the Active Directory on "PDC" look like this
This is shown in case the pic below is not available.
Southtown School Disctict
    Bob D Boss
    Teach U
    Teach Mii
    Teach Et
  Tech Dept
    Joe Hack
    Jack Slap
    Will Slash

We are finished with setup of “PDC” containers/users. We will now be working on “Mail Machine” for most of the remainder of this tutorial.

Offline Bcrosswize

  • Jr. Member
  • **
  • Posts: 10
RoundCube Install
« Reply #1 on: May 16, 2007, 06:47:57 PM »
Didn’t want roundcube in htdocs so I made these mods.

Apache install created the D:\www\

Create a new dir:= D:\www\utils   // Web utilities (IE: phpMyAdmin etc)
Create a new dir:= D:\www\utils\web_pass // htpasswd
Open command prompt to D:\www\bin and type
Code: [Select]
htpasswd –c htpasswd.txt admin
enter the password 2 times.

Close command prompt then move D:\www\bin\htpasswd.txt to D:\www\utils\web_pass\

Create a new dir:= D:\www\logs\roundcube
Create a new dir:= D:\www\logs\roundcube\temp // This is where your log and temp files for roundcube will be.

Open apache’s config file:= httpd.conf and search for and type

Code: [Select]
# Change 01/01/07
Alias /mail “D:/www/utils/mail”

  Order allow,deny
  Allow from all
  AllowOverride AuthConfig
  AuthName “Restricted Area!”
  AuthType Basic
  AuthUserFile D:\www\utils\web_pass\htpasswd.txt
 Require user admin // username you have in htpasswd.txt
Just before

Notes: This will give you password protection until you have this up and running correctly.
     Require user admin should correlate to the username you made in htpasswd.txt

Downloaded 557.tar.gz from
Extracted to D:\www\utils\mail
Rename D:\www\utils\mail\.htaccess to 1.htaccess /* error problem if not
Make a copy of D:\www\utils\mail\config\ Rename to
Make a copy of D:\www\utils\mail\config\ Rename to

Offline Bcrosswize

  • Jr. Member
  • **
  • Posts: 10
« Reply #2 on: May 16, 2007, 06:48:59 PM »
We need to create the roundcubemail database and roundcube user.
Open a command prompt window and type
Code: [Select]
mysql –u root –p
Enter password

> CREATE DATABASE roundcubemail DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
> GRANT ALL PRIVILEGES ON roundcubemail.* TO roundcube@localhost
      IDENTIFIED BY ‘password’;
> quit

There are problems with D:\www\utils\mail\mysql5.initial.sql
Some variables needed to be null to work correctly.
Attached is an updated mysql5.initial.sql file. Compare this to the original if your interested.

Open a command prompt window and cd to D:\www\utils\mail\SQL then type
Code: [Select]
Mysql –u root –p roundcubemail < mysql5.initial.sql
Enter password

Notes: this mysql5.initial.sql is modified for the Advanced Address Book. You can compare this and the original and delete the entries if needed.

Offline Bcrosswize

  • Jr. Member
  • **
  • Posts: 10
The Config Files
« Reply #3 on: May 16, 2007, 06:49:37 PM »

  Open D:\www\utils\mail\config\ with your fav editor and change
Code: [Select]
$rcmail_config[‘db_dsnw’] = ‘mysqli://roundcube:pass@localhost/roundcubemail’;  Save and Close

  Notes: mysqli is the php5 driver
      Use the same username(roundcube), password(pass) and database name that you made in the MySQL setup.

  Open D:\www\utils\mail\config\ with your fav editor and change
Code: [Select]
$rcmail_config['enable_caching'] = FALSE;
$rcmail_config['default_host'] = 'localhost';
$rcmail_config['username_domain'] = '';
$rcmail_config['smtp_server'] = 'localhost'; // Note if left blank it uses PHP to mail...My mail was courrupt
$rcmail_config['temp_dir'] = 'D:/www/logs/roundcube/temp/'; // very important... temp not right, no log files
$rcmail_config['log_dir'] = 'D:/www/logs/roundcube/'; // very important for trouble shooting your gig
$rcmail_config['useragent'] = 'Southtown E-Mail';
$rcmail_config['product_name'] = 'Southtown E-Mail';
$rcmail_config['drafts_mbox'] = 'Drafts'; // Outlook Replica
$rcmail_config['junk_mbox'] = 'Spam'; // Outlook Replica
$rcmail_config['sent_mbox'] = 'Sent Items'; // Outlook Replica
$rcmail_config['trash_mbox'] = 'Deleted Items'; // Outlook Replica
$rcmail_config['default_imap_folders'] = array('INBOX', 'Drafts', 'Sent Items', 'Spam', 'Deleted Items'); // Outlook Replica
$rcmail_config['ldap_public']['Southtown'] = array( // ldap setup
 'name'     => 'Southtown School', // name shown in roundcube address book
 'hosts'     => array(''), // Server 2003 with Active Directory
 'port'     => 389, // Server 2003 ldap port
 'version'    => 3, // added for ldap version
 'user_id'    => 'ImUrHuckleBerry', // added for ldap username
 'pwd'      => 'SuperCrypticPass', // added for ldap password
 'base_dn'    => 'OU=Southtown School District,DC=southtown,DC=k12,DC=mo,DC=us', // Active Directory Setup
 'filter'    => 'sn=*', // Active Directory Filter... Change as needed
 'search_fields' => array('Email' => 'mail', 'Name' => 'cn'), // search fields
 'name_field'  => 'cn',  // this field represents the contact's name
 'email_field'  => 'mail', // this field represents the contact's e-mail
 'scope'     => 'sub', // search mode: sub|base|list
 'fuzzy_search'  => 0); // server allows wildcard search
$rcmail_config['dont_override'] = array(timezone, dst_active, language); // no user override
$rcmail_config['timezone'] = -6; // your time zone
$rcmail_config['prefer_html'] = FALSE; // no html
$rcmail_config['htmleditor'] = FALSE; // no html
$rcmail_config['preview_pane'] = TRUE; // Preview pane :)
 Notes: We have Outlook users so I replicated the folders used.
      Fields for version, user_id, and pwd were added to the ldap area for Active Directory

Offline Bcrosswize

  • Jr. Member
  • **
  • Posts: 10
Bug Squishing
« Reply #4 on: May 16, 2007, 06:50:23 PM »
Point your browser to
Enter username and password for the Restricted Areas! box. (these are from htpasswd.txt setup)
You should have a RoundCube logon page. Below are some errors I encountered.

Note: D:\www\utils\mail\config\ has a setting $rcmail_config[‘debug_level’] = 1’
You can change this to 4 to show on screen errors. Helps if you don’t have error log working correctly.

Error 1f4
  My problem was a database error. // these are corrected in the available in the MySQL Post.
  Some possible causes:
  No database/databaseuser for roundcube // consult MySQL Post above.
  Incorrect permissions for roundcubeuser on the roundcube database // consult MySQL Post above.
  Incorrect mysql driver in D:\www\utils\mail\config\ // needs mysqli as noted in MySQL Post
  Incorrect info for roundcubeuser and or roundcube database in D:\www\utils\mail\config\ // consult MySQL Post above.
  Incorrect database values // NOT NULL vrs NULL again…these are corrected in the available in the MySQL Post.

Logon Errors
  Config hMailServer to log activity then check those logs.
  Check RoundCube errors log D:\www\logs\roundcube\errors

PHP Errors

Logging Errors
  Incorrect setting in D:\www\utils\mail\config\
  $rcmail_config['temp_dir'] = 'D:/www/logs/roundcube/temp/';
  $rcmail_config['log_dir'] = 'D:/www/logs/roundcube/';
  Note: these need to be FORWARD SLASH (IE: / not \)

Log Errors
  RoundCube errors log to D:\www\logs\roundcube\errors on this tutorial.

  PHP Warning: Cannot modify header information - headers already sent in ...etc
   Don't have a fix at this time. I get this Warning ever time an email is sent. No apparent effect.

Attachments hiden/not showing in Internet Explorer
  Internet Explorer has problems with float. For a lack of better knowledge I commented it out.
  Open D:\www\utils\mail\skins\default\mail.css
Code: [Select]
#attachment-list li
/* Change 01/01/07*/
/* float: left;*/
 height: 18px;
 font-size: 11px;
 padding: 2px 10px 0px 10px;

Corrupt email attachments
  With the default $rcmail_config['smtp_server'] = ''; setting my mail/attachments were courrupt. PHP mailing problem?
  Open D:\www\utils\mail\config\
Code: [Select]
// Change 01/01/07
//$rcmail_config['smtp_server'] = '';
$rcmail_config['smtp_server'] = 'localhost';

Offline Bcrosswize

  • Jr. Member
  • **
  • Posts: 10
Active Directory
« Reply #5 on: May 16, 2007, 08:57:16 PM »
Note: jxplorer installed and worked correctly on one machine, but installed and failed to open with the icon on another machine. Had to use the jxplorer .bat file to open it. C:\Program Files\JXplorerjxplorer.bat

This can be used to explore Active Directory on “PDC”
Setup for opening a connection to ‘PDC” as follows

Code: [Select]
Protocal: LDAP v3
DSML Service: (leave alone)
Base DN: DC=southtown,DC=k12,DC=mo,DC=us
Level: Choose User + Password
User DN: ImUrHuckleBerry
Password: SuperCrypticPassword

Active Directory variables were setup in D:\www\utils\mail\config\ in The Config Files Post.
Need to mod
Open D:\www\utils\mail\program\include\ Search for and Change
Code: [Select]
// Change 01/01/07
// Change this for filtering options.
//$this->filter = "(cn=*)";
$this->filter = ($this->prop['filter']);";

Same file D:\www\utils\mail\program\include\ Search for and Change
Code: [Select]
 * Establish a connection to the LDAP server
 function connect()
  if (!function_exists('ldap_connect'))
   raise_error(array('type' => 'ldap', 'message' => "No ldap support in this installation of PHP"), true);

  if (is_resource($this->conn))
   return true;
  if (!is_array($this->prop['hosts']))
   $this->prop['hosts'] = array($this->prop['hosts']);

  foreach ($this->prop['hosts'] as $host)
   if ($lc = @ldap_connect($host, $this->prop['port']))
    ldap_set_option($lc, LDAP_OPT_PROTOCOL_VERSION, $this->prop['version']);
    $this->prop['host'] = $host;
    $this->conn = $lc;
    // Change 05/10/07

Offline Bcrosswize

  • Jr. Member
  • **
  • Posts: 10
PHP Info Page from Active Directory
« Reply #6 on: May 16, 2007, 10:49:12 PM »
Code: [Select]
//this is the main code
$USER_ID = &quot;ImUrHuckleBerry&quot;;
$PWD = &quot;SuperCrypticPassword&quot;;
//$dn = &quot;OU=Staff,OU=Accounts,OU=Elementry School,OU=Southtown School District,DC=southtown,DC=k12,DC=mo,DC=us&quot;;
$dn = &quot;OU=Southtown School District,DC=southtown,DC=k12,DC=mo,DC=us&quot;;
$ad ldap_connect(&quot;;, &quot;389&quot;)
or die(&quot;Couldn't connect to AD!&quot;);
ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3);
//ldap_set_option($ad, LDAP_OPT_REFERRALS, 0);
$bd = ldap_bind($ad,$USER_ID,$PWD)
or die(&quot;Couldn'
t bind to AD!&quot;);
$filter = &quot;(sn=*)&quot;; //cn=*, mail=*, givenname=*, sn=*
$result ldap_search($ad$dn,$filter);
$entries ldap_get_entries($ad$result);

  for (
$i=0$i<$entries[&quot;count&quot;]; $i++)
$entries[$i][&quot;displayname&quot;][0].&quot; &quot;;
$entries[$i][&quot;mail&quot;][0].&quot;<br />&quot;;

Note: Criteria for "ThIs NaMe" in ($entries[$i]["ThIs NaMe"]) needs to be in lower case (IE: telephonenumber not telephoneNumber)

Offline Bcrosswize

  • Jr. Member
  • **
  • Posts: 10
Tips, Tricks, and Wishes
« Reply #7 on: May 16, 2007, 10:50:39 PM »
  phpMyAdmin is your friend.
  hMailServer is Sweeeeet // like concentrated honey
  Smile... it no crack face.

  organization and reply_to
   Upon Creation of user in the roundcube database I wanted their fields in identities for organization and reply_to automatically generated.
   Notes: Had to fix my Wishs reply-to (listed below) first.
   Fix as follows.
Code: [Select]
Work in progress.
  No new Identities for my users
    I don’t want my users to be able to make new Identities. Location: Menu Personal Setting Tab Identities
    This is a brutal hack. Was not exactly what I was looking for but its what I've settled with… for the time being.
    Hope someone has a better solution.
    Fix as follows.
Code: [Select]
Work in progress.
  Active Directory Address Book Showing Accounts that I don't want.
    Acounts like postmaster, webmaster and Lunch are in my Address Book from Active Directory.
    I'm sure there is a better way to do this; but here is my fix. /hand behind ear listening for a reply
    Fix as follows.
Code: [Select]
Work in progress.
    I wish the database did not use reply-to. I have fixed this by renaming it to reply_to in the database and mail files that use it.
    This is related to a bug in MySQL with Hyphens (IE:"-").
    Fix as follows.
Code: [Select]
Work in progress.

Offline Bcrosswize

  • Jr. Member
  • **
  • Posts: 10
« Reply #8 on: May 17, 2007, 09:55:24 AM »
I’m a very poor speller. I run everything through word but that doesn’t catch it all. If you catch any errors please let me know and I will fix them. ;)

I don’t claim to be a programmer. If you see a better way to do what I have done please post it and I will change my tutorial. Thanks in advance for any suggestions.

This tutorial was composed while viewing through Intenet Explorer 6 at 1280 by 1024. If the format is jacked, its more then likely Microsofts fault :)

Note: Code was used from many places. Would like to thank the original authors but my memory fails.