As promised, here is my setup. It does not touch any Plesk files, except ones that we are allowed to change by design. However, it's late and it is a quick write-up. Keep that in mind.
Make sure you have root access on the server. If you don't know how to handle it, please, don't continue. I am not responsible for damage of any kind. Use at your own risk! The following commands are issued on a CentOS 7.7 machine (RHEL and CloudLinux should be quite the same, but haven't tested). For Debian users: the paths might vary. Please handle with care!
First, we create the roundcube user and group:
Bash:
mkdir /usr/share/custom-roundcube
groupadd custom_roundcube_sysgroup
useradd custom_roundcube_sysuser -N -g custom_roundcube_sysgroup -c "custom roundcube webmail user" -M -d /usr/share/custom-roundcube -s /sbin/nologin
Deploy Roundcube:
Bash:
cd /usr/share/custom-roundcube/
wget https://github.com/roundcube/roundcubemail/releases/download/1.4.3/roundcubemail-1.4.3-complete.tar.gz
tar xfz roundcubemail-1.4.3-complete.tar.gz --strip-components=1
rm -f roundcubemail-1.4.3-complete.tar.gz
rm -rf CHANGELOG INSTALL LICENSE README.md UPGRADING composer.* public_html temp logs
rm -f installer/* installer/.htaccess
mv .htaccess /etc/httpd/conf/plesk.conf.d/custom.roundcube.htaccess.inc
cp /usr/share/psa-roundcube/installer/.htaccess installer
Create a custom roundcube config and and log dir:
Bash:
mkdir -p /etc/custom-webmail/roundcube
cd /etc/custom-webmail/roundcube
cp /etc/psa-webmail/roundcube/php.ini .
mkdir /var/log/custom-roundcube
chown custom_roundcube_sysuser:root /var/log/custom-roundcube
chmod 0750 /var/log/custom-roundcube/
Next, the database section.
In Plesk (ISP View), go to
Tools & Settings -> Database Servers -> MariaDB -> Click the icon next to 'Databases' in the table. It should open phpMyAdmin as root.
Create a user
custom_roundcube
,
do not grant any permissions yet, nor use the create database with same name option. Use the generate function of PMA to create a password or use your own random one, mark down the password (not the one you're using everywhere else, do you? ;-)).
Next, create a database
custom_roundcubemail
.
Then, go to the
custom_roundcube
user you just created (PMA Home -> User accounts -> edit privileges for
custom_roundcube
, click the databases tab, select
custom_roundcubemail
in the list and click 'Go'.
Grant everything under the 'Data' tab, 'CREATE, ALTER, INDEX, DROP' under 'Structure' and 'REFERENCES' under Administration. Click 'Go'.
Now, navigate to the
custom_roundcubemail
database page and click import. Import the SQL file in
/usr/share/custom-roundcube/SQL/mysql.initial.sql
. Use SCP to get the file on your computer or download the tar file and extract the corresponding file from it.
Next, we configure Roundcube:
Bash:
cd /usr/share/custom-roundcube/config/
mv defaults.inc.php defaults.inc.php.pkg-default
rm -f .htaccess
cp ../../psa-roundcube/config/config.inc.php .
chown root:custom_roundcube_sysgroup config.inc.php
cp ../../psa-roundcube/config/defaults.inc.php .
chown root:custom_roundcube_sysgroup defaults.inc.php
cp ../../psa-roundcube/config/.htaccess .
# Plugin configs:
cp /usr/share/psa-roundcube/plugins/password/config.inc.php /usr/share/custom-roundcube/plugins/password
chown root:custom_roundcube_sysgroup /usr/share/custom-roundcube/plugins/password/config.inc.php
cp /usr/share/psa-roundcube/plugins/managesieve/config.inc.php /usr/share/custom-roundcube/plugins/managesieve
chown root:custom_roundcube_sysgroup /usr/share/custom-roundcube/plugins/managesieve/config.inc.php
cp /usr/share/psa-roundcube/plugins/markasjunk2/config.inc.php /usr/share/custom-roundcube/plugins/markasjunk
chown root:custom_roundcube_sysgroup /usr/share/custom-roundcube/plugins/markasjunk/config.inc.php
We need to edit /usr/share/custom-roundcube/config/config.inc.php:
$config['db_dsnw'] = 'mysql://custom_roundcube:your_unique_password@localhost/custom_roundcubemail';
Next, save the mysql password (single line) in /usr/share/custom-roundcube/config/.roundcube.shadow
Next, we need to edit /usr/share/custom-roundcube/config/defaults.inc.php (lines to change, use search):
PHP:
// yep, no password this time
$config['db_dsnw'] = 'mysql://custom_roundcube:@localhost/custom_roundcubemail';
// change the logging directory to the one we created before
$config['log_dir'] = '/var/log/custom-roundcube/';
// markasjunk and markasjunk2 plugins have been merged
$config['plugins'] = array('password', 'markasjunk', 'managesieve');
// enable that sweet, slick looking responsive goodness...
$config['skin'] = 'elastic';
At this point, we need to make sure plesk serves us our own, custom roundcube. Luckily, Plesk allows us to modify the templates that are used to generate config files on the fly. (Overriding generated configs is pointless as they will be overwritten by every action)
Bash:
mkdir -p /usr/local/psa/admin/conf/templates/custom/webmail/
Please note that files we want to touch go inside the templates/
custom folder,
always leave templates/default untouched. You can, off course, copy files from the default to custom folder and change to your likings. But
never edit a file inside the default folder.
Create the file /usr/local/psa/admin/conf/templates/custom/webmail/roundcube.php with the following content (if you followed the above instructions exactly, this should suffice):
PHP:
<?php
/** @var Template_VariableAccessor $VAR */
$roundcubeDocroot = "/usr/share/custom-roundcube";
$roundcubeConfD = "/etc/custom-webmail/roundcube";
$roundcubeSysUser = "custom_roundcube_sysuser";
$roundcubeSysGroup = "custom_roundcube_sysgroup";
$roundcubeHtaccess = $VAR->server->webserver->httpConfDir . "/plesk.conf.d/custom.roundcube.htaccess.inc";
$roundcubePhpIni = $roundcubeConfD . "/php.ini";
?>
DocumentRoot "<?php echo $roundcubeDocroot ?>"
Alias /roundcube/ "<?php echo $roundcubeDocroot ?>/"
<IfModule mod_suexec.c>
SuexecUserGroup <?php echo $roundcubeSysUser; ?> <?php echo $roundcubeSysGroup; ?>
</IfModule>
<IfModule mod_fcgid.c>
FcgidInitialEnv PP_CUSTOM_PHP_CGI_INDEX plesk-php73-fastcgi
FcgidInitialEnv PP_CUSTOM_PHP_INI "<?php echo $roundcubePhpIni; ?>"
FcgidMaxRequestLen 134217728
<Directory "<?php echo $roundcubeDocroot ?>">
Options -Indexes +FollowSymLinks
AllowOverride FileInfo
<?php if ($VAR->server->webserver->apache->useRequireOption): ?>
Require all granted
<?php else: ?>
Order allow,deny
Allow from all
<?php endif; ?>
Include "<?php echo $roundcubeHtaccess ?>"
<Files ~ (\.php$)>
SetHandler fcgid-script
FCGIWrapper <?php echo $VAR->server->webserver->apache->phpCgiBin ?> .php
Options +ExecCGI
</Files>
</Directory>
</IfModule>
Next, run:
/usr/local/psa/admin/sbin/httpdmng --reconfigure-all
If everything went well, you should see a brand new Roundcube instance when going to webmail.<domain>.
As pointed out by
@HHawk , I overlooked the fail2ban part. Enabling it is easy:
In "/etc/fail2ban/jail.d/plesk.conf" duplicate the
[plesk-roundcube]
section and change to:
INI:
[custom-roundcube]
action = iptables-multiport[name="plesk-roundcube", port="http,https,7080,7081"]
filter = plesk-roundcube
logpath = /var/log/custom-roundcube/errors.log
Next, issue
service fail2ban restart
Ad pointed out by
@justinmacleod, I forgot to symlink the well-known folder to keep LetsEncrypt functioning correctly. I ran into this issue myself and fixed it, but forgot to mention it here:
Code:
ln -s /usr/share/psa-roundcube/.well-known /usr/share/custom-roundcube/.well-known
Also, check if there are log files (error and sendmail) in /var/log/custom-roundcube (the latter gets created after sending a mail).
Congrats, you just beat the Plesk marketing team.
How to undo? Should be as easy as:
Bash:
userdel custom_roundcube_sysuser
groupdel custom_rouncube_sysgroup
rm -rf /usr/share/custom-roundcube /etc/custom-webmail /var/log/custom-roundcube
rm -f /usr/local/psa/admin/conf/templates/custom/webmail/roundcube.php /etc/httpd/conf/plesk.conf.d/custom.roundcube.htaccess.inc
/usr/local/psa/admin/sbin/httpdmng --reconfigure-all
For completeness, remove the database and corresponding user and remove the
[custom-roundcube]
section from fail2ban's config.
Really, that's it. I still need to look to proper log rotation and maybe SELinux policies. But let's hope Plesk updates Roundcube for us, as they should do as a company that cares about their users... Right? ;-)