How to Configure Postfix with Webmail on Ubuntu 18.04

postfix roundcube webmail ubuntu

We have shown in the first part of our tutorial how to install and configure Postfix on Ubuntu 18.04 with Dovecot, MySql, Nginx, Postfixadmin with which we have created the virtual domains and users. Now we are able to send email on our server but all is done in command line but the virtual users don't have a way to connect in order to send mail. In this part, RoundCube will give an interface for our virtual users to connect, send emails and manage their mailboxes while PhpMyAdmin to easily manage our Database for any manipulation.

This is the second part of our tutorial which will show the configuration of postfix with RoundCube and PhpMyAdmin on Ubuntu 18.04.


In order to complete this part of our article, you need to have

  • an Ubuntu 18.04 server
  • a web server and database management already running such as Nginx and Mysql in our case.
  • postfix already running on your server
  • mails accounts to test the connection on roundcube and sending email

Recommended read

1) Install and configure phpmyadmin

You can install phpmyadmin directly from the official repositories or from the sources.

a) Install phpmyadmin

Phpmyadmin is present in the official repositories of Ubuntu 18.04 so

# apt update && apt install phpmyadmin

During the installation process, you will be asked for some questions. First the web server to use with phpmyadmin. In our case, because our web server run on Nginx, don't choose any of the proposals

Now it will ask to automatically configure the database for phpmyadmin

Now set the mysql password for phpmyadmin

b) Configure phpmyadmin for web access

When phpmyadmin is installed, it's located in /usr/share/phpmyadmin but we need to tell Nginx how it can find and run it. We will create a symbolic link to our web root directory and rename phpmyadmin to pma

# ln -s /usr/share/phpmyadmin /var/www/html/pma

Then add the lines below to your Nginx configuration file in the server block lines

# vim /etc/nginx/sites-available/default
location /pma {
         root /var/www/html;
         index index.php;
         location ~ ^/pma/(.+\.php)$ {
                 try_files $uri =404;
                 fastcgi_pass unix:/run/php/php7.2-fpm.sock;
                 fastcgi_index index.php;
                 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                 include /etc/nginx/fastcgi_params;
         location ~* ^/pma/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
                 root /var/www/html;

Make sure that your configuration is correct

# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Then restart nginx.

# systemctl restart nginx

Now you can run your web browser with the address http://your-ip-or-domain/pma. If someone tries to use phpmyadmin instead of pma, he can't be able to access our database. You can use your postfix database credential to log in

Now you can see your postfix database information

Now you can manipulate your database as you want. You can also use your phpmyadmin credential to access its own database. Make sure to enter the password you used during the installation

2- Download and configure roundcube

Roundcube is present by default in the official repositories of Ubuntu 18.04 but we will use the installation from source to use the actual latest version 1.3.6. Go in the web root folder for the download

# cd /var/www/html && wget
--2018-06-18 13:08:37--
Resolving (,
Connecting to (||:443... connected.

Now decompress

# tar xvf roundcubemail-1.3.6-complete.tar.gz

verify the name that you have and rename it

# mv roundcubemail-1.3.6 webmail

Now delete the compressed file and go to the webmail directory

# rm roundcubemail-1.3.6-complete.tar.gz && cd webmail

a) Create the roundcube database

We need to create the roundcube database to store some information. This subpart will be not detailed here because you have the same configuration detailed in our tutorial How to Install Roundcube Webmail on Ubuntu 18.04

Log into mysql as root and follow the steps

mysql> CREATE DATABASE roundcubedb;
mysql> CREATE USER 'roundcube'@'localhost' IDENTIFIED BY 'your-roundcubedb-password';
mysql> GRANT ALL PRIVILEGES ON roundcubedb.* to 'roundcube'@'localhost';
mysql> EXIT;

Now import the initial tables for the roundcube database

# mysql -u roundcube -p roundcubedb < SQL/mysql.initial.sql
Enter password:

Now edit your default Nginx configuration file and add these lines in the server blocks

# vim /etc/nginx/sites-available/default
location /webmail {
        root /var/www/html;
        index index.php;
        location ~ ^/webmail/(.+\.php)$ {
                root /var/www/html;
                try_files $uri =404;
                fastcgi_index index.php;
                fastcgi_pass unix:/run/php/php7.2-fpm.sock;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include /etc/nginx/fastcgi_params;
        location ~ ^/webmail/(README|INSTALL|LICENSE|CHANGELOG|UPGRADING)$ {
                deny all;
        location ~ ^/webmail/(bin|SQL|config|temp|logs)/ {
               deny all;

Check your configuration

# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Then restart nginx

# systemctl restart nginx

b) Configuration of roundcube

We need to give the proper permissions using chmod command and ownership using chown command in order to have roundcube well running.

# chown -R www-data:www-data /var/www/html/webmail/
# chmod 755 /var/www/html/webmail/temp/ /var/www/html/webmail/logs/

Now you need to continue the installation process through your web browser. Notice that Roundcube runs a script called installer located in its directory to perform the process installation and check if all the required components are installed. Now you can open your browser http://your-ip-or-domain/webmail/installer to continue the installation

At the end of the checking page, choose Next if it is good.

If you miss some components such as below

You can also miss the PHP Internationalization extension (php-intl).  Then try to install it as below

# apt install php-net-ldap3 php-intl
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
 php-ldap php-net-ldap2 php7.2-ldap
The following NEW packages will be installed:
 php-ldap php-net-ldap2 php-net-ldap3 php7.2-ldap

You will not have the same error. Now on the next page, check the present configuration

Notice the log folder for roundcube if you encounterer any error for the debug

Enter the information of your roundcube database to establish the connection

Now give the imap and smtp server information.

Then we can continue at the bottom of the page

The configuration will be saved in /var/www/html/webmail/config/

The next page will give the result of the previous information. It's important here to check the sending mail and the login. The results will let you know if you will not encounter some error on Roundcube. Now enter all the smtp information with the password for the tests and make sure the result is valid. If not, check the logs files both for roundcube and postfix for a better troubleshooting

now let us enter the imap information and password. You can see that all are valid. See the warning telling you to disable the installer after that

You can rename the installer folder if you don't want to remove it.

# mv webmail/installer/ webmail/installer.old

c) Connection to roundcube

Now you can log in roundcube with our two virtual users to see if we effectively received the test mails during the configuration. Open the roundcube login page without the installer with  http://your-ip-or-domain/webmail

You can see the homepage of roundcube and the mails from the second virtual user in the inbox.

Now you can log out and log in again with the other virtual user to check the mailbox. You can see the mail waiting for you

Now you can create more virtual users and domains which can now easily manage their mailboxes with a pleasant web interface.

Read also

1 thought on “How to Configure Postfix with Webmail on Ubuntu 18.04”... add one

  1. Hello excellent guide, I have configurated a web aplication in python-django on VPS(ubuntu18.04), and running with apache2, I have a domain. the questions is, Can I configurated a mail server in the same VPS(ubuntu). Sorry my english :)


Leave a Comment