Setting up a mail server on Ubuntu 18.04?

February 12, 2019 107 views
Apache Ubuntu 18.04

Hi person! :-)

I've been going through a lot of DO's forums, OS forums, and server forums, so I'm listing everything here which may address many of the recommendations I've come across.

What I'm attempting: personalized family accounts - personal Wordpress websites available through /var/www/html, personal Rainloop e-mail through /var/www/rainloop, personal Filerun storage through /var/www/filerun. Oh, and some server games so we can play each other online through the server, but that's not important here.

If you see server setup problems or file problems you would change - even if you're unsure what's going on with the domain - I'm happy to accept critiques on that, as well.

The current setup:

Ubuntu PhpMyAdmin on 18.04 droplet

  • phpMyAdmin installed and properly accessible via https://mydomain.tld/phpmyadmin
  • MySQL installed
  • Apache2 installed
  • Wordpress installed at /var/www/html and working properly at https://mydomain.tld
  • Rainloop installed at /var/www/rainloop but not working
  • LetsEncrypt SSL certificate

What I'm currently working on is the e-mail.
My goal is to reach the webmail at https://email.mydomain.tld

  1. http://email.mydomain.tld just redirects to https://mydomain.tld
  2. With SSL it says, "This site can't be reached"
  3. http://webmail.mydomain.tld breaks as if the domain doesn't exist.
  4. With SSL it says, "The site can't be reached"

(Rainloop's website uses "webmail.mydomain.tld" for installation. Even if I can just get it installed, I'm still fine with using https://webmail.mydomain.tld, instead of "email".)

Current DNS record setup:

Type | Hostname | Value | Priority | TTL (seconds)

MX records, added several priorities because I can't figure it out
MX | webmail.mydomain.tld | mail handled by DO.HOST.IP.ADDRESS | 0 | 14400
MX | webmail.mydomain.tld | mail handled by DO.HOST.IP.ADDRESS | 1 | 14400
MX | webmail.mydomain.tld | mail handled by DO.HOST.IP.ADDRESS | 5 | 14400
MX | webmail.mydomain.tld | mail handled by DO.HOST.IP.ADDRESS | 10 | 14400
MX | mydomain.tld | mail handled by DO.HOST.IP.ADDRESS | 0 | 14400
MX | mydomain.tld | mail handled by DO.HOST.IP.ADDRESS | 1 | 14400
MX | mydomain.tld | mail handled by DO.HOST.IP.ADDRESS | 5 | 14400
MX | mydomain.tld | mail handled by DO.HOST.IP.ADDRESS | 10 | 14400
MX | email.mydomain.tld | mail handled by DO.HOST.IP.ADDRESS | 0 | 14400
MX | email.mydomain.tld | mail handled by DO.HOST.IP.ADDRESS | 1 | 14400
MX | email.mydomain.tld | mail handled by DO.HOST.IP.ADDRESS | 5 | 14400
MX | email.mydomain.tld | mail handled by DO.HOST.IP.ADDRESS | 10 | 14400

(Once I can get it properly set up, I intend to start removing these one by one, to figure out which ones I need to keep.)

Wordpress installation, working properly
CNAME | wordpress.mydomain.tld | is an alias of mydomain.tld. | 43200

For future storage installation (not there yet)
CNAME | mydrive.domain.tld | is an alias of mydomain.tld. | 43200

Linking domain to host IP
A | mydomain.tld | directs to DO.HOST.IP.ADDRESS | 3600

To fix "www"
CNAME | www.mydomain.tld | is an alias of mydomain.tld. | 43200

Nameservers
NS | mydomain.tld | directs to ns1.digitalocean.com. | 1800
NS | mydomain.tld | directs to ns2.digitalocean.com. | 1800
NS | mydomain.tld | directs to ns3.digitalocean.com. | 1800

Current .htaccess and .conf Setups:

/var/www/.htaccess
Options -Indexes

/var/www/html/.htaccess
<Directory /var/www/>
AllowOverride All
</Directory>

RewriteCond %{HTTP_HOST} ^([^.]+).mail.mydomain.tld$
RewriteRule ^/(.*)$ http://mail.mydomain.tld/%1/$1 [L,R]

Options -Indexes
DirectoryIndex index.php index.html /example.php

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUESTFILENAME} !-f
RewriteCond %{REQUESTFILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

/var/www/rainloop/.htaccess
None yet, intend to edit once I've gotten it set up.

/etc/apache2/apache2.conf
ServerName mydomain.tld

rainloop.conf (VirtualHost *:80) and rainloop-le-ssl.conf (VirtualHost *:443)
Both list the correct domain (ServerName email.mydomain.tld) and point to the correct folder (DocumentRoot /var/www/rainloop).

rainloop.conf

<VirtualHost *:80>
ServerName email.mydomain.tld
DocumentRoot "/var/www/rainloop/"
ServerAdmin my@email.address

ErrorLog "/var/log/apache2/rainlooperrorlog" (word just got italicized in this post because of underscores)
TransferLog "/var/log/apache2/rainloopaccesslog"

<Directory />
Options +Indexes +FollowSymLinks +ExecCGI
AllowOverride All
Order deny,allow
Allow from all
Require all granted
</Directory>

rainloop-le-ssl.conf

<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName email.mydomain.tld
DocumentRoot "/var/www/rainloop/"
ServerAdmin my@email.address

ErrorLog "/var/log/apache2/rainlooperrorlog"
TransferLog "/var/log/apache2/rainloopaccesslog"

<Directory />
Options +Indexes +FollowSymLinks +ExecCGI
AllowOverride All
Order deny,allow
Allow from all
Require all granted
</Directory>

SSLCertificateFile /etc/letsencrypt/live/email.mydomain.tld/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/email.mydomain.tld/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

</VirtualHost>

/etc/apache2/wordpress.conf
<Directory /var/www/>
Options FollowSymLinks
</Directory>

If you see server setup problems or file problems you would change - even if you're unsure what's going on with the domain - I'm happy to accept critiques on that, as well.

3 Answers

Also, here's the firewall settings:

ufw status

To Action From

443/tcp ALLOW Anywhere
80/tcp ALLOW Anywhere
3306 ALLOW Anywhere
OpenSSH ALLOW Anywhere
22 ALLOW my.home.ip.address
3306 ALLOW my.home.ip.address
443 ALLOW my.home.ip.address
80 ALLOW my.home.ip.address
Anywhere ALLOW my.home.ip.address
22/tcp ALLOW Anywhere
Apache ALLOW Anywhere
Apache Full ALLOW Anywhere
Apache Secure ALLOW Anywhere
443/tcp (v6) ALLOW Anywhere (v6)
80/tcp (v6) ALLOW Anywhere (v6)
3306 (v6) ALLOW Anywhere (v6)
OpenSSH (v6) ALLOW Anywhere (v6)
22/tcp (v6) ALLOW Anywhere (v6)
Apache (v6) ALLOW Anywhere (v6)
Apache Full (v6) ALLOW Anywhere (v6)
Apache Secure (v6) ALLOW Anywhere (v6)

Okay, so I finally figured it out. For anyone else who wants it:

  1. I set the FQDN of email.mydomain.tld
  2. I deleted the other MX records, but kept just this one: MX | email.mydomain.tld | mail handled by DO.HOST.IP.ADDRESS | 0 | 14400
  3. I added CNAME: CNAME | email.domain.tld | is an alias of mydomain.tld. | 43200
  4. And then for the server to accept e-mails, I followed the instructions here: https://www.tecmint.com/install-postfix-mail-server-with-webmail-in-debian/

Nevermind, forget everything here. I've skipped over some steps. This did work at face value, but it didn't work with receiving mail, nor did it allow for proper subdomaining. Reset everything - just going to keep working through it.

Have another answer? Share your knowledge.