Install Mautic 4.x on a DigitalOcean VPS (2022)

Mautic is an open-source marketing and email automation application, that’s gaining popularity quickly. Installing Mautic (and maintaining it to run error-free) has proven to be problematic for many. This doesn’t have to be so. In this article, I will show you how to install and set up Mautic Marketing Automation on a DigitalOcean VPS, the proper way.

Note: if you’re not familiar with Mautic and don’t know if it’s a viable option for your business, then have a look at this in-depth Mautic Marketing Automation Review.

Disclaimer: I have republished this Mautic Installation guide because of popular demand. However, I am providing these instructions for people who are going to install Mautic Marketing Automation on their own.

In no way am I going to provide any free support, or solve issues you may have with your Mautic installation. If you decide to follow these instructions you do so of your own accord. If you are not willing to be your own support team, then consider a Cpanel installation with a shared host, instead of following this installation guide.

I use this Mautic installation process myself. The installations have been running without issues for some years and some of the installations hold a contact list of up to 200K users. This installation process is complete.

For Mautic related questions, I recommend joining the official Mautic support forum. If you are a serious business and are in need of help with Mautic, you may (attempt to) hire me.

Table of contents

  1. Create a VPS on DigitalOcean
  2. Set up your DNS to point to a subdomain
  3. Server Setup and Configuration
  4. Install Nginx, Mysql, PHP and Create the Database
    1. Install Webinoly
    2. Add a user for the Admin Tools
    3. Get the MySQL password
    4. Login to PhpMyAdmin and Create the Mautic Database
  5. Download and Install Mautic
    1. Create the Mautic Installation folder
    2. Download Mautic from Github
    3. Enable SSL for your Mautic Installation
    4. Nginx Configuration
    5. HTTP Headers Configuration
    6. PHP Configuration
    7. Reboot your Server
  6. Install Mautic
    1. Cronjob Configuration

Step 1 – Create a VPS on DigitalOcean

Install Mautic on Digitalocean

After creating your VPS, you are ready to log in to your server, configure it so, you can start installing Mautic.

Step 2 – Set up your DNS to point to a subdomain

I recommend you install Mautic on a subdomain of your website, yet on its own server. You can read more about why this is a good idea here.

Installing Mautic on a subdomain (yet, on its own server) will solve a possible third-party cookie placing problem. This is in the works for all major browsers. See the previous link I shared for more explanation.

For example, I recommend installing Mautic on a subdomain of your main website or project you’re working on.

mautic.yourmaindomainname.com

In order to make this happen, log in to your DNS provider and create an A record for the subdomain you’ll be using to install Mautic on. For example, here I am using Cloudflare DNS and I’ve created an A record for my Mautic installation.

mautic installation DNS settings

Remember: it might take up to 48 hours for your subdomain configuration to propagate through the DNS system. However, in my experience, it takes even less than an hour with Cloudflare.

Step 3 – Server Setup and Configuration

In order to properly set up your server, you’ll need to install Putty. This little application will allow you to log in to your server from your windows machine.

  1. Download and install Putty
  2. Enter your server’s IP address in Putty as shown below
  3. Enter your login name (you will be prompted for your password when you log in to your server)
install mautic putty login
mautic installation putty login

After logging into your server you’ll automatically end up in the Linux command prompt (CLI). This is where you’ll start configuring the server and install Mautic.

Mautic Installation on Digitalocean

Note: For the sake of keeping this tutorial simple, it’s okay to install Mautic by logging into your server as root. Later on, you might want to learn how to use SSH keys in order to login to your server, as that’s a best practice for security.

Let’s start our Mautic Installation journey by upgrading our server packages. This is a good practice. Enter the following command in the Linux command line:

apt-get update && apt-get upgrade -y

Step 4 – Install Nginx, Mysql, PHP and Create the Database

Instead of manually installing a web server, database, and PHP, we are going to use an automated script to install the necessary packages.

Step 4.1 Install Webinoly

Login in to your server with putty and download Webinoly. You can copy the line of code below with CTR-C, and copy it in your Putty window with a right mouse button click:

wget -qO weby qrok.es/wy && sudo bash weby 3

The Webinoly installation might take up to 10 minutes. It will configure your server and prepare it for handling sites and web applications (such as Mautic). This script basically installs Nginx as a web server, MySQL for the Database, the PHP scripting language and configures the server to work with these applications. It also installs some administration tools.

Step 4.2 – Add a user for the Admin Tools

As mentioned, Webinoly also installs some administration tools on your server. One of the applications it installs PhpMyAdmin (PMA), which allows you to create the Database that Mautic needs to function.

First, however, you need to add a user for the admin tools. This is because the admin tools page is protected with a password.

Enter the following command:

httpauth -add

This command will ask you to create a user. Write down your username and password. You will use this username and password in order to log in to the page for the administration tools in a bit.

Step 4.3 – Get the MySQL password

Next, we need to retrieve the MySQL password that Webinoly created upon installing MySQL (this is the database software that we are using on the server). In order to retrieve the root password for MySQL, enter the following command:

webinoly -dbpass

This will show you the root password (as well as the admin) password for Mysql. Write down the root password. This is the password you’ll be using in order to log in to PhpMyAdmin and create the Mautic database.

Step 4.4 – Login to PhpMyAdmin and Create the Database

To reach the admin tools, enter your server’s IP address in your browser’s address bar and add a semi-colon with 5 times ‘2’ behind it. Remember that you pasted your newly created server’s IP address in a text file? This is where you’ll need it.

Enter your IP address plus a ‘:22222’ in your address bar, and enter the username:

yourIPaddress:22222

Next, you’ll be prompted with a login box. Remember the user and password you created in step 4.2? This is where you’ll enter them. If you do this correctly, you’ll be able to see the admin tools page.

webinoly admin tools mautic

Enter the user name and password you created in step 4.2

webinoly admin tools mautic

Select pma in the list of administration tools

Next select ‘pma’ (PhpMyadmin) in the list and log in as root. The root password for MySQL is the one you retrieved in step 4.4.

phpmyadmin login screen

Login to PhpMyadmin with the MySQL root password.

create mautic database - phpmyadmin

Select create a database, then enter ‘mautic’ as the database name and select create a database.

Step 5 – Download and install Mautic

Now that you’ve created the database, it’s time to download and install Mautic. Login to your server again with Putty (in case you’ve closed that window).

So, it’s back to the command line now.

Mautic Installation Digitalocean

Step 5.1 – Create the Mautic Installation folder

Next, you’ll create the folder where the Mautic files will live by entering the command below:

site mautic.yourdomainname.com -php

This will set up the configuration for the webserver and create the folders that will hold the Mautic installation files.

Step 5.2 – Download Mautic from Github

The next step is to download the Mautic package from Github. You should select the latest stable release and copy the link address by clicking the right mouse and selecting ‘copy link address‘ in the menu.

download mautic github

Find the latest stable release

mautic download from github

Right mouse click and copy the download link address.

Next, go back to your Linux command line and enter the following command, in order to download Mautic to your server (note the download link is pasted by clicking the right mouse button):

wget https://github.com/mautic/mautic/releases/download/3.0.2/3.0.2.zip

Next, we’ll copy the downloaded .zip file to the Mautic files folder and unzip the file there, by using the following commands. Enter these line by line:

cp 3.0.2.zip /var/www/mautic.yourdomainname.com/htdocs/

cd /var/www/mautic.yourdomainname.com/htdocs/

unzip 3.0.2.zip

rm 3.0.2.zip

Now that the files are in the right folder on your server, we need to make sure that all permissions are set correctly. To set the correct permissions for Mautic, enter the following commands one by one in the command line:

cd /var/www/mautic.yourdomainname.com

chown www-data:www-data -R htdocs

chmod 775 -R htdocs

Step 5.3 – Enable SSL for your Mautic installation

A Mautic installation without SSL is a bad idea. Luckily for us, Webinoly enables us to install a free LetsEncrypt SSL certificate for our Mautic installation. Enter the following line in order to setup SSL easily and quickly:

site mautic.yourdomainname.com -ssl=on

This should automatically configure the SSL certificate.

Note: this will only work if your DNS is propagated (see step 2). This is because for LetsEncrypt to issue a new SSL certificate, it will check if the DNS points to your domain name. If you run into problems here, try again after an hour or so.

Step 5.4 – Nginx Configuration (inc. CORS Mautic)

Before you can install Mautic, you still need to add some extra lines of configuration to the Nginx web server. Without this, Mautic will not work properly and you cannot use the powerful features.

In order to edit the web server configuration files, you’ll use the Nano text editor. This is one of the default text editors that come with your Ubuntu Web Server.

Enter the following command:

nano /var/www/mautic.yourdomainname.com/mautic-nginx.conf

Next copy and paste the following configuration lines into the file:

# Mautic settings start

# Allow the well known challenge for SSL certificates
location ~ /.well-known {
allow all; }

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

# 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)
    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;
    }

# Tracking script
    location ~* /(mtc.js|1.js|generate.js|mtracking.gif|.*\.gif|mtc) {
    # default_type “application/javascript”;
    try_files $uri /index.php$is_args$args;
 }
# Mautic settings end

This is the configuration file for Mautic, which will be included in the original Nginx configuration file. Without these directives, your Mautic installation will not track properly, because it will not be able to find the mtc.js tracking script.

Next, you have to make a change in the original Nginx configuration file, in order to include this extra configuration.

nano /etc/nginx/sites-enabled/mautic.yourdomainname.com

Change the location of the following line, so it’s in the position as in the image below. Make sure you don’t leave it at the bottom of the list where it was earlier.

Mautic Nginx configuration

To save the configuration file, press CTRL+X and then press Y and ENTER.

Step 5.5 – HTTP Headers Configuration

Next we need to reconfigure the HTTP headers file that Nginx uses. Enter the following commands, one by one, to edit the file:

cd /etc/nginx/common

nano headers-http.conf

Comment out the following line by adding a ‘ # ‘ in front of it.

add_header X-Frame-Options SAMEORIGIN;

Add the following line immediately beneath the line you commented out, just now:

add_header X-Frame-Options “”;

mautic nginx settings

Save the file by pressing CTRL+X then Y and ENTER

Step 5.6 – PHP Configuration

Mautic uses PHP 7.4 and lower. Webinoly will install PHP 7.4 by default, so you need to set the server to use PHP 7.4. This is easily done.

stack -php-ver=7.4

Besides that, there are few PHP parameters that need to be set for your Mautic installation to optimally run.

cd /etc/php/7.4/fpm

nano php.ini

Change the default settings in php.ini to the following:

  1. memory_limit = 256M
  2. max_execution_time = 900

Step 5.7 – Reboot your Server

In order for all the changes that you’ve made to the configuration files to take effect, you should now reboot your server. This will restart your web server and all configurations will be loaded.

Enter the following command:

reboot

Step 6 – Install Mautic

Now that you’ve configured the webserver, you can finally install Mautic.

mautic installation digitalocean
  1. Got your mautic.domainname.com in the web browser
  2. Enter your database name: mautic
  3. Enter ‘localhost‘ as your database server
  4. Enter root as the username for the database as well as the root password.
  5. Follow the instructions on the screen.
install mautic digitalocean
  1. Got your mautic.domainname.com in the web browser
  2. Enter your database name: mautic
  3. Enter ‘localhost(not mysql) as your database server
  4. Enter root as the username for the database as well as the root password.
Mautic Install on digitalocean
  1. Enter the username you want to create to log into Mautic. For example admin
  2. Enter the password for your Mautic user.
  3. Enter your first name and email address.
  4. Press the next step.

Now that you’ve installed Mautic and you are able to log in, you might think that you are done. This is not the case. For Mautic to function properly, you still have to configure the Mautic cronjobs. This is the part where many users go wrong. Don’t worry though, because you can just copy and paste the configuration that I use in the next step.

Step 6.1 – Configure Mautic Cronjobs

Without configuring the Mautic Cronjobs, Mautic will not function properly.

Log in to your server once again with Putty and enter the following command:

crontab -e

Choose Nano as your editor (the system will give you a list to choose from), and enter the following into the crontab. Just copy and paste the following code underneath the lines that are already present.

Remember: you can paste these lines with the right mouse button.


0,5,10,15,20,25,30,35,40,45,50,55 * * * * php /var/www/mautic.yourdomainname.com//htdocs/bin/console mautic:segments:update > /dev/null 2>&1
3,8,12,17,22,27.32.37,42,47,52,57 * * * * php /var/www/mautic.yourdomainname.com//htdocs/bin/console mautic:campaigns:update > /dev/null 2>&1
1,6,11,16,21,26,31,36,41,46,51,56 * * * * php /var/www/mautic.yourdomainname.com//htdocs/bin/console mautic:campaigns:trigger > /dev/null 2>&1
*/10 * * * * php /var/www/mautic.yourdomainname.com/htdocs/bin/console mautic:broadcasts:send > /dev/null 2>&1
0,15,30,45 * * * * php /var/www/mautic.yourdomainname.com/htdocs/bin/console mautic:emails:send > /dev/null 2>&1
15 * * * * php /var/www/mautic.yourdomainname.com/htdocs/bin/console mautic:webhooks:process > /dev/null 2>&1
0 0 1 * * php /var/www/mautic.yourdomainname.com/htdocs/bin/console mautic:maintenance:cleanup –-days-old=90 –no-interaction > /dev/null 2>&1
0 4 * * * php /var/www/mautic.yourdomainname.com/htdocs/bin/console mautic:iplookup:download > /dev/null 2>&1

Save the file by pressing CTRL+X, followed by Y and ENTER.

Note: be sure to use your own domain name in the lines if you copy and paste this configuration. For more information about Mautic Cronjobs, how they work, please have a look at this Mautic Documentation. This is the configuration I prefer, however you might want to customize it to your needs if necessary.

Congratulations! You’ve just installed Mautic on a high-performance DigitalOcean server, in the proper way. You can now start using Mautic properly!

Wrapping up

Best practices

  • Keeping the server up to date – Log in to your Mautic hosting server every week and update the packages that are installed on the server. This is done with the terminal command: apt-get update && apt-get upgrade -y
  • Hardening your server – For the sake of simplicity, in this tutorial, we’ve used the root user in order to install Mautic. You are using this root user in order to log in to your server. I recommend creating another user and logging into your server under that user. DigitalOcean provides some very clear documentation about how to add a new user and log into your server using SSH keys.
  • Making Backups – Always take a snapshot of your Mautic installation before changing any configuration or updating Mautic. That way you can still revert back to your previous installation if something goes wrong. My rule of thumb is to take a snapshot before I do anything on the server level.
  • Upgrading your server – If you’ve installed Mautic on a 20 USD / Month server, you’ll easily be able to manage a list of up to 100K contacts (if not much more). Whenever you feel the system is getting slower, you can upgrade the server with a click of a button in the DigitalOcean Dashboard.
  • Installation issues to avoid – Have a look at this Mautic Installation Errors article in order to understand a little bit more about common installation issues.
  • Clearing Mautic cache – If you’ve followed the Mautic installation best practices, you might still run into issues once in a while. In case of any issues, the first thing to try is clearing the Mautic cache and resetting the permissions on the root folder. In my experience, 85% of the Mautic issues are solved by clearing the cache and resetting the permissions.
  • Mautic Cron Jobs – Always make sure that your cron jobs are running. Wrongly configured cron jobs basically keep Mautic from doing anything at all. If you’re experiencing segments not updating, emails not being sent, or campaigns not being executed, the first thing to do is check the cron jobs. You can also check if Cron jobs are being executed in your system Syslog (which you can find at: /var/logs/syslog).
  • Mautic error log messages – At times, you’ll notice some Mautic or PHP notices in the error log. Notices are not necessary errors and they are usually nothing to worry about. They show up with different PHP versions, because of more sensitive error reporting settings. When you start seeing ‘critical warnings’, is the time that you should start paying attention.

Join the Mautic discussion

Because Mautic installation on-premise (your own VPS or Dedicated server) is such a popular topic, I’ve decided to open up the comment section, so a discussion with fellow Mautic users becomes possible. Keep in mind, however, that this is not a Mautic support section. If you need Mautic support I recommend you try the official Mautic forum.

If you still need help with Mautic, then feel free to contact me.

Install Mautic Digitalocean