×
Community Blog A Brief Guide to Install and Setup Mailtrain Newsletter on Alibaba Cloud

A Brief Guide to Install and Setup Mailtrain Newsletter on Alibaba Cloud

In this tutorial, we will install and configure Mailtrain Newsletter on Alibaba Cloud Elastic Compute Service (ECS) with Ubuntu 16.04.

By Arslan Ud Din Shafiq, Alibaba Cloud Community Blog author.

Mailtrain is a self-hosted newsletter app developed in Node.js. It allows you to manage large subscriber lists, generate a new campaign using entry data as message contents, send it to selected subscribers, and track individual click statistics for every link in the message.

In this tutorial, we will install and set up a Mailtrain Newsletter on Alibaba Cloud Elastic Compute Service (ECS) with Ubuntu 16.04 installed.

Prerequisites

  • You must have Alibaba Cloud Elastic Compute Service (ECS) activated and verified your valid payment method. If you are a new user, you can get $300 – $1200 worth in Alibaba Cloud credits for your new account. If you don't know how to setup your ECS instance, you can refer to this tutorial or quick-start guide. Your ECS instance must have at least 1GB RAM and 1 Core processor).
  • A domain name registered from Alibaba Cloud. If you have already registered a domain from Alibaba Cloud or any other host, you can update its domain nameserver records.
  • Domain name must be pointed to your Alibaba Cloud ECS's IP address
  • Access to VNC console in your Alibaba Cloud or SSH client installed in your PC
  • Set up your server's hostname and create a user with root privileges.

Setting Up Your Server

Before proceeding with the installation of any kind of package, use the following command to update your Ubuntu system. To execute this command, remember to login from non-root user with Sudo privileges.

sudo apt update && sudo apt upgrade

After executing the above command, you will get a prompt stating "Is this ok?" Type 'y' and hit Enter key.

Install Unzip

Further, you need to install Unzip which will be used to unzip the compressed zip folder. For installing unzip, execute the below command.

sudo apt-get install unzip -y

Install Git

Execute the command shown below to install git.

sudo apt-get install git -y

Install Build-essential

Also, you need to install build-essential by running the command below.

sudo apt-get install build-essential -y

Install Node.js

Next, we need Node.js for the purpose of this tutorial. To install Node.js execute the steps listed below.

Download the setup files by using the following command.

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -

Now, install Node.js by executing command below.

sudo apt install -y nodejs

Install Software-properties-common

To install software-properties-common, execute the command below.

sudo apt-get install software-properties-common

Install MariaDB

Mailtrain Newsletter supports MySQL and for this tutorial, we will use the MariaDB server for MySQL. By default, the Ubuntu repository has an older version of the MariaDB server. We need to add MariaDB repository to the Ubuntu system for using the new version of MariaDB by following the steps listed below:

Verify the keys by executing the command shown below.

# sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8

Add the repository using the following command.

sudo add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://mirror.nodesdirect.com/mariadb/repo/10.2/ubuntu xenial main'

Now update the system by using the command below.

sudo apt update

Now install MariaDB using the following command.

sudo apt install -y mariadb-server

Start and enable the MariaDB server to ensure that after reboot, the server starts automatically.

sudo systemctl start mariadb

sudo systemctl enable mariadb

Now run the following command to enhance the security of MariaDB server and set a password for the root user.

sudo mysql_secure_installation

Also, connect to the MySQL shell as the root user by executing the command below and enter your password.

sudo mysql -u root -p

Execute the following MySQL queries in your MariaDB server.

CREATE DATABASE plane CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER 'aareez'@'localhost' IDENTIFIED BY '654321Ab';
GRANT ALL PRIVILEGES ON plane.* TO 'aareez'@'localhost';
FLUSH PRIVILEGES;
EXIT;  

Install Nginx Server

For this tutorial, we also require to install Nginx. Let's follow the steps below to complete the installation:

To begin the installation of Nginx, execute the command below.

sudo apt install nginx -y

You can confirm installation by executing the following command.

sudo nginx -v

Now you need to enable Nginx to ensure that the system automatically starts after reboot.

sudo systemctl enable nginx.service

Start the Nginx server by executing the command below.

sudo systemctl start nginx.service

Configure Virtual Host

Let's create an Nginx configuration file for Mailtrain Newsletter. A file will open in a Nano text editor once you execute the following command.

sudo nano /etc/nginx/sites-available/mail.conf

Copy and paste the following code and save the file.

    server {
    listen [::]:80;
    listen 80;
    server_name www.softpedia.xyz;
    charset utf-8;
    client_max_body_size 50M;
    location / {
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_next_upstream error timeout http_502 http_503 http_504;
    }

}   

Now create a symlink of newly created file's configuration to an enabled-sites directory by executing the command below.

sudo ln -s /etc/nginx/sites-available/mail.conf /etc/nginx/sites-enabled/

Also, in order to test the syntax of the Nginx configuration file, execute the following command.

sudo nginx -t

Further, to reload the updated configurations, run the command mentioned below.

sudo systemctl reload nginx

Install Mailtrain Newsletter

Now, let's follow the steps listed below to install Mailtrain Newsletter.

Create a document root folder by executing the command below.

sudo mkdir -p /var/www/html

Navigate to /var/www/html using the following command.

cd /var/www/html

Now, change ownership of /var/www/html directory as shown below.

sudo chown -R aareez:aareez /var/www/html

Also, download the latest stable release of Mailtrain using the command below.

wget https://github.com/Mailtrain-org/mailtrain/archive/master.zip

You need to unzip the downloaded zipped folder by running the following command.

unzip master.zip

Execute the following command to remove master.zip.

rm -r master.zip

Now, move the downloaded files to /var/www/html by executing the command below.

mv /var/www/html/mailtrain-master/* /var/www/html

Next, execute the following command to remove Mailtrain-master.
rm -r mailtrain-master

Note to execute the following commands to install the required dependencies.

npm install --production

You need to copy config/default.toml as config/production.toml and update MySQL and any other configurations that it contains using the below-mentioned command.

cp config/default.toml config/production.toml

You can open it using Nano editor as shown below.

nano config/production.toml

Next, update database settings.

Lastly, execute the following command to run the Mailtrain Newsletter Application.

NODE_ENV=production npm start

Set Up Firewalls and Ports

If you have activated firewalls, you need to define a rule in Alibaba Cloud security group for your cloud server to add an exception for port 80/TCP, 443/TCP, and 3000/TCP. You can enable these ports while creating ECS instance, but in case if you have forgotten to unblock these ports, you can follow the procedure in this guide: https://www.alibabacloud.com/help/doc-detail/25471.htm

Install SSL Certificate

You need to use Certbot for installing the SSL certificate using Let's Encrypt. To do so, execute the following steps:

Update the package using the following command.

sudo apt-get update

Install software-properties-common by executing the command below.

sudo apt-get install software-properties-common

Add the Certbot repository by using the following command.

sudo add-apt-repository ppa:certbot/certbot

Use the command below to update the package for loading the added Certbot repository.

sudo apt-get update

Now, install python-certbot-nginx using the command below.

sudo apt-get install python-certbot-nginx

Execute the following command to get Let's Encrypt SSL issued.

sudo certbot --nginx -d softpedia.xyz

Select Option 2 to redirect the link to https and update virtual host settings for SSL.

After a successful issuance of the SSL certificate, you will be navigated to the following screen.

1

Now, run the following command to restart the Nginx server.

sudo systemctl restart nginx

Execute the following command to run the Mailtrain Newsletter Application.

NODE_ENV=production npm start

Now you can access your Mailtrain Newsletter by hitting your URL. Finally, you can log in by using the login credentials and navigate to the following screen:

2

There you go! You have successfully installed and configured Mailtrain Newsletter on your Alibaba Cloud ECS.

0 0 0
Share on

Alibaba Clouder

2,605 posts | 747 followers

You may also like

Comments