Install a fully functional Mautic 3 on a Raspberry Pi

There are two kinds of projects, that make the geek heart beat faster: Install Doom on any device, and run any software on a Raspberry Pi.

I was shocked to find out that there is no proper instructions on the internet for installing Mautic on a Rapsberry Pi, so I figured, this outragous neglection has to be addressed as soon as possible.

If I plan to install Mautic, I have to make sure, fully functional.

  • Runs reasonably fast
  • All crons run nice and optimized
  • Email sending works, DKIM, SPF, Dmarc is set
  • Site tracking works on a WordPress blog
  • Mautic resolves on a DNS, even it’s hosted at home

And I will use a Raspberry Pi 2, since my 3 and 4 are not available, as they are busy serving my media consumption and retro gaming needs. But if I manage to make it work on a Raspberry Pi 2, it will be 4-12 times faster on newer boards.

Before you read further: Your chance to get Mautic Tips and Secrets in Your inbox!

In this weekly email you’ll recieve never published guides, ready to deploy code samples, premium templates!

Step 1: Install the Operation system

After looking into some operation systems, I went with Diet-Pi. Super optimised, well maintained, lightweight. Head over to dietpi.com, get your copy. I recommend to use a 16 GB SD card to have enough space, but it’s really up to you. Once you downloaded your DietPi, you can burn it with balenaEtcher.

Plug in the SD card, connect it to your local network. No screen, keyboard or mouse needed., just boot it up. Now go to your router’s DHCP settings and list your DHCP devices. Your Rpi will be listed, make a note of it’s IP address.

Now connect to your Dietpi using SSH. Login and password will the the default: dietpi/dietpi.

Step 2: Install Apache and MariaDB

Update your distro, and enter a simple commands to get your webserver running:

sudo apt update
sudo apt upgrade
sudo apt install apache2 -y

Jump over to your browser and enter the IP address of your Rpi and you’ll see the the default Apache page already.

Step 3: Tie in our domain name

Head to your router, and set up port forwarding. All incoming traffic on port 80 and 443 should be rerouted to the IP of your Rpi. You might have to restart your router for changes to take effect.

Check if the routing works by entering your IP into the address bar of your browser. If the Apache test site is visible, you are all good.

If we want to install a fully functioning Mautic, we need to have a proper domain name. Not just a free DynDNS, that comes built in into most modern routers. In order to inbox our email campaigns we need to set DKIM, SPF. We need a full domain name, that we can control entirely.

To make this happen will use Cloudflare API to take care of this for us, so go to cloudflare, open your domain and add a subdomain:

In order to control this domain with our API script, we will need to get our Global API key.

Go to your Cloudflare profile / API tokens, scroll down and View your Global Api Key.
Complete the password challenge and write down your api key.

Now head back to your Rpi, and deploy the api script. We start the process with creating a folder for our operations.

mkdir cf

Install nano editor if you don’t have it, create a file called lwp-cloudflare-dyndns.sh. Head to Github and copy + paste the contents into that file from from here.

Change the following settings:

auth_email="[email protected]" // this is your cloudflare login email
auth_key="global_api_key_goes_here" // this is the Global API Key you wrote down above
zone_name="example.com" // The main domain, you want to edit via API
record_name="home.example.com" // The specific record that should point at this raspberry pi

Let’s make the file executable:

chmod +x cf/lwp-cloudflare-dyndns.sh

If you run this code, it will create a cloudflare.ids file. That file will contain the id of your dns records. It is essential to allow your script to change the right IP dynamically.
Now we will automate the process by running it from the cron:

crontab -e

Set to run the script every 10 minutes to guarantee solid availability.

*/10 * * * * /bin/bash /home/pi/cf/lwp-cloudflare-dyndns.sh

Once you run the script, it will update your Cloudflare records and the sudomain you set will resolve in your rPi and the Apache test page will appear.

Step 4: Install depdendencies

Now we can install the software needed to run Mautic.

Firstly install MariaDB:

sudo apt-get install mariadb-server mariadb-client
sudo systemctl start mariadb.service
sudo mysql_secure_installation

Secondly, enter the following values:

Enter current password for root (enter for none): 
Set root password? [Y/n]: Y
New password: Enter password
Re-enter new password: Repeat password
Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]: Y
Reload privilege tables now? [Y/n]: Y

Thirdly install php and extra modules:

sudo apt-get install php -y
sudo apt install php libapache2-mod-php -y
sudo apt install php-zip ext-dom php-xml php-mbstring php-imap php-curl php-bcmath php-gd

Your php.ini will be most likely in the following folder:

cd /etc/php/7.3/apache2/
nano php.ini

Make the proper settings to run Mautic flowlessly:

file_uploads = On
allow_url_fopen = On
short_open_tag = On
memory_limit = 256M
upload_max_filesize = 100M
max_execution_time = 300

Step 5: configure Apache and create database

Now we need to make sure our little Pi knows he has to wave its tiny hand, when someone is looking for that subdomain. sp let’s add the virtual server. In this tutorial I’ll go for berry.yoursite.com:

sudo nano /etc/apache2/sites-available/mautic.conf

Control + C the following configuration and save:

<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/mautic
ServerName berry.yoursite.com
<Directory /var/www/html/mautic/>
Options +FollowSymlinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log
combined
</VirtualHost>

Save your config, so you can enable the virtual server with the following commands:

sudo a2ensite mautic.conf
sudo a2enmod rewrite
sudo systemctl restart apache2.service

Let’s go back to our database service

sudo mysql

With a few hand crafted Mysql commands we can create a new database, user, add privileges:

CREATE DATABASE mauticdb;
CREATE USER 'mauticuser'@'localhost' IDENTIFIED BY 'yoursafepsw';
GRANT ALL ON mauticdb.* TO 'mauticuser'@'localhost' IDENTIFIED BY 'yoursafepsw' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;

Step 6: Install Mautic via Github

In order to have an always up-to-date environment for Mautic, we will use Github for the installation.
First should install Composer, then Curl and everything else we need.

sudo apt install curl git
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

Next step is cloning Mautic from github:

cd /var/www/html
sudo git clone https://github.com/mautic/mautic.git
cd /var/www/html/mautic
sudo composer install

Make sure your permissions and ownership are set properly:

sudo chown -R www-data:www-data /var/www/html/mautic/
sudo chmod -R 755 /var/www/html/mautic/

Now you are all set, so it’s time to finish the install via the GUI. There are a bunch of tutorials for that, I’ll skip the detailed guide for that, and it is really just 3 steps anyway:

By entering the domain, we can finally log in into our instance. If all went well, the dashboard should greet us cheerfully:

Let’s create an shell script chaining up all cron commands:

nano /usr/local/bin/mauticcrons.sh

Add the Mautic cron jobs:

!/bin/bash
php /var/www/html/mautic/app/console mautic:broadcasts:send --limit=100
php /var/www/html/mautic/app/console mautic:campaigns:rebuild --batch-limit=100
php /var/www/html/mautic/app/console mautic:segment:update --batch-limit=300
php /var/www/html/mautic/app/console mautic:campaigns:trigger
php /var/www/html/mautic/app/console mautic:import --limit=250
php /var/www/html/mautic/app/console mautic:emails:send --message-limit=200

Open your crontab, so you can run the above script as a cron commands:

sudo crontab -e
* * * * * /bin/bash /usr/local/bin/mauticcrons.sh

Okay, now we are closer than ever, bear with me.

Step 7: Add email to Mautic

We will add now email sending capabilities to make sure our Rapsberry Pi is a full featured marketing machine. The Amazon SES account I’m gonna use is out from the sandbox so we can already set it up. Let’s also assume, we created the mailbox for our Mautic as well.

Head to Amazon SES so you can choose the right region. By adding a new email address the verification process is fired up.

A verification email will arrive to this mailbox in a jiffy, and after you clicked the link, your email sending capability will become borderless. (Well, almost.) Now head to Simple Notification Service in the Amazon Console and add the SMTP endpoint:

Add the topic name:

Click next and add the subscription url to create a new subscription:

I’m using SMTP here, so the subscription URL will be:

Now head back to Amazon SES and add your subscription to the bounce handling section in your email:

Add your topics in the bounce and complaint management section to ensure your bounce feedback loops are assigned to the email in question.

We still need to create our SMTP creds, which is done by clicking on SMTP Settings.

Create your new SMTP username and password. Firstly make sure you are aware of which region you are using here, secondly make sure you are choosing Amazon SMTP as email method.
After that head back to your Raspberry Mautic configuration and enter your email settings:

You can test by clicking on Test connection if you doubt yourself 🙂 Okay, your email sending is ready to go.

Step 8: Benchmarking:

Now that we have our amazing Mautic at home, let’s see what the capabilities are. I ran couple of tests on it, and the finding were the followings:

Import ing 10k contacts

This is really slow, but who cares – unless you are a spammer, you don’t have to do this all the time 🙂

Mautic Action Execution Time
Segments update 10k2m 50s
Campaigns update 10k3m 40s
Campaigns trigger 10k12m 40s
Email Broadcast queue 10k5m 20s
Email sending (from queue) 10k45m 10s

Summary

Altough this project was very close to a regular Mautic on a VPS setup, which I do every day, I truely enjoyed it and learned some things along the way. I used an old Rpi 2 for this project, and as you can see in the benchmarking part of this article it performed not so bad for a tiny robot as it is :). Made me also super curious, how it would perform on an Rpi4, so you can expect a follow up to this guide in the near future. As this Rpaspberry Pi is fully functional, and if you have a domain name, a subdomain with the free dynamic DNS solution using the Cloudflare API won’t cost you anything extra. You can use it to automate your marketing of your blog or small business, all you need to pay for is the little electricity this bad boy consumes.