Setup Mautic on Ubuntu 16.0 LEMP Stack

Mautic is a Marketing Automation Software, It lets you automate all marketing through campaigns in a centralized location to track everything at one place.

Installing Mautic

Before we continue installing mautic I suggest you to read my post on how to setup LEMP stack on ubuntu 16.0, so I am assuming that you have already installed PHP7.0-FPM, NGINX, MariaDB/MySQL.

I will download all files of mautic to my /var/www/html directory, by running the following command

cd /var/www
sudo apt-get install unzip
unzip -d html
rm html/index.nginx-debian.html
chown -R www-data:www-data html/

Setting up Database

First, we will log into MySQL/MariaDB and create the database that will be used by Mautic. Additionally, we will create a dedicated user for Mautic and grant it privileges on the new database.

mysql -u root -p
create database mautic;
grant all on mautic.* to 'muser' identified by 'password';

Setting up PHP

We are assuming that you have installed PHP7.0-fpm, you just need to make sure you have all the PHP extensions needed by Mautic.

sudo apt-get -y install php7.0-fpm php7.0-cli php7.0-json php7.0-curl php7.0-gd php7.0-mysqlnd php7.0-imap php7.0-mcrypt php7.0-mbstring php7.0-xml php7.0-zip php7.0-intl

sudo nano /etc/php/7.0/fpm/php.ini
date.timezone = "Asia/Kolkata"
memory_limit = 256M
upload_max_filesize = 32M
post_max_size = 32M
max_execution_time = 300
sudo service php7.0-fpm restart

Configure Nginx

Now edit your Nginx config for your Mautic site. Make sure it matches the below configuration file.

Running Mautic

Now we will install a mautic step

  1. Enter Database Details
  2. Set Admin panel password
  3. Leave everything default

Setting Up CRON Job

There are four CRON jobs to automate mail scheduling, segments, campaigns etc. The time for each is set to be executed at every 15 minutes depending on server speed.

*/5 * * * * php /var/www/html/app/console mautic:segments:update
*/5 * * * * php /var/www/html/app/console mautic:campaigns:rebuild
*/5 * * * * php /var/www/html/app/console mautic:campaigns:trigger
*/5 * * * * php /var/www/html/app/console mautic:emails:send
*/5 * * * * php /var/www/html/app/console mautic:email:fetch


Easy LEMP Stack on Ubuntu 16.04

Ubuntu 16.04 is the new stable version of Ubuntu and has many security fixes to get a website up and running much faster we will use Nginx, MariaDB, PHP7.0-FPM they together are called LEMP stack.

STEP 1: Installing Nginx

To Display web pages to visitors we need to install Nginx to do so we will use an apt command in Linux.

sudo apt-get update
sudo apt-get install nginx


After installation, Nginx has started automatically.

step2: Configuring Firewall

If you have the ufw firewall running, as outlined in our initial setup guide, you will need to allow connections to Nginx. Nginx registers itself with ufw upon installation, so the procedure is rather straightforward.

sudo ufw allow 'Nginx HTTP'
sudo ufw allow 'OpenSSH'
sudo ufw enable

sudo ufw status


Type one of the addresses that you receive in your web browser. It should take you to Nginx’s default landing page:


Step3: Installing MariaDB

I am using MariaDB instead of MySQL because I like MariaDB for its better performance, if you want MySQL you can install it, there will be no problem.

Run the following commands to install MariaDB

sudo apt-get install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp:// 0xF1656F24C74CD1D8
sudo add-apt-repository 'deb [arch=amd64,i386,ppc64el] xenial main'

Once the key is imported and the repository added you can install MariaDB with:

sudo apt update
sudo apt install mariadb-server

Step4: Installing PHP for Processing

We now have Nginx installed to serve our pages and MariaDB installed to store and manage our data. However, we still don’t have anything that can generate dynamic content. We can use PHP with Fast processing for this.

Since Nginx does not contain native PHP processing like some other web servers, we will need to install PHP-fpm, which stands for “fastCGI process manager”. We will tell Nginx to pass PHP requests to this software for processing.

sudo apt-get install php-fpm php-mysql

Step4: Configure Nginx to Use the PHP Processor

Now we have everything ready, The only configuration change we still need is to tell Nginx to use our PHP processor for dynamic content.

We do this on the server block level (server blocks are similar to Apache’s virtual hosts). Open the default Nginx server block configuration file by typing:

sudo nano /etc/nginx/sites-available/default

You can test the working by creating a sample file and you are done. For any issue feel free to drop any comments.


Installing PHP7.0 MongoDB extension Ubuntu 16.04

The new PHP 7.0 is twice as fast as compared to previous ones, we are going to setup new MongoDB extension for PHP.

Installing PHP MongoDB extension


I am assuming that you have already installed php7.0 and now wants to install MongoDB PHP7.0 extension

We will need the following PHP 7.0 libraries :

sudo apt-get -y install php7.0-fpm php7.0-cli php7.0-json php7.0-curl php7.0-gd php7.0-mysqlnd php7.0-imap php7.0-mcrypt php7.0-mbstring php7.0-xml php7.0-zip php7.0-intl php7.0-dev

Installing required libraries for MongoDB


We also need OpenSSL libraries to be installed to be used in creating MongoDB secure connections

sudo apt-get install libcurl4-openssl-dev pkg-config libssl-dev libsslcommon2-dev

pecl install mongodb-1.1.9.tgz

Configuring php.ini

We need to add the line "" to php.ini configuration file at the end, based on your configuration you can find the file location

sudo nano /etc/php/7.0/fpm/php.ini


You can now save the file and restart PHP and Nginx to enable the changes.

sudo service php7.0-fpm restart
sudo service nginx restart

How To Create A WordPress Plugin

WordPress plugin architecture allows users to extend the features and functionality of a website or blog. WordPress has over 40,501 plugins available, each of which offers custom functions and features enabling users to tailor their sites to their specific needs.

Initiate your first plugin

Go to wordpress/wp-content/plugins and make a folder with the name of your plugin and include a php file with the same name in it.


Include this in your php file with proper data filled-

*Plugin Name:
*Version: 1.0
*Author URI:


Make Your Plugin Work

WordPress provide hooks and built in functions for your code to work. For example


function prefix_your_function_name(){


add_action(‘hook_name’, ‘prefix_your_function_name’);


This adds your code to a particular hook and make it do the thing you want. Click here for more info

Search for a proper hook on the link above and ink it with your function. For example

function your_footer_function(){

echo “Hello, This is Your Footer.”;


add_action(‘wp_footer’, ‘prefix_your_function_name’);

Setting an AWS server for Beginners

Amazon Elastic Compute Cloud (Amazon EC2) is a web service that provides resizable compute capacity in the cloud. It is designed to make web-scale cloud computing easier for developers.

LOGIN TO YOUR AWS ACCOUNT , sign in or if you are a new user register


On top right hand side of your console select the nearest region for your server. Oregon US West will be selected by default. After selecting the region click on EC2 under compute.

Then under create instance, select Launch Instance. Select Your operating system to be installed. Then select an instance type that is your server, t2 micro will be your free server if your account is in your first year.Then select review and launch instance.

After that click on launch, you will be asked to create a key (.pem file), create it and keep it safe.

Then You can see your server running in instance section of your EC2 console


Go to terminal and use this command to make you key file private.

chmod 400 {full_key_path}

To open your port for vesta and ssh click on launch-wizard-2 in instance section under description. Select Inbound tab and add these rules

Type                          Protocol             Port             Source

HTTP                          TCP                   80              Anywhere

Custom TCP rule        TCP                 8083            Anywhere

SSH                             TCP                   22              Anywhere

Now use this command to login your server. You can see your ip in instance section under description. you have to use your public ip.

ssh -i {full_key_path} ubuntu@{your_public_ip_address}

You are now logged in.

For setting up vesta control panel use these commands

curl -O


For more info goto

You will be asked for email and hostname, you can skip that by pressing enter. Vesta after getting installed will provide you with username and password, save it.

Log in your_public_ip:8083 to see your vesta panel.

Thanks for reading.

Hosting Node js App on Ubuntu

In this post we will show you how to host a node js application on Ubuntu Server.


  • Ubuntu 14.04+
  • Node js
  • PM2 (Node js app manager)
  • Nginx



How this works?

In this post we will consider that your domain is and node js application is running on a port 3000. So we will setup ‘nginx’ as a reverse proxy such that when user tries to access he sees the node js app running on port 3000.

Why reverse proxy?

Because the port on which websites run is generally 80 and only one application can monitor a given port at a time but there can be many node js application running on your server.

Suppose:   ——> APP:3000 (Points to App running on port 3000) ——-> APP:5000 (Different app running on different port)

If not mentioned the default port is always 80 i.e. is equivalent to So we see that only 1 port is exposed to the public but we can run many apps.

Your Domain <—-> Reverse Proxy <——-> Your App


Setting Up the Server:


* Creating a Nodejs App

Lets create a “Hello world” application create a new file ‘app.js’, copy and paste the code given below:

const http = require('http');

const hostname = '';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World\n');

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);

Start your App: node app.js

Open a new SSH Terminal and test your app by doing curl If verified then move on to the next step.

* Running Your App with help of App Manager

As you might have seen by now that if you close the terminal running your node js app.js file then your app will stop so in production we use process manager to keep running the app.

In this tutorial we will be using PM2 though there are other process managers as well:

Basic PM2 commands:

pm2 start app.js # Start your app
pm2 list # Show a list of running apps
pm2 show 0 # Show details of App 0
pm2 stop 0 # Stop app by its ID

After verifying that your application is running with the help of process manager it’s time to setup nginx as reverse proxy.

* Setting Up Nginx

Edit the default server file /etc/nginx/sites-available/default and replace the content with the following:

server {
    listen 80;

location / {
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_cache_bypass $http_upgrade;

Be sure to replace server_name with your domain name and then restart nginx.
sudo service nginx restart

That’s It.

Installing Node JS on Ubuntu 14.04+

Node.js is updated frequently so the question becomes which version to install? For Production environment the latest stable release is version 4.2.x. So in this tutorial we will be installing Node.js v4.2

There are different methods of installing Node.js on Ubuntu. The simplest one is using NVM (Node Version Manager).

curl -o- | bash

Screen Shot 2016-08-07 at 7.43.31 PM.png

To start using ‘nvm’ without closing the terminal do

source ~/.bashrc

Now it’s time to install Node js

nvm install 4.2

Now ‘node’ and ‘npm’ are installed. To make them available to all users we need to create symbolic links.

path=($(type node))
sudo ln -s ${path[2]} /usr/local/bin/node
path=($(type npm))
sudo ln -s ${path[2]} /usr/local/bin/npm

Optimize php.ini for WordPress


php.ini is the default configuration file for PHP which stores the info variables of file upload size, timeouts etc.

I will be covering two PHP installation type configuration

  1. Simple PHP
  2. PHP-FPM

Simple PHP
Enter the command to open the file

sudo nano /etc/php5/apache2/php.ini

Screen Shot 2016-08-23 at 9.59.40 PM

Enter the command to open the file

sudo nano /etc/php5/fpm/php.ini

find and modify bellow lines
use ctrl + w to search

1. To increase files upload limit
upload_max_filesize = 32M

Screen Shot 2016-08-23 at 9.59.40 PM

2. Increase POST request size
post_max_size = 32M

3. Increase Execution time
max_execution_time = 300

4. Increase memory limit
memory_limit = 256M

save file and exit, after that restart apache

sudo service apache2 restart

Firewall setup for high traffic server prevent DDOS

We will show you how to setup firewall with UFW(uncomplicated firewall) you will also learn how to setup Fail2ban.


UFW is an interface of iptables which is set with simplifying the process of configuring the firewall. While iptables is a solid and flexible tool, it is difficult for beginners to learn how to use it to properly configure a firewall. If you’re a beginner starting to secure your network, and you’re not sure which tool to use, UFW is the right choice for you.

Install UFW on ubuntu:

UFW is installed by default on ubuntu operating system, if not you can install by
sudo apt-get install ufw

For high-security default firewall, configuration should set default to deny every request and then allow ssh and httpd/apache2

ufw allow ssh
ufw allow 80/tcp
ufw enable # If the command ask’s for choice give yes

ufw default deny incoming
ufw default allow outgoing

To display status and rules set by you
ufw status

Setup fail2ban to stop DDOS on port 80 and 22

As Wikipedia says Fail2ban is an intrusion prevention software framework that protects computer servers from brute-force attacks, basically, it works by analyzing access log files.

cd /etc/fail2ban
cp jail.conf jail.local

Edit the file jail.local
nano jail.local
add your vps ip in the file to ignore itself
ignoreip =

set the following in the following

bantime = 3600
findtime = 3600
maxretry = 3

Find the sections [ssh-ddos] , [apache-noscript] , [apache-overflows]
and set enabled=true


We will create a rule for apache ddos, at the end of the file jail.local add bellow lines.

enabled = true
port = http,https
filter = http-get-dos
logpath = /var/log/apache*/*error.log
maxretry = 300
findtime = 300
bantime = 300
action = iptables[name=HTTP, port=http, protocol=tcp]

save the file jail.local, now create a new file named
nano /etc/fail2ban/filter.d/http-get-dos.conf

add these lines into and save and exit

failregex = ^ -.*”(GET|POST).*
ignoreregex =

now restart the service
service fail2ban restart

Configure FTP Backup VestaCP Ubuntu

VestaCP is the best Open-Source Control Panel for Web Admins which has the option to FTP Backup all your files to a different server. Follow this tutorial to configure FTP backup on Ubuntu Server.

We are assuming that you have successfully setup High-Security Firewall for the Server and port 21 is open on both servers.

Login to server

I have bought 4GB Dedicated Server with 500GB SATA to use that as FTP Backup server for all my client files, now I will log into my server through ssh, Replace with your own server user and ip

ssh [email protected]

FTP Backup Command

VestaCP provides us with sets of useful commands one of the command is for setting up FTP backup server

/usr/local/vesta/bin/v-add-backup-host TYPE HOST USERNAME PASSWORD [PATH] [PORT]

/usr/local/vesta/bin/v-add-backup-host ftp admin pa$$word /home/user 21
Replace with your own FTP server details.

Screen Shot 2016-07-28 at 12.21.34 PM

Verify FTP Server Added

After you have set the FTP backup server through command line you need to verify that it is successfully added to the system, to verify that run the command below and match the details, if nothing shows up you are either on newer version of VestCP, comment below for any issue

nano /usr/local/vesta/conf/ftp.backup.conf

Backup Files

You need to change the configuration of VestaCP to make FTP as your default backup, edit the file

nano /usr/local/vesta/conf/vesta.conf

Screen Shot 2016-07-28 at 12.08.14 PM

search for BACKUP_SYSTEM and set its value to ftp. Now you can easily take backup of all your files and configure the CRON job from VestaCP CRON dashboard. Run the following command to take FTP Backup of your Server.


Screen Shot 2016-07-28 at 12.48.12 PM

Now you can check the backup server with the path we specified.

Let me know if you are interested in its video tutorial too.