Setting up your own email server & web server
Nowadays, servers are really cheap. If you want dedicated, take a look at Online.net's offerings - sometimes they have really good deals on. If you want a VPS with fantastic uptime and performance, take a look at OVH's offerings; they have decent spec'd VPSes and they actually work out cheaper than DigitalOcean (affiliate link) ones.
This guide does not go into detail for specific hosts on how to login; if servers are new to you then you really would be better getting someone else to do this or looking at the DigitalOcean guides.
For this project, you will need six things:
- A domain name.
- A x64 Debian 8 server/VPS with a minimum of 1GB of RAM that can be OpenVZ.
- A x64 Ubuntu 14.04 server/VPS with a recommendation of 1GB of RAM that is NOT OpenVZ (it won't work).
- A DNS provider for your domain name; take a look at dns.he.net, it's free. There are also providers like Rage4.
- A serverpilot.io account (free or paid; the basic paid version allows you to create individual user accounts & enable SSL - instead of everything being run under the main user).
Within this guide, there will be examples to demonstrate how it is done; you will need to replace them with yours. I am also going to be setting these up for the guide via DigitalOcean as I have some credit there to spare to spin up instances. I'll also be using dns.he.net for the DNS management.
18.104.22.168 = Mailserver IP
22.214.171.124 = Webserver IP
mail.example.org = mailserver hostname
web.example.org = webserver hostname
example.org = Domain Name
Where to start?
First up, make sure you've got all the information you need. When ordering servers, make sure that the hostname is entered as you want it.
The next thing we want to do is to get DNS working correct; if this is a new domain it's quite important to do it early on due to the time taken for DNS propagation.
Within your domain registrar, you need to update the nameservers to point to ns1.he.net, ns2.he.net, ns3.he.net, ns4.he.net and ns5.he.net
We want to make sure that we create DNS entries for everything; it's relatively straightforward... I've listed all the entries needed below:
example.org IN A 126.96.36.199<br />
autoconfig IN A 188.8.131.52<br />
dav IN A 184.108.40.206<br />
mail IN A 220.127.116.11<br />
www IN CNAME example.org.<br />
example.org IN MX 10 mail.example.org.<br />
_imap._tcp IN SRV 0 1 143 mail.example.org.<br />
_imaps._tcp IN SRV 0 1 993 mail.example.org.<br />
_pop3._tcp IN SRV 0 1 110 mail.example.org.<br />
_pop3s._tcp IN SRV 0 1 995 mail.example.org.<br />
_submission._tcp IN SRV 0 1 587 mail.example.org.<br />
example.org IN TXT "v=spf1 a mx include:mail.example.org ~all"<br />
mail IN TXT "v=spf1 a mx -all"<br />
example.org IN SPF "v=spf1 a mx include:mail.example.org ~all"<br />
mail IN SPF "v=spf1 a mx -all"
Next up, after all that is saved and the nameservers of the domain are resolving, you need to set the rDNS of each IP to match the hostname (otherwise your email will probably bounce or get put in spam folders). If you aren't sure how to do this with your provider, contact their support department. In the example above, I would ask the provider to update the rDNS entry for 18.104.22.168 to point to mail.example.org via a support ticket. If you've used DigitalOcean, then they automatically point the rDNS to the hostname you chose during setup.
You can check if you are on the right track using a website like DNSInspect
Setting up the mailserver
For the mail server, we are going to use a free script created by MailCow. It's easy to use and is perfect for beginners; there's nothing complicated to setup.
If the version of mailcow is no longer 0.12, replace it in the github link below.
First thing to do is to is to login to the VPS as your root account. When at the prompt, type the following command:
apt-get update -y;apt-get upgrade -y;apt-get purge exim4* -y;apt-get install nano wget -y;mkdir ~/build;cd ~/build;wget -O - https://github.com/andryyy/mailcow/archive/v0.12.tar.gz | tar xfz -;cd mailcow*;nano mailcow.config;./install.sh;nano ./installer.log
When the configuration file has opened on your screen, there are only a few things you need to change.
Update the sys_domain entry to say [example.org] instead of domain.com.
Update the sys_timezone to point to yours; I use Europe/London as i'm in the UK.
Update the mailcow_admin_pass to a secure password (or leave it as is to allow it to create it's own secure password).
You can then exit out of nano using CTRL+X and press Y to save and enter.
The installer will now start. Keep an eye on the screen.
Press ENTER at the following tasks:
- System environment
- Package installation
- Self-signed certificate
- MySQL configuration
- Postfix configuration
- Dovecot configuration
- vfilter configuration
- ClamAV configuration
- Spamassassin configuration
- Webserver configuration
- Roundcube configuration
- Rsyslogd configuration
- Fail2ban configuration
- OpenDKIM configuration
- Restarting services
- Checking DNS settings
- Finish installation
If you setup your DNS correctly, then it should have not thrown any errors for the DNS section (but don't panic if it has done).
After the setup has completed, it'll reopen Nano so that it shows your mailcow administrator username and password; you'll need to write these down.
Once you've done that, press CTRL+X to quit nano then type
reboot and hit enter.
Wait a couple of minutes, and then open your browser and go to the [ https://mail.example.org ] site, then click the "Control Centre" link and choose login; enter the login details you wrote down from earlier. Once you've logged in, press the Control Centre link again and choose mailboxes.
Add a domain
Look for the title Domains and then on the far-right press the + button.
Type in your domain name [example.org] and press the Submit button.
Add a mailbox
Look for the title Mailboxes and then on the far-right press the + button. Type in what you want before the @ symbol and then choose your domain from the drop down list. Give it a quota (maximum mailbox size), or empty 0 for no limit. Choose a password, and then repeat it in the box below. Then press submit.
Add a catch-all
Look for the title Aliases and then on the far-right press the + button. Type @example.org in the first box and then in the box below type the mailbox that you created above followed by the domain [[email protected]]. That means anything sent to [email protected] will be forwarded to the [email protected] mailbox (if you chose admin as the mailbox name).
Mailbox setup complete
If you did everything right, email should all be setup. You can login to your email account via the [ https://mail.example.org/rc/ ] link to check if the account is set up.
If something isn't working, simply post on this LET thread and someone will be able to help you.
First thing to do is to create an account over at ServerPilot; it's free to create a basic account.
Once you've created your account and logged in, we need to connect your second server to it so that it can install everything for you. Press the + Connect Server link and then scroll to the bottom and look for a link that says Install ServerPilot Manually. Give it a name [web]. Choose a password that you will use for your main account for SFTP'ing files onto it. Press Begin Manual Installation.
Up will come a page that has a command that you need to enter when logged into your Ubuntu 14.04 x64 server; you need to copy and paste it in EXACTLY as is displayed; it's rather long.
The SSH console will then start doing it's thing to install all the software it needs. Even when it finishes, leave it and go back to your ServerPilot.io browser window; you should notice it updates and starts displaying what the server is doing (installing stuff in the background).
Once it's done, it'll come up with a page that you can add your first website; you need to press the + Create App button. Press it.
Give your app a name [website] - it's gotta be all lowercase and no spaces or punctuation marks. Then enter the domain name (without the www).
If you want it it to install Wordpress for you, tick the wordpress box and then fill in the boxes that appear. Choose your PHP version, then press the Create App button.
Webserver setup complete
If you visit [example.org]/[www.example.org] then your site should show. If not, it could mean that either DNS is not propagated yet, or something else has gone wrong.
Sending Mail from your webserver
If you install Wordpress on your site, it's important to install an SMTP plugin; otherwise any email sent from the site is not likely to actually be sent. Once you've installed one of the many SMTP-plugins, then use it's own test feature to check that it's working; simply enter the login details that you created at the top of the page on the mailserver setup section.
If you get stuck with anything, then someone around here will be able to help you; it's all pretty easy. You can also send me a message.
Who does what