How to get rid Virtualmin of Usermin for webmail so that Roundcube is the default

On a stock Virtualmin server, the default is Usermin for webmail. However, the industry standard appears to be RoundCube. There is some template manipulation you can do to fix the defaults, or you can use this script on legacy servers.

cat webmail-alias
#!/bin/bash

# Usage: ./webmail-alias example.com anchor.example.com

set -e

if [ -z "$1" ]; then
echo "Usage: $0 domain-name anchor-domain"
exit 1
fi

DOMAIN="$1"
ANCHOR="$2"
CONFIG_FILE="/etc/apache2/sites-available/$DOMAIN.conf"
WEBMAIL="webmail.${DOMAIN}"

if [ ! -f "$CONFIG_FILE" ]; then
echo "Apache config file not found: $CONFIG_FILE"
exit 2
fi

date
echo "Inspecting file: $CONFIG_FILE"
echo "Searching for lines related to '$WEBMAIL'..."

MATCHED=$(grep -E "ServerAlias.*$WEBMAIL|RewriteCond.*$WEBMAIL|RewriteRule.*20000" "$CONFIG_FILE")

if [ -z "$MATCHED" ]; then
echo "No matching lines found for $WEBMAIL"
exit 0
fi

echo "The following lines will be removed:"
echo "$MATCHED"
echo
read -rp "Press ENTER to proceed with removal, or CTRL+C to abort..."

# Make a backup
cp "$CONFIG_FILE" "$CONFIG_FILE.bak"

# Remove the matching lines
sed -i "/ServerAlias.*$WEBMAIL/d" "$CONFIG_FILE"
sed -i "/RewriteCond.*$WEBMAIL/d" "$CONFIG_FILE"
sed -i "/RewriteRule.*20000/d" "$CONFIG_FILE"

echo
echo "Done. Verifying that lines have been removed:"
grep -E "$WEBMAIL|20000" "$CONFIG_FILE" || echo "✅ Cleaned successfully."

echo
read -rp "Next, adding $WEBMAIL to $ANCHOR. Press ENTER: " CONFIRM

echo "Creating alias with Virtualmin..."
virtualmin create-domain --domain "$WEBMAIL" --alias "$ANCHOR" --dns --web
echo "✅ Alias created."
date

Share this article

Leave a Reply

Your email address will not be published. Required fields are marked *