Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Subscribe to our newsletter

Advertise on LowEndTalk.com

Latest LowEndBox Offers

    Setting up your own email server & web server
    New on LowEndTalk? Please read our 'Community Rules' by clicking on it in the right menu!

    Setting up your own email server & web server

    DeanDean Member
    edited September 2015 in Tutorials

    image

    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:

    1. A domain name.
    2. A x64 Debian 8 server/VPS with a minimum of 1GB of RAM that can be OpenVZ.
    3. A x64 Ubuntu 14.04 server/VPS with a recommendation of 1GB of RAM that is NOT OpenVZ (it won't work).
    4. A DNS provider for your domain name; take a look at dns.he.net, it's free. There are also providers like Rage4.
    5. 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).
    6. Patience.

    Example Information

    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.

    123.123.123.123 = Mailserver IP

    199.199.199.199 = 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

    image

    We want to make sure that we create DNS entries for everything; it's relatively straightforward... I've listed all the entries needed below:

    <br /> example.org IN A 199.199.199.199<br /> autoconfig IN A 123.123.123.123<br /> dav IN A 123.123.123.123<br /> mail IN A 123.123.123.123<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"

    image

    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 123.123.123.123 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.

    image

    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.

    image

    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

    image

    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.

    image

    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.

    image

    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.

    image

    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.

    image

    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).

    image

    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.

    Webserver Setup



    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.

    image

    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.

    image

    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).

    image

    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.

    image

    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.

    image

    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.

    image

    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.

    image

    Getting Stuck

    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.

    image

    Who does what

    @servercow - created and maintains mailcow

    @ServerPilot - created ServerPilot.io

    image

    Comments

    • jvnadrjvnadr Member
      edited September 2015

      DeanKamitsis said: if servers are new to you then you really would be better getting someone else to do this.

      If servers aren't new for your tutorial reader, then, he will definitely not use serverpilot to install a LAMP stack. he will install it himself, it is a straight forward task, after all.
      And if your reader is new, by just installing mailcow without configuring in their domain things like rdns and spf records, he won't be able either to send emails, whatever smtp configurations he will use in his newly created WP site... Most of mail companies will reject it or, in the best scenario, throw it to spam...

      Thanked by 1rm_

      • If a program actually fits in memory and has enough disk space, it is guaranteed to crash.
      • If such a program has not crashed yet, it is waiting for a critical moment before it crashes.

    • DeanDean Member
      edited September 2015

      @jvnadr
      I've got screenshots to add to this tomorrow :) It's 11:25pm and i'm tired after having written all that. :)

      I also mentioned rDNS within the article, and also show the sample SPF entries within the DNS template above.

      ServerPilot installs: NGINX, Apache, MySQL, PHP-FPM as well as PHP 5.4, 5.5, 5.6 & 7.0 on the same server... and it works, right out the box, without having to mess around with configuration files. I love it because it does all the work for me.

    • @DeanKamitsis - By tomorrow your 1 hour editing window will be gone :)

      Thanked by 3Dean rm_ netomx

      It's better to keep your mouth shut and appear stupid than open it and remove all doubt

    • Thanks @Lee, thought it was 24 hours. I've uploaded some holding images I can overwrite tomorrow morning :)

    • You could perhaps you know, install your own web server, and put this stuff up there, where you could edit it even after 1 hour, in case people spot a mistake or you want to update/expand some section...

      Thanked by 1netomx
    • NocRoomNocRoom Member, Provider

      very good write up, but setup a mail server is half the battle.. you will run into a spam problem and hijacking of smtp. stmp relay is a must have http://nocroom.com/datacenter/spamfirewall/

      Thanked by 1Dean

      NocRoom.com | e: [email protected] | social tw: @NocRoom | fb:/MiamiNetwork | in:/nocroom | Miami, Dallas, Los Angeles

      High Speed VPS - Dedicated Servers - Exchange Servers - Colocation - Spam FireWall SMTP Relay | #Bitcoin Ok

    • @Nocroom - you may want to check the LET rules regarding your signature :)

    • Thank you for ur efforts to write up this tutorial, they are well writen and good explanation.
      I'm sure lot of LET member will use this how to gain some experience and knowledge.
      Gr8 job mate ;)

      Thanked by 1Dean

      wget http://freevps.us/downloads/bench.sh -O - -o /dev/null|bash && dd if=/dev/zero of=test bs=64k count=16k conv=fdatasync; rm -rf test

    • NodejsNodejs Member
      edited September 2015

      looks too complicated to set up. Citadel is more simple and quick to setup. just apt-get install

      for self-hosted email server the biggest problem is spam control.

    • ServercowServercow Member, Provider

      Great article, Dean!

      Thank you for spreading the word about mailcow. :)

      Thanked by 1Dean

      mailcow - your self hosted mail server solution

      Servercow - looking for a great vps for mailcow? - servercow.de

    • I only see 'Image Placeholder' images. Is that correct?

      Thanked by 1netomx

      I recommend Prometeus, the best provider ever!

    • @mpkossen said:
      I only see 'Image Placeholder' images. Is that correct?

      Me too.

    • See above, he linked to placeholder images on his server so he could add them later, otherwise he'd be stuck with what's there because of the 1 hour editing limit.

    • MikePTMikePT Member, Provider

      Correct, the OP confirmed that he'd replace those placeholder images for real screenshots.

      BTW Thanks for the great tutorial.

    • Yeah the real screenshots are going up later on my own server - each one is a separate image to get around the 1hr block. :-)

    • Thanks for this. Still i expect a clear explanation as a newbie.

    • DeanDean Member
      edited September 2015

      Note: The Debian server is the MailCow server. The Ubuntu is the ServerPilot one.

    • Gteat effort.

      Thanked by 1Dean

      Hosts I Recommend >> HVH | XiNiX | CloudCone | HostUs | BuyVM | VirMach

    • Your image host got deadpooled

      Thanked by (44)

    • Nice tutorial. Have a couple of questions and suggestions, though:

      • what are the five IN SRV records for? Is this a Mailcow thing...?

      • why the double SPF entries (in SPF and repeated in TXT)?

      • no mention of DKIM entry in DNS. Configuring OpenDKIM on the mailserver is highly counterproductive if no corresponding entry in DNS ;)

      • you seem to have forgotten about OpenDKIM on the webserver. This is not part of ServerPilot's LEMP+WP install, if I'm not mistaken…?

      I propose using a different SMTP plugin* here instead, one that allows relaying email via the mailserver.

      *) assuming such WP plugin exists? (sorry, I'm a Drupal guy myself)

      Andrew Glodek | Special Projects Director | 香港國際商務中心 HONG KONG INTERNATIONAL BUSINESS CENTRE
    • @BG32 said:
      Your image host got deadpooled

      no, not quite finished the images yet :)

    • @aglodek said:
      Nice tutorial. Have a couple of questions and suggestions, though:

      Will reply later :)

    • victortruicavictortruica Member
      edited October 2015

      E-mail server configuration can be a real pain. I think its very useful that you've mentioned DNS and added an example configuration in your post, as this tends to confuse most people. One thing that you did not mention is the PTR record, which I'm not sure, but I think that all major providers consider it. Microsoft/Outlook the most, probably, because they are the ones that gave me the most problems when configuring my e-mail server

      Blogging on tech, security and hosting. Check it out at truica-victor.com
      Recommending DigitalOcean for hosting and online projects

    • @victortruica: nice seo and spam.

      Thanked by 1rm_

      ==========

    • DeanDean Member
      edited October 2015

      If you actually read my article @victortruica, you will see that I do actuall mention rDNS...

    • GM2015GM2015 Member
      edited December 2015

      Ooouh! El Necro!

      It's great you actually uploaded the images after waiting for so much./s

      otherwise thanks.

      Hey Dean, after multiple retries it works!

      I can send myself mail, too! Icedove thinks it's spam, but wgaf! I need it for receiving emails.

      I'll get an ovh vps.

      DeanKamitsis said: If you actually read my article @victortruica, you will see that I do actuall mention rDNS..

      Go give Vultr(referral) a try. | GNU/Linux http://debian.org

    Sign In or Register to comment.