Learn how to install and configure Roundcube Webmail on Ubuntu (16.04, 18.04, and 18.10) using Apache2, MariaDB, and PHP 7.2. This guide is optimized for cloud instances like Vultr or DigitalOcean.
Prerequisites
Before you begin the installation, please ensure your environment meets the following requirements:
- OS: An Ubuntu 16.04, 18.04 LTS, or 18.10 x64 instance.
- Access: Logged in as a user with sudo privileges.
- LAMP Stack Requirements:
- Apache2: Installed and running. Follow these instructions to set it up.
- MariaDB: Installed and secured. Follow these instructions to prepare your database server.
- PHP 7.2: Installed with required extensions (
php7.2-xml,php7.2-mbstring,php7.2-intl,php7.2-zip,php7.2-mysql, andphp7.2-gd). Follow these instructions for the full installation guide.
Step 1: Create Roundcube Database
Initially, Roundcube requires a dedicated database to store user preferences and contacts. Therefore, you must run the following commands to set up the MariaDB database and user.
First, log in to the MariaDB shell:
sudo mysql -u root -p
Next, create the database and user. Execute these SQL queries one by one, making sure to replace your_secure_password with a real one:
CREATE DATABASE roundcube;
CREATE USER 'roundcubeuser'@'localhost' IDENTIFIED BY 'your_secure_password';
GRANT ALL PRIVILEGES ON roundcube.* TO 'roundcubeuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Step 2: Download and Configure Roundcube
Now that the database is ready, we will download the Roundcube source files and move them to your web root.
Download the latest stable release using wget:
cd /tmp
wget https://github.com/roundcube/roundcubemail/releases/download/1.3.9/roundcubemail-1.3.9-complete.tar.gz
After the download completes, extract the archive and move the files to the web directory:
tar -xvzf roundcubemail-1.3.9-complete.tar.gz
sudo mv roundcubemail-1.3.9 /var/www/html/roundcube
Subsequently, import the initial SQL schema to populate the database tables:
cd /var/www/html/roundcube
sudo mysql -u roundcubeuser -p roundcube < SQL/mysql.initial.sql
Finally, set the correct permissions. You need to grant Apache ownership of the directory and secure the file access levels:
sudo chown -R www-data:www-data /var/www/html/roundcube/
sudo find /var/www/html/roundcube/ -type d -exec chmod 750 {} \;
sudo find /var/www/html/roundcube/ -type f -exec chmod 640 {} \;
Step 3: Configure Apache2
Once the files are in place, you must create a Virtual Host file so Apache knows how to serve your webmail.
Start by creating the configuration file:
sudo nano /etc/apache2/sites-available/roundcube.conf
Then, paste the following configuration into the editor. Be sure to update ServerName and ServerAdmin to reflect your actual details:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/roundcube
ServerName example.com
<Directory /var/www/html/roundcube/>
Options FollowSymlinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
To apply these changes, enable the site and reload the Apache service:
sudo a2ensite roundcube.conf
sudo systemctl reload apache2.service
Step 4: Final Web Installer
At this point, the server configuration is complete. You can now finish the setup via your browser by navigating to:
[https://example.com/installer](https://example.com/installer)
Important Note: After you have completed the web setup, it is highly recommended to delete the /installer directory for security purposes. You can do this by running: sudo rm -rf /var/www/html/roundcube/installer