How to install and configure Roundcube (webmail)

Posted by Md. Mahidul Hasan on 3:27 AM with 4 comments
How to install and configure Roundcube (webmail)

Install webserver and database:
~# apt-get install apache2 mysql-server php5 php5-mcrypt phpmyadmin -y

Install Roundcube from tar file:
~# mkdir /var/www/webmail/
~# cd /var/www/
~# wget http://sourceforge.net/projects/roundcubemail/files/roundcubemail/0.7/roundcubemail-0.7.tar.gz
~# tar xfz roundcubemail-0.7.tar.gz
~# mv roundcubemail-0.7/* webmail
~# rm roundcubemail-0.7.tar.gz
~# rm -rf roundcubemail-0.7
~# cd webmail
~# chown -R www-data:www-data temp/ logs/
~# mysql -u root -p (enter the given password while installing MYSQL )

CREATE DATABASE roundcubemail;
GRANT ALL PRIVILEGES ON roundcubemail.* TO mithupcs@localhost IDENTIFIED BY 'mithupcs';
FLUSH PRIVILEGES;

For Configuring RoundCube:
Now point your browser to http://172.16.0.1/webmail/installer/ and you will find tow NOT OK responding error
message. Don't worry about NOT AVAILABLE ERROR.(ignore them....) Do as follows.........

~# cd /etc/php5/apache2/conf.d
~# vim suhosin.ini   (To change the suhosin entry....)
The error message is [ suhosin.session.encrypt: NOT OK]

Solution:
remove the ( ; ) sign from infront of the line & set its value (off)

Another error message is date.timezone NOT OK.....
Have to change the date.timezone to  Asia / Dacca

Solution:
cd /etc/php5/apache2/
vim php.ini

remove the ( ; ) sign from infront of the line & set its value
date.timezone = 'Asia/Dacca'

If everything is okay click
"START INSTALLATION". The installer checks if everything is there. In case you see some red NOT OK
messages, you need to install or enable something. Follow the links to see what has to be done.

If everything checks out fine you are ready to create the configuration files, click "NEXT" to get
 there. Get through the form and change the settings according to your needs. Do not forget to enter
 the database setting that we made earlier within the "Database Setup" section.

DATABASE SETUP:
Database Server   : localhost
Database Name     : roundcubemail
Database UserName : mithupcs
Database Password : mithupcs

IMAP Settings:
default_host : localhost
default_port : 143

SMTP Settings:
smtp_server : localhost

When you are finished hit the "CREATE CONFIG" button and you will get two text boxes with the information
 for main.inc.php and db.inc.php.  Download this two file and paste them into /var/www/webmail/config directory.

Finally click "CONTINUE" and get to the last step of the installation process. Your configuration will
 now be verified and tested against your webserver. Click "Initialize database" to create the necessary
 tables in your database.

If there are no red NOT OK messages, you can also try to send a mail in order to test the SMTP settings.

Last but not least you have to remove the whole installer directory from the webserver. If this remains
active it can expose the configuration including passwords. We do this with the following command:

Test SMTP Config
Sender   : mehedi@mithu.com (Domain should be included...)
Receipent: hasan@mithu.com  (Domain should be included...)

Test IMAP Config
Username : mehedi (Only give the user name, not along with domain... )
Password : ******

FINAL TOUCH AFTER COMPLETION OF ROUNDCUBE CONFIG 
Don't forget to remove the mail installer forlder after successful roundcube config...
# rm -rf /var/www/webmail/installer

For everyone to be able to access his webmail (under his domain name) you have to create or edit
the file /etc/apache2/conf.d/roundcube.conf and add the alias "/webmail" and some more information
about the directories:
~# vim /etc/apache2/conf.d/roundcube.conf

Copy and paste the following script:
# RoundCube alias and redirect functions
Alias /webmail /var/www/webmail
<Directory /var/www/webmail>
  Options +FollowSymLinks
  # This is needed to parse /var/www/webmail/.htaccess. See its
  # content before setting AllowOverride to None.
  AllowOverride All
  order allow,deny
  allow from all
</Directory>
# Protecting basic directories:
<Directory /var/www/webmail/config>
        Options -FollowSymLinks
        AllowOverride None
</Directory>
<Directory /var/www/webmail/temp>
        Options -FollowSymLinks
        AllowOverride None
        Order allow,deny
        Deny from all
</Directory>
<Directory /var/www/webmail/logs>
        Options -FollowSymLinks
        AllowOverride None
        Order allow,deny
        Deny from all
</Directory>
<IfModule mod_rewrite.c>
  <IfModule mod_ssl.c>
    <Location /webmail>
      RewriteEngine on
      RewriteCond %{HTTPS} !^on$ [NC]
      RewriteRule . https://www.yourdomain.com:8080/webmail/  [L]
    </Location>
  </IfModule>
</IfModule>

Final TWEAKS
~# vim /var/www/webmail/config/main.inc.php

Give the following values as given below:
[...]
$rcmail_config['message_cache_lifetime'] = '30m';
[...]
$rcmail_config['default_host'] = 'localhost';
[...]
$rcmail_config['smtp_server'] = '%h';
[...]
$rcmail_config['session_lifetime'] = 30;
[...]
$rcmail_config['create_default_folders'] = TRUE;
[...]

Now go to http://yourServerIp/webmail to access the newly created webmail interface.


Trouble Shooting:
Problem: IF WEBSPACE doesn't user MOD-PHP then do the following....
~# vim /etc/apache2/conf.d/roundcube.conf
Submitted by xxs (not registered) on Fri, 2012-01-06 20:07.
~# vim /etc/apache2/conf.d/roundcube.conf

must be
# RoundCube alias and redirect functions
Alias /webmail /var/www/webmail
<Directory /var/www/webmail>
  Options +FollowSymLinks
  # This is needed to parse /var/www/webmail/.htaccess. See its
  # content before setting AllowOverride to None.
  AllowOverride All
  order allow,deny
  allow from all

        <IfModule mod_php5.c>
                AddType application/x-httpd-php .php

                php_flag magic_quotes_gpc Off
                php_flag track_vars On
                php_flag register_globals Off
                php_value include_path .
        </IfModule>

</Directory>
# Protecting basic directories:
<Directory /var/www/webmail/config>
        Options -FollowSymLinks
        AllowOverride None
</Directory>
<Directory /var/www/webmail/temp>
        Options -FollowSymLinks
        AllowOverride None
        Order allow,deny
        Deny from all
</Directory>
<Directory /var/www/webmail/logs>
        Options -FollowSymLinks
        AllowOverride None
        Order allow,deny
        Deny from all
</Directory>

To make sure it is working if the customer web-space doesn't use mod_php