Install Redis Server on Ubuntu 16.04

Why would I use redis?

Redis is wonderful for many reasons. I primarily use it for caching web applications like Magento 2 and WordPress. Some other great ways to use it are as a database or a message broker. You should check it out here.

How do I install it?

The official suggestion is to build the package, but I’d much rather install applications from an official package repository (PPA). This simplifies the install, upgrade, and uninstall methods greatly.

First, you’ll need to add the PPA repository to your OS.

sudo add-apt-repository ppa:chris-lea/redis-server

Next, you’ll want to update your repositories.

sudo apt update

After that, run the installation script.

sudo apt install redis-server

Check that everything installed correctly by checking the version, starting the server, and checking the status of your newly installed server.

redis-server --version
sudo service redis-server start
sudo service redis-server status

You can run a few commands to test out your new server by jumping into the redis-cli application that was installed with your server. If not, just install redis-cli and boot it up.

$ redis-cli
127.0.0.1:6379> ping
PONG

When you get that PONG back, it’s quite satisfying. Let’s test saving and retrieving some values.

127.0.0.1:6379> set bears-eat "beets"
OK
127.0.0.1:6379> get bears-eat
"beets"

Final Notes on Web Aplications

Magento 2

You can configure Redis with Magento 2 quite easily for some really great performance benefits. There are a lot of reasons to use Redis over a few other technologies for many reasons, which are outlined quite nicely over in the Magento DevDocs.

WordPress

WordPress can easily cache with Redis with the installation of a single plugin. I love that it’s a single click away from being enabled or disabled. It’s stupid simple installation abstracts all the heavy lifting Redis does and hides the awesome power in the back-end. You’ll really love the performance boost though, and so will your visitors!

 

Installing Send Only Postfix To Ubuntu 16.04 LTS (Replace Sendmail)

Introduction

There is nothing more upsetting than email. It’s an old technology, and no one should use it. You know it, I know it, everyone knows it.

It’s just too bad the entire world practically revolves around email. So I’m going to help you with an issue I ran into recently. Hopefully this saves some hair-pulling.

Today, I’ll be explaining how to install the Sendmail like application Postfix in conjunction with Mailutils to allow you to send email from your web application. This particular guide will also solve the issue of your web application server not sending to an external mail server on the same domain.

The example I’ll be using will relate to an Amazon Web Service Elastic Cloud Compute (AWS EC2) instance sending mail to GSuite. I know that there are other (likely better) ways of sending mail like AWS SES (Simple Email Service), GSuite SMTP-Relay, Mailgun, or Mandrill. However, we’re going to go purist on this first try and have the Application Server do the entire job.

Server Setup and Installing Mailutils & Postfix

I’ll be removing Sendmail as Postfix will be replacing it. You can run sudo apt purge sendmail if you would like to remove sendmail with it’s configuration. If you only want to remove sendmail but keep its configuration run: sudo apt remove sendmail.

Next, you’ll want to specify the server hostname and change your hosts file if you haven’t yet.

sudo vim /etc/hostname

Remove the current hostname and replace with your domain. (eg. yourdomain.com)

sudo vim /etc/hosts

Change the first line in your host file to reflect the following:

127.0.0.1 yourdomain.com localhost

Once that is complete, give your instance a restart to have it reflect the changes.

Next we’ll need to make sure we have all the utilities and packages we’ll be using installed. I’m told that installing Mailutils will also install Postfix and prompt the setup steps, but in my case, it did not.

sudo apt install mailutils
sudo apt install postfix

Either mailutils will prompt you to set up postfix (a pink background fullscreen prompt) or installing postfix itself will.

You’ll want to specify the the configuration type as Internet Site. You’ll then want to set the System mail name: to yourdomain.com.

The next step will be editing your Postfix main configuration file.

sudo vim /etc/postfix/main.cf

You’ll want to change these lines:

....
mydestination = $myhostname, yourdomain.com, localhost.yourdomain.internal, localhost
....
inet_interfaces = all
....

To…

....
mydestination = 
....
inet_interfaces = loopback-only
....

Once you’re done, save your file and restart Postfix.

sudo service postfix restart

Make sure your postfix is running without errors using sudo systemctl status postfix. If you run into any errors, give your server a reboot. This is an important note. I was running into issues with port 25 having already been bound.

You can now send a test email by running:

echo "This is some email body text" | mail -s "This is a test email subject" your@email.com

Make sure to test it on your own domain, and you should be good to go!

Notes About Spam

You’ll want to make sure of a few things when sending email from multiple sources. One of the most important, and easiest spam-securing technologies available is the humble SPF record.

By adding a TXT record to your Domain Records, you can specify which servers are allowed to send mail, and what to do when something is not validated.

A simple example of this would be:

v=spf1 a mx include:_spf.example.com ip4:999.88.777.66 -all

This SPF record effectively validates A records, MX records, includes, and IP addresses to be able to send mail as an authorized domain sender. If your web application sits at your A record, you’re done. If not, add it with an ip4: tag and call it a day!

Hope you enjoyed!