How to Install Roundcube in CentOS

Last modified: July 30, 2020
You are here:
Estimated reading time: 5 min

Roundcube is also known as webmail. Webmail is any email client that is running on web server.  It allows the user to access their email through web browser as long as an internet connection is available. In this tutorial we can check how to install Roundcube in CentOS. To do this, please follow the below given steps:

 

Install web server

Any web server can be used to install Roundcube. We can start by installing NGINX web server. First, we need to add the EPEL package to CentOS server, so that we can install NGINX.

# yum install epel-release

# yum install nginx

Configure the server to start NGINX upon reboot.

# systemctl start nginx

# systemctl enable nginx

 

Install and run MariaDB

For installing MariaDB server follow the commands below.

# yum install mariadb-server

Enable MariaDB to start on boot and then start the service.

# systemctl enable mariadb

# systemctl start mariadb

 

Download and install Roundcube

Follow the below steps to install and configure latest version of Roundcube.

1) Install the following PHP packages.

# yum install php php-common php-json php-xml php-mbstring php-imap php-pear-DB php-mysql

Once the above packages list is installed, then set the time zone value in PHP.

# vi /etc/php.ini

date.timezone= EST

 

2) Create and configure Roundcube Database.

Login to MySQL through command line.

# mysql -u root -p

Create database for Roundcube.

# mysql;> create database roundcubedb;

# mysql;> use roundcubedb;

Create user for Roundcube database and allow all permission to that user.

# mysql;>  create user usercube identified by password ‘usercube’;

mysql;> grant all privileges on roundcubedb.* to ‘usercube’ identified by ‘usercube’;

 

3) Download and install Roundcube.

Navigate to /tmp and download the latest Roundcube and copy it to the Webroot “/usr/share/nginx/roundcube” and extract the zip file.

# cd /tmp

# wget http://nchc.dl.sourceforge.net/project/roundcubemail/roundcubemail/1.1.3/roundcubemail-1.1.3-complete.tar.gz

Extract and copy the downloaded file to your webserver document root.

# tar -zxpvf roundcubemail-1.1.3-complete.tar.gz -C /usr/share/nginx/roundcube/

Rename the extracted file.

# mv roundcubemail-1.1.3 roundcube

Restart the Nginx service.

# systemctl restart nginx

 

Install Roundcube in web browser

open URL: http://yourhostname/roundcube/installer to initialize the Roundcube installation. You can install required PHP extension if it is not installed on your server. Then click on create config page. You can assign your database details created earlier as well as your imap and smtp server details. Once done this you can click “continue”. In next screen, you will be asked to initialize the database. Next screen will be to test your mail server smtp and imap feature. After this you can close the browser.

For securing webmail remove the installer directory from the document root.

# rm -rf installer /usr/share/nginx/roundcube

 

Roundcube with Postfix, Dovecot and MariaDB

1) Install required packages.

# yum install postfix

# yum install dovecot dovecot-mysql

 

2) Create and configure database.

Create a database for your mail server and add a user and grant full permission to that user.

# mysql;>CREATE DATABASE mail;

# mysql;>USE mail;

# mysql:> grant all privileges on mail.* to ‘mail_admin’@’localhost’ identified by ‘password’;

# mysql:> grant all privileges on mail.* to ‘mail_admin’@’localhost.localdomain’ identified by ‘password’;

# mysql;>FLUSH PRIVILEGES;

Create the virtual domains table.

# mysql;>CREATE TABLE domains (domain varchar(50) NOT NULL, PRIMARY KEY (domain) );

Create a transports table.

# mysql;> CREATE TABLE transport ( domain varchar(128) NOT NULL default ”, transport varchar(128) NOT NULL default ”, UNIQUE KEY domain (domain) );

 

3) Bind MariaDB to localhost by editing /etc/my.cnf.

# vi /etc/y.cnf

bind-address=127.0.0.1

Restart MariaDB.

# systemctl restart mariadb

 

Configure Postfix to work with MariaDB

1) Create a virtual domain configuration file for Postfix named /etc/postfix/mysql-virtual_domains.cf and paste the code.

# vi /etc/postfix/mysql-virtual_domains.cf

user = mail_admin

password = password (password for your mail_admin user)

dbname = mail

query = SELECT domain AS virtual FROM domains WHERE domain=’%s’

hosts = 127.0.0.1

 

2) Create a virtual mail forwarding file for fostfix called /etc/postfix/mysql-virtual_forwardings.cf and paste the code.

# vi /etc/postfix/mysql-virtual_forwardings.cf

user = mail_admin

password = password

dbname = mail

query = SELECT destination FROM forwardings WHERE source=’%s’

hosts = 127.0.0.1

 

3) Create a virtual mailbox configuration file for postfix called /etc/postfix/mysql-virtual_mailboxes.cf and paste the code.

# vi /etc/postfix/mysql-virtual_mailboxes.cf

user = mail_admin

password = password

dbname = mail

query=SELECT CONCAT(SUBSTRING_INDEX(email,’@’,-1),’/’,SUBSTRING_INDEX(email,’@’,1),’/’) FROM users WHERE email=’%s’

hosts = 127.0.0.1

 

4) Create a virtual email mapping file for postfix called /etc/postfix/mysql-virtual_email2email.cf.

# vi /etc/postfix/mysql-virtual_email2email.cf

user = mail_admin

password = password

dbname = mail

query = SELECT email FROM users WHERE email=’%s’

hosts = 127.0.0.1

 

5) Secure this file by changing the file permission to allow users in the postfix group to access this file.

# chmod o= /etc/postfix/mysql-virtual_*.cf

# chgrp postfix /etc/postfix/mysql-virtual_*.cf

 

6) Create a user and group for handling the mail. All virtual mailboxes are stored in the home directory of this user.

# groupadd mailuser;

# useradd -g mailuser -u mailuser -d /home/mailuser -m

 

7) Complete the remaining steps required for postfix configuration. Please replace ” server.example.com” with your exact hostname.

# postconf -e ‘myhostname = server.example.com’

# postconf -e ‘mydestination = localhost, localhost.localdomain’

# postconf -e ‘mynetworks = 127.0.0.0/8’

# postconf -e ‘inet_interfaces = all’

# postconf -e ‘message_size_limit = 30720000’

# postconf -e ‘virtual_alias_domains =’

# postconf -e ‘virtual_alias_maps= proxy:mysql:/etc/postfix/mysql-virtual_forwardings.cf, mysql:/etc/postfix/mysql-virtual_email2email.cf’

# postconf -e

‘virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql-virtual_domains.cf’

# postconf -e

‘virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql-virtual_mailboxes.cf’

# postconf -e ‘virtual_mailbox_base = /home/mailuser’

# postconf -e ‘virtual_uid_maps = static:5000’

# postconf -e ‘virtual_gid_maps = static:5000’

# postconf -e ‘smtpd_sasl_type = dovecot’

# postconf -e ‘smtpd_sasl_path = private/auth’

# postconf -e ‘smtpd_sasl_auth_enable = yes’

# postconf -e ‘broken_sasl_auth_clients = yes’

# postconf -e ‘smtpd_sasl_authenticated_header = yes’

# postconf -e

‘smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination’

# postconf -e ‘smtpd_use_tls = yes’

# postconf -e ‘smtpd_tls_cert_file = /etc/pki/dovecot/certs/dovecot.pem’

# postconf -e ‘smtpd_tls_key_file = /etc/pki/dovecot/private/dovecot.pem’

# postconf -e ‘virtual_create_maildirsize = yes’

# postconf -e ‘virtual_maildir_extended = yes’

# postconf -e

‘proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $virtual_mailbox_limit_maps’

# postconf -e ‘virtual_transport = dovecot’

# postconf -e ‘dovecot_destination_recipient_limit = 1’

 

8) Add Dovecot service to bottom of the postfix configuration file.

# vi /etc/postfix/master.cf

dovecot   unix  –       n       n       –       –       pipe

flags=DRhu user=mailuser:mailuser argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}

Uncomment the lines starting with submission and smtps and the block of lines stating with -o after  each in /etc/pstfix/master.cf. The first section of master.cf resembles the following:

# vi /etc/postfix/master.cf

# Postfix master process configuration file.  For details on the format

# of the file, see the master(5) manual page (command: “man 5 master”).

#

# Do not forget to execute “postfix reload” after editing this file.

#

# ==========================================================================

# service type  private unpriv  chroot  wakeup  maxproc command + args

#               (yes)   (yes)   (yes)   (never) (100)

# ==========================================================================

smtp      inet  n       –       –       –       –       smtpd

#smtp      inet  n       –       –       –       1       postscreen

#smtpd     pass  –       –       –       –       –       smtpd

#dnsblog   unix  –       –       –       –       0       dnsblog

#tlsproxy  unix  –       –       –       –       0       tlsproxy

submission inet n       –       –       –       –       smtpd

-o syslog_name=postfix/submission

-o smtpd_tls_security_level=encrypt

-o smtpd_sasl_auth_enable=yes

-o smtpd_client_restrictions=permit_sasl_authenticated,reject

-o milter_macro_daemon_name=ORIGINATING

smtps     inet  n       –       –       –       –       smtpd

-o syslog_name=postfix/smtps

-o smtpd_tls_wrappermode=yes

-o smtpd_sasl_auth_enable=yes

-o smtpd_client_restrictions=permit_sasl_authenticated,reject

-o milter_macro_daemon_name=ORIGINATING

Enable postfix to start on boot and then start the service.

# systemctl enable postfix

# systemctl start postfix

 

Congrats now you have successfully configured postfix!!!

 

Configure Dovecot

1) Move the existing dovecot configuration file.

# mv /etc/dovecot/dovecot.conf /etc/dovecot/dovecot.conf-backup

2) Paste the below code to the new dovecot.conf file.

# vi /etc/dovecot/dovecot.conf

protocols = imap pop3

log_timestamp = “%Y-%m-%d %H:%M:%S ”

mail_location = maildir:/home/mailuser/%d/%n/Maildir

ssl_cert = </etc/pki/dovecot/certs/dovecot.pem

ssl_key = </etc/pki/dovecot/private/dovecot.pem

namespace {

type = private

separator = .

prefix = INBOX.

inbox = yes

}

 

service auth {

unix_listener auth-master {

mode = 0600

user = mailuser

}

 

unix_listener /var/spool/postfix/private/auth {

mode = 0666

user = postfix

group = postfix}

 

user = root

}

 

service auth-worker {

user = root

}

 

protocol lda {

log_path = /home/mailuser/dovecot-deliver.log

auth_socket_path = /var/run/dovecot/auth-master

postmaster_address = [email protected]

}

 

protocol pop3 {

pop3_uidl_format = %08Xu%08Xv

}

 

passdb {

driver = sql

args = /etc/dovecot/dovecot-sql.conf.ext

}

 

userdb {

driver = static

args = uid=5000 gid=5000 home=/home/mailuser/%d/%n allow_all_users=yes

}

 

3) For storing Password information, we need to create a file named /etc/dovecot/dovecot-sql.conf.ext and insert the code below into the file.

# vi /etc/dovecot/dovecot-sql.conf.ext

driver = mysql

connect = host=127.0.0.1 dbname=mail user=mail_admin password=password

default_pass_scheme = CRYPT

password_query = SELECT email as user, password FROM users WHERE email=’%u’;

 

4) Secure this file by changing the file permission to allow users in the dovecot group to access it.

# chgrp dovecot /etc/dovecot/dovecot-sql.conf.ext

# chmod o= /etc/dovecot/dovecot-sql.conf.ext

Enable dovecot to start on boot and then start the service.

# systemctl enable dovecot.service

# systemctl start dovecot.service

 

Setup domains and user to access the Roundcube

Log into the MariaDB shell.

# mysql -u root -p

Switch to the mail database.

# mysql;>USE mail;

# mysql;>INSERT INTO domains (domain) VALUES (‘yourdoamin.com’);

# mysql;>INSERT INTO users (email, password) VALUES (‘[email protected]’, ENCRYPT(‘password’));

# mysql;>quit

 

This completes the configuration for a new domain and email user.

 

If you need any further assistance please contact our support department.

 

Was this article helpful?
Dislike 0
Views: 9