Mailtrain is an open-source self hosted newsletter app built on Node.js and MySQL/MariaDB. Mailtrain's source is on GitHub. This guide will show you how to install Mailtrain on a fresh CentOS 7 Rcs instance.
Requirements
- Software Requirements:
- Node.js v7 or greater
- MariaDB
- Nginx
- Redis (optional)
- Hardware Requirements:
- 1 vCPU
- 1024 MB RAM
Check the CentOS version.
cat /etc/centos-release
# CentOS Linux release 7.5.1804 (Core)Create a new non-root user account with sudo access and switch to it.
useradd -c "John Doe" johndoe && passwd johndoe
usermod -aG wheel johndoe
su - johndoeNOTE: Replace johndoe with your username.
Set up the timezone.
timedatectl list-timezones
sudo timedatectl set-timezone 'Region/City'Ensure that your system is up to date.
sudo yum update -yInstall Development Tools and unzip.
sudo yum groupinstall -y 'Development Tools' && sudo yum install -y unzipFor simplicity's sake, disable SELinux and Firewall.
sudo setenforce 0 ; sudo systemctl stop firewalld ; sudo systemctl disable firewalldInstall Node.js and npm
Install Node.js and npm by utilizing the NodeSource YUM repository for Node.js.
curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
sudo yum install -y nodejsCheck the versions.
node -v && npm -v
# v8.11.4
# 5.6.0Install MariaDB
Install MariaDB.
sudo yum install -y mariadb-serverCheck the version.
mysql --versionStart and enable MariaDB.
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.serviceRun the mysql_secure installation script to improve security.
sudo mysql_secure_installationConnect to the MariaDB shell as the root user.
mysql -u root -p
# Enter password:Create an empty database and user, and remember the credentials.
CREATE DATABASE dbname;
GRANT ALL ON dbname.* TO 'username' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
exitInstall Nginx
Install Nginx.
sudo yum install -y nginxCheck the version.
nginx -vStart and enable Nginx.
sudo systemctl start nginx.service
sudo systemctl enable nginx.serviceConfigure Nginx as an HTTP or HTTPS (if you use SSL) reverse proxy for Mailtrain. Run sudo vi /etc/nginx/conf.d/mailtrain.conf and add the following configuration.
server {
listen [::]:80;
listen 80;
server_name example.com;
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;
}
}Test the configuration.
sudo nginx -tReload Nginx.
sudo systemctl reload nginx.serviceInstall Mailtrain
Create an empty document root folder where Mailtrain should be installed.
sudo mkdir -p /var/www/mailtrainNavigate to the document root folder.
cd /var/www/mailtrainChange ownership of the /var/www/mailtrain folder to user johndoe.
sudo chown -R johndoe:johndoe /var/www/mailtrainDownload and unzip Mailtrain.
wget https://github.com/Mailtrain-org/mailtrain/archive/master.zip
unzip master.zip
rm master.zip
mv mailtrain-master/* . && mv mailtrain-master/.* .
rmdir mailtrain-masterRun npm install --production in the Mailtrain folder to install required dependencies.
Copy config/default.toml as config/production.toml and update MySQL and any other settings in it.
cp config/default.toml config/production.toml
vi config/production.tomlRun the server.
NODE_ENV=production npm startInstallation is complete. Login with the username admin and the password test. Once logged in, update the user information and password via the Mailtrain web interface. For more information, visit Mailtrain Github wiki page.