If you recall the introductory post to this series – Set Up an Unmanaged VPS (4 Newbies) .. The V-P-S Bible – I said the aim was to set up the fastest possible web server, while retaining options to strap on other functionality later on. For most of us, the most likely addition would be a mail server. But.
But. A mail server takes up valuable resources. SMTP, for example, eats RAM. Which slows down your sites. OK, we could set up POP3 and retain greater efficiency. Then again, we could just use Google Apps, and focus this box 100% towards our web server solution.
…and that's my plan, for now; retaining the option to add a mail server later on, yet allowing our web apps a mail handling capacity. So we need Postfix for that, and some configuration.
Video: Enable Email on a VPS
Change the Hostname
To see your hostname, at the CLI, type:-
…and hit return. The name displayed is probably not what you're after. Let's change it to something more personalised and user-friendly.
I've got a domain hanging about so I'll use that as an ongoing example. It's wpcop.com, vpsB's sister site, so there's a cheap plug if ever there was one. For our mail functionality we could use any HOST.wpcop.com, such as mail.wpcop.com or vps.wpcop.com or whateveryoulike.wpcop.com. For this example I want to use the hostname mail.wpcop.com. You do likewise, editing the host to whatever you want and the domain, typically, for that of your principle website.
We’ll change the hostname in 2 files, and then change the Reverse DNS to match the hostname.
For the first file, having logged into the superuser account, we'll use the handy echo command (which is explained below) to paste the new hostname into a fresh file. Then we'll quit root's account:-
[private_vpsBible New Site Offer]
echo mail.wpcop.com > /etc/hostname
[/private_vpsBible New Site Offer]
.. swapping your hostname for mine.
The Echo Command
.. figured I'd introduce this handy command, used to parse a string in various ways.
Take our example command above:-
In this case we're inserting the string “mail.wpcop.com” into a file.
One important note about using the > symbol ..
- > The ‘greater than' symbol deletes file content, replaced with the new string
- >> Using 2 of these appends file content, adding the new string to the end
.. So if in doubt, use a text editor like Nano instead.
For more on “echo” type man echo.
(Er, “man” is short for manual and works for most commands.)
For the second hostname change we'll use Nano:-
.. replacing the single instance of the existing hostname with mail.wpcop.com.
If your Linux distro doesn't have a line with the hostname, no worries, just add the line and ..
.. it should look something like this…
By the way, if your hosts file doesn't contain those last 7 lines, don't worry about it.
Set the Reverse DNS (RDNS)
Now for the reverse DNS. For this, using your web browser, head to your VPS manager.
For Slicehost, after logging into the Slicemanager, you click the DNS tab, then the Reverse DNS link. Other unmanaged VPS providers will have similar control panels.
Perform a quick reboot:-
Logged back in, now type:-
That's better, huh?
To check the RDNS, do this:-
(You may find that dnsutils is already installed. Either way, the above command won't do any harm.)
Then, replacing mine with your IP address:-
Provided the output contains the following, but with your IP, we're fine:-
…if it doesn't, make some tea and try again. The RDNS may take a little time to propogate.
Prompted, choose Internet Site, as shown in the image at the top of this post.
Then enter your hostname:-
Now we'll redirect mail from root to our username, in my case olly:-
…and where you see this line…
…change “some_value” to your username, like this in my case…
…(Or if you don't see that line at all, add it, substituting “olly” for your username.)
Reload the aliases database:-
Edit the Postfix configuration:-
…and replace 3 lines, substituting wpcop for your domain:-
Restart the Postfix service to refresh its configuration:-
Testing your email
Check it by sending an email to your email address, in this example using the mailx program that came bundled in mailutils, that we installed a moment ago.
Swapping the email address for yours, type this:-
You'll see there's a Cc: field now. Add another email address if you like, else ignore this. Then, hit return.
Now we've got a Subject: field. Golly! Type in whatever and again hit return.
Now we've got a blank line. Gosh. That's where you tap in your message body, so do: “This is a test blah whatnot.” And this time, DO NOT hit return. Well, you can, but all it does is to give you a carriage return. To escape out of the message body field, whilst simultaneously sending the message, press CTRL and D at the same time.
Now check your mail client and get generally over-excited.
OK, that's the outgoing email sorted for your server, so you'll be able to send email from your web applications, for each and every domain using the name of each domain *. For incoming email, we'll be setting up Google Apps later in this series, which is free, easy, saves time and your system resources, and can be popped or smtp'ed to your local email client, using your own domain name. Fairly splendid.
* ie, email@example.com as well as firstname.lastname@example.org, as many domains as you want, independent of each other regardless of you RDNS setting. Nice, huh!
In the next section Install PHP5 & MySQL – The One-Stop FastCGI Index Page, as well as setting up MySQL for your databases we'll look at the options for setting up PHP to work with Nginx, plus how to extend that solution with added security and caching. If that sounds complex, don't sweat it, it's pretty clear and I'll steer you in the right direction.
Meantime, here's the index…