How to Install Mautic Marketing Automation Tool on Ubuntu 20.04

Mautic is an open-source self-hosted marketing automation tool for everyone. You can use it to grow up your business or community, monitor your website, create landing pages, create a campaign for your business, manage contacts, and even send marketing emails.

This tutorial will show you how to install the Mautic Marketing Automation Tool on the latest Ubuntu 20.04 Server. We will install Mautic with the LEMP Stack (Linux, Nginx, MySQL, and PHP-FPM), and we will secure our installation using the SSL Letsencrypt.

Prerequisites

  • Ubuntu 20.04 Server
  • 2GB or more RAM
  • Root privileges

What will we do?

  • Install Nginx Web Server
  • Install and Configure PHP-FPM 7.3 on Ubuntu 20.04
  • Install and Configure MySQL Server
  • Generate SSL Letsencrypt
  • Download Mautic Source Code Latest Version
  • Configure Nginx Server Blocks for Mautic
  • Mautic Post Installation

Step 1 - Install Nginx Web Server

Firstly, we will install the Nginx packages to the Ubuntu 20.04 Server. The Mautic software will be running under the Nginx web server with a secure HTTPS connection.

Update all available repositories on your system and install Nginx packages using the apt command below.

sudo apt update
sudo apt install nginx -y

Once all installation is completed, start the Nginx service and add it to the system boot.

systemctl start nginx
systemctl enable nginx

The Nginx service is up and running, check using the following command.

systemctl status nginx

Below is the result you will get.

Install Nginx on Ubuntu 20.04

As a result, the Nginx web server installation on Ubuntu Server has been completed.

Step 2 - Install and Configure PHP-FPM 7.3 on Ubuntu 20.04

At this time, the Mautic software still does not support the new PHP 7.4 version. In that case, we will install the PHP 7.3 packages from the PPA repository to our Ubuntu 20.04 Server.

Install the 'software-properties-common' package and add the PPA repository for PHP using the command below.

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php -y

Once all is completed, you're ready to install and configure PHP-FPM 7.3 packages.

Add PHP 7.3 Repository on Ubuntu 20.04

Install PHP-FPM 7.3 packages with some additional packages using the apt command below.

sudo apt install -y php7.3-fpm php7.3-mbstring php7.3-xml php7.3-mysql php7.3-common php7.3-gd php7.3-json php7.3-cli php7.3-curl php7.3-zip php7.3-xml php7.3-imap php7.3-intl

Once all installation is completed, go to the '/etc/php/7.3/fpm' directory and edit the configuration file 'php.ini' using vim editor.

cd /etc/php/7.3/fpm/
vim php.ini

Uncomment the following lines and change the values as below.

date.timezone = "UTC"
cgi.fix_pathinfo = 0

Save and close.

Next, start the PHP-FPM service and add it to the boot time.

systemctl start php7.3-fpm
systemctl enable php7.3-fpm

Start PHP-FPM Service

The PHP-FPM service is up and running. Check using the following command.

systemctl status php7.3-fpm
ss -pl | grep php

Below is the result you will get.

Check PHP-FPM Service Status

As can be seen, the PHP-FPM service is up and running under the sock file '/var/run/php/php7.3-fpm.sock'.

As a result, the installation and configuration of PHP-FPM 7.3 on Ubuntu 20.04 Server has been completed.

Step 3 - Install and Configure MySQL Server

In this step, we will install the MySQL Server and configure the default MySQL root password using the 'mysql_secure_installation' command utility. And after that, we will create a new MySQL database and user for our Mautic installation.

Install MySQL Server packages using the apt command below.

sudo apt install mysql-server mysql-client

Once all installation is completed, start the MySQL service and add it to the system boot.

systemctl start mysql
systemctl enable mysql

Now check the MySQL service status using the following command.

systemctl status mysql

Below is the result you will get.

Install MySQL Server on Ubuntu 20.04

As can be seen, the MySQL service is up and running on the Ubuntu 20.04 Server.

Next, we will set up the MySQL root password using the 'mysql_secure_installation' command utility provided by MySQL.

Run the 'mysql_secure_installation' command below.

mysql_secure_installation

Now you will be asked for some configurations, type your new password for MySQL root user and type 'Y' for others configuration.

Press y|Y for Yes, any other key for No: 
Please set the password for root here.

New password:
Re-enter new password:

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y

As a result, the password configuration for the MySQL root user has been completed and was ready to create a new database and user for Mautic.

Next, log in to the MySQL shell using the 'mysql' command below.

mysql -u root -p

Create a new database named 'mautic_db' and the user 'mauticuser' with the password 'mautic321' using the following queries.

CREATE DATABASE mautic_db;
CREATE USER [email protected] IDENTIFIED WITH mysql_native_password BY 'mautic321';
GRANT ALL PRIVILEGES ON mautic_db.* TO [email protected] WITH GRANT OPTION;
FLUSH PRIVILEGES;

Now type 'exit' to log out from the MySQL shell.

Create Database and User for Mautic

As a result, the MySQL database and user for Mautic installation have been created.

Step 4 - Generate SSL Letsencrypt

For this tutorial, we will secure our Mautic installation using the SSL Letsencrypt. Also, make sure that you have got a domain name, and it's resolved to your server IP address.

Now install the certbot tool for generating SSL Letsencrypt using the apt command below.

sudo apt install certbot

Once all installation is completed, stop the Nginx service and generate the SSL Letsencrypt using the command below. Also, make sure to change the email address and with your own.

systemctl stop nginx
certbot certonly --rsa-key-size 2048 --standalone --agree-tos --no-eff-email --email [email protected] -d mautic.hakase-labs.io

One all is completed, your SSL certificates will be available at the '/etc/letsencrypt/live/your-domain.com/' directory.

As a result, the SSL Letsencrypt certificates for Mautic has been generated.

Step 5 - Download Mautic Source Code Latest Version

In this step, we will download and install the Matic latest version to the '/var/www' directory.

Before downloading the Mautic Source Code, install the unzip package using the apt command below.

sudo apt install unzip

Next, go to the '/var/www' directory and download the Mautic source code using the wget command below.

cd /var/www/
wget -q https://www.mautic.org/download/latest

Extract the Mautic source code to the new directory named 'mautic', then change the ownership of the 'mautic' directory to the 'www-data' user.

unzip -qq latest -d mautic
sudo chown -R www-data:www-data /var/www/mautic

As a result, the Mautic source code has been downloaded to the '/var/www' directory, and we're ready to install the Mautic Marketing software tool.

Download Mautic Source Code

Step 6 - Set up Nginx Server Blocks for Mautic

In this step, we will set up the Nginx server blocks for the Mautic installation.

Now go to the '/etc/nginx/sites-available' directory and create a new configuration 'mautic' using vim editor.

cd /etc/nginx/sites-available/
vim mautic

Change the domain name and path of the SSL certificates with your own, then paste the configuration into it.

server {
    listen               80;
    server_name          mautic.hakase-labs.io;
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl;
    server_name mautic.hakase-labs.io;

    ssl_certificate /etc/letsencrypt/live/mautic.hakase-labs.io/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/mautic.hakase-labs.io/privkey.pem;
    
    ssl_session_timeout 5m;
    ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";

    client_max_body_size 4M;
    client_body_buffer_size 128k;
      
     root /var/www/mautic;
     index index.php index.html index.htm index.nginx-debian.html;
      
     location / {
       try_files $uri $uri/ =404;
     }
 
     location ~ .php$ {
       include snippets/fastcgi-php.conf;
       fastcgi_pass unix:/run/php/php7.3-fpm.sock;
     }
 
     location ~* ^/index.php {
       fastcgi_split_path_info ^(.+.php)(/.+)$;
       fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
       fastcgi_index index.php;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       include fastcgi_params;
       fastcgi_buffer_size 128k;
       fastcgi_buffers 256 16k;
       fastcgi_busy_buffers_size 256k;
       fastcgi_temp_file_write_size 256k;
     }
}

Save and close.

Next, activate the Nginx virtual blocks for Mautic and make a test for the configuration. Also, make sure there is no error.

ln -s /etc/nginx/sites-available/mautic /etc/nginx/sites-enabled/
nginx -t

Now restart the Nginx service to apply the new server blocks configuration.

systemctl restart nginx

As a result, the Nginx server blocks configuration for Mautic has been completed, and we're ready to continue for the Mautic Post Installation.

Setup Nginx Server Blocks for Mautic

Warm up the Mautic cache:

cd /var/www/mautic/app
rm -rf cache/*
./console cache:warmup

Step 7 - Mautic Post Installation

Open your web browser and type the domain name of your Mautic installation on the address bar. Mine is:

https://mautic.hakase-labs.io/

The Mautic installer will do system environment checks for the installation, and make sure you get the "Ready to install" message as below.

Mautic Check Environment for the Installation

Click 'Next Step' to continue the installation.

Now type details MySQL database for the Mautic installation and click 'Next Step' to continue.

Mautic Database Configuration

Next, type the new admin user, email, and password for the Mautic and click the 'Next Step' button.

Mautic Create Admin User and Password

For the Mautic Email configuration, chose as you need and click the 'Next Step' button.

Mautic Setup Email Marketing Provider

And the Mautic installation has been completed, and you will be redirected to the Mautic Login page.

Mautic Login Page

Type your admin user and password, then click the 'Login' button.

Now you will get the Mautic Dashboard.

Mautic Admin Dashboard

As a result, the installation of Mautic with the Nginx web server, MySQL database, and PHP-FPM on Ubuntu 20.04 has been completed successfully.

Reference

Share this page:

Suggested articles

7 Comment(s)

Add comment

Comments

By: IceManXS

Thank you for the Tutorial.

There was a problem I had. So maybe someone else is stuck at the same point:

Every time I tried to finish Step 2 "Mautic Installation - Administrative User" I got a Error 500.

The Problem is the not existing cache of Mautic. There is one missing file. I had to warm up the cache before.

Solution:

sudo su

cd /var/www/mautic/app

rm -rf cache/*

./console cache:warmup

By: peterpetr

Can Mautic be installed to run on an Ubuntu 18.04 LTS server using the ISPconfig.org control panel?

By: IceManXS

@IzFazT That´s why it is always good to read the comments. And sometimes the tutorial get´s a update. As you can see above.

@peterpetr Yes you can do so. Your config is exactly what I use. You just have to start from Chapter 5 within your desired domain or subdomain.

After I created new database and a subdomain marketing.dein-domain-name.de in ISPConfig with PHP-FPM7.3, LetsEncrypt SSL, Rewrite HTTP to HTTPS, use HTTP2, I exctracted the downloaded latest stable version (actually it is 2.16.3) of mautic to /var/www/marketing.dein-domain-name.de/web/mautic.

For individual php.ini I used:

cgi.fix_pathinfo = 0

date.timezone = "Europe/Berlin"

 

For nginx directives I used:

##subroot mautic ##

# Include Header configuration
#include /etc/nginx/snippets/header.conf;

# Include SSL configuration
#include /etc/nginx/snippets/ssl.conf;

client_max_body_size 20M;

location / {
    # try to serve file directly, fallback to app.php
    try_files $uri /index.php$is_args$args;
}

location ~ /(mtc.js|1.js|mtracking.gif|.*\.gif|mtc) {
    # default_type "application/javascript";
    try_files $uri /index.php$is_args$args;
}

# redirect some entire folders
rewrite ^/(vendor|translations|build)/.* /index.php break;

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    {FASTCGIPASS}
}

location ~* ^/index.php {
    # try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

    {FASTCGIPASS}
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;

    fastcgi_buffer_size 128k;
    fastcgi_buffers 256 16k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
}

# Deny everything else in /app folder except Assets folder in bundles
location ~ /app/bundles/.*/Assets/ {
    allow all;
    access_log off;
}
location ~ /app/ {
    deny all;
}

# Deny everything else in /addons or /plugins folder except Assets folder in bundles
location ~ /(addons|plugins)/.*/Assets/ {
    allow all;
    access_log off;
}
# location ~ /(addons|plugins)/ { deny all; }

# Deny all php files in themes folder
location ~* ^/themes/(.*)\.php {
    deny all;
}

# Don't log favicon
location = /favicon.ico {
    log_not_found off;
    access_log off;
}

# Don't log robots
location = /robots.txt  {
    access_log off;
    log_not_found off;
}

# Deny yml, twig, markdown, init file access
location ~* /(.*)\.(?:markdown|md|twig|yaml|yml|ht|htaccess|ini)$ {
    deny all;
    access_log off;
    log_not_found off;
}

# Deny all attempts to access hidden files/folders such as .htaccess, .htpasswd, .DS_Store (Mac), etc...
location ~ /\. {
    deny all;
    access_log off;
    log_not_found off;
}

# Deny all grunt, composer files
location ~* (Gruntfile|package|composer)\.(js|json)$ {
    deny all;
    access_log off;
    log_not_found off;
}

# Deny access to any files with a .php extension in the uploads directory
location ~* /(?:uploads|files)/.*\.php$ {
    deny all;
}

# A long browser cache lifetime can speed up repeat visits to your page
location ~* \.(jpg|jpeg|gif|png|webp|svg|woff|woff2|ttf|css|js|ico|xml)$ {
    access_log        off;
    log_not_found     off;
    expires           360d;
}

 

In my used config there are some modifications for ssl and header config, for more security, that I did not post above. I hope everyone here using ISPConfig knows how to secure your sites. I use some snippets for that, which I include via "include". That´s why i commented them out.

My above nginx config (I found on another site for installing mautic) works and I think it restricts some bad behavior a little better than the config of Muhammad Arul. But the one from Muhammad also works with ISPConfig if you modify it a little bit:

 

 

    client_max_body_size 4M;    client_body_buffer_size 128k;           location / {       try_files $uri $uri/ =404;     }      location ~ .php$ {       include snippets/fastcgi-php.conf;       {FASTCGIPASS}     }      location ~* ^/index.php {       fastcgi_split_path_info ^(.+.php)(/.+)$;       {FASTCGIPASS}       fastcgi_index index.php;       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;       include fastcgi_params;       fastcgi_buffer_size 128k;       fastcgi_buffers 256 16k;       fastcgi_busy_buffers_size 256k;       fastcgi_temp_file_write_size 256k;     }

Both configs don´t work perfectly so far for me. If you installed the latest stable version of mautic you get a info within mautic that there is a new version of mautic available (v3.0.1) If you click the button "update now", the nginx vhost sends you to marketing.dein-domain-name.de/index.php/upgrade_v3.php and you get a 404. The index.php/ part in it is wrong. It only has to be marketing.dein-domain-name.de/upgrade_v3.php to use it. It works if you change the adress manually. I think it is because I can´t write the nginx vhost by myself. I always need someone like howtoforge and others who writes the config. With that I understand what it does or what it restricts. So if there is someone who can help please post it here.

By the way if you installed v3.x.x you have to use bin/console instead of app/console. With version 3 the mautic developers changed it that way.

By: IceManXS

Sorry for this strange looking comment from me before. When I wrote it it looked much better and readable.

It isn´t a good idea to copy and paste code-blocks from the tutorial and use them for a comment. It looks perfect when you write it but it becomes unreadable when it is published.

So maybe someone can delete the code-blocks from my comment before. Because I think this is only confusing.

By: Emma

Thanks alot for the tutorial, it worked perfectly well for me, the only major challenge I had was after the installation, I was getting this error message in the browser "The site is currently offline due to encountering an error. If the problem persists, please contact the system administrator." - from research I had to run this cmd to fix it, chown -R www-data /var/www/mautic/ solve the problem.

By: onastvar

FYI:

 

This commmand did not work for me.

 

 

unzip -qq latest -d mautic

 

i get this?

 

 

[email protected]:/var/www# unzip -qq latest -d mautic

[latest]

  End-of-central-directory signature not found.  Either this file is not

  a zipfile, or it constitutes one disk of a multi-part archive.  In the

  latter case the central directory and zipfile comment will be found on

  the last disk(s) of this archive.

unzip:  cannot find zipfile directory in one of latest or

        latest.zip, and cannot find latest.ZIP, period.

By: mpyusko

Can Mautic be managed using ISPconfig?