Here is a simple step by step guide about installing Mautic 4 on a clean Ubuntu 18.04 server. Enjoy.

Watch the video or enjoy the step by step guide with all the commands you need below.

Install prerequisites

Configure your timezone

dpkg-reconfigure tzdata

Install PHP prerequisits

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

Install required packages

apt install apache2 libapache2-mod-php7.4 php7.4 unzip php7.4-xml php7.4-mysql php7.4-imap php7.4-zip php7.4-intl php7.4-curl php7.4-gd php7.4-mbstring php7.4-bcmath ntp -y

Install MariaDB 10.5

This method will install from the official repo:

sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] http://mirror.lstn.net/mariadb/repo/10.5/ubuntu bionic main'
sudo apt update
sudo apt install mariadb-server

Configure Apache2

Configure Apache2 site configuration file for Mautic. This file will control how users access Mautic content. Run the commands below to create a new configuration file called mautic.conf

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

Then copy and paste the content below into the file and save it. Replace the highlighted line with your own domain name and directory root location.

<VirtualHost *:80>
     ServerAdmin admin@yoursite.com
     DocumentRoot /var/www/html/mautic
     ServerName 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>

Add SSL

sudo add-apt-repository ppa:certbot/certbot
apt update && apt upgrade -y


sudo apt-get install python-certbot-apache

Initiate Certbot setup

certbot --apache -d subdomain.yourdomain.com

Once you configured the Virtual Host as above, you’ll need to enable it by running following the commands:

sudo a2ensite mautic.conf
sudo a2enmod rewrite

Tweak PHP settings

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

Some of these settings will be already set as below, but you still need to make all the necessary changes.

You can anytime search in the file editor with CTRL+W.

file_uploads = On
allow_url_fopen = On
short_open_tag = On
memory_limit = 256M
upload_max_filesize = 100M
max_execution_time = 300
post_max_size = 200M
date.timezone = "Europe/Zurich"

(When you finished, you can close the file with CTRL+X and Y + Enter)

It is time to restart Apache to validate all changes.

sudo systemctl restart apache2.service

Create our database

Once we installed the database, let’s secure our installation.

sudo mysql_secure_installation

When prompted, answer the questions below as follows:

Enter current password for root (enter for none): Just press the Enter
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

Stop and restart the server

sudo systemctl stop mariadb.service
sudo systemctl start mariadb.service

Mautic needs a database to run, so we will make an empty database first.

We need to log in into our MariaDB database server, with the following commands below.

CREATE DATABASE mauticdb;

Create a database user called mauticuser with new password. This is a password, which will be used for especially this database. Do not use your root password.

CREATE USER 'mauticuser'@'localhost' IDENTIFIED BY 'YOURSTORNGPSW';

Then grant the user full access to the database. (Make sure you use the password you just gave above)

GRANT ALL ON mauticdb.* TO 'mauticuser'@'localhost' IDENTIFIED BY 'YOURSTRONGPSW' WITH GRANT OPTION;

We are done, save your changes and exit.

FLUSH PRIVILEGES;
EXIT;

Download Mautic

Let’s download the newest version from Github

mkdir /var/www/html/mautic
cd /var/www/html/mautic
wget https://github.com/mautic/mautic/releases/download/4.0.0/4.0.0.zip
unzip 4.0.0.zip
rm 4.0.0.zip

Reset ownership and permisssions

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

Reload Apache

service apache2 reload

Save the file and exit. You know now how by now 🙂

Install Mautic

Now, open your browser and browse to your domain name. You should see Mautic setup wizard.

You supposed to see something like the following screenshot:

Mautic 4 Installation environment check

If you don’t see anything red, we are good to go. Click on Next step.

Mautic 4 installation setting database access

Fill out the fields with the database nane, database user name and passwords as set previously.

Mautic 4 installation user login settings

Now we need to create the credentials of our main admin user.

You can specify the SMTP settings here, but that differs based on your SMTP service provider. You can also leave it empty and click on next.

Hopefully you will see a login screen. Congratulations. You are almost done!

Add cronjobs

I like to run my cron commands sequentially, and this is why I add them to a single file.

nano /usr/local/bin/mauticcrons.sh

I have a fine tuned cron script, but you can change each element if you know what you are doing:

#!/bin/bash

MAUTICCONSOLE="/var/www/html/mautic/bin/console"


if [ -z "$(ls -A /var/www/html/mautic/var/spool)" ]; then

	php $MAUTICCONSOLE mautic:broadcasts:send --limit=50
	php $MAUTICCONSOLE mautic:campaigns:rebuild --batch-limit=300
	php $MAUTICCONSOLE mautic:segment:update --batch-limit=900
	php $MAUTICCONSOLE mautic:campaigns:trigger
	php $MAUTICCONSOLE mautic:import --limit=500
	php $MAUTICCONSOLE mautic:webhooks:process
	php $MAUTICCONSOLE mautic:reports:scheduler
	php $MAUTICCONSOLE mautic:maintenance:cleanup --days-old=365

else
	php $MAUTICCONSOLE mautic:broadcasts:send --limit=200
	php $MAUTICCONSOLE mautic:emails:send --message-limit=200
fi

Save it, and open the crontab:

crontab -e

Add the script to the cron and run it every minute:

* * * * * /bin/bash /usr/local/bin/mauticcrons.sh

Enjoy, you are ready!

Tags:

53 Comment

  • Daniel Wood

    says:

    Thanks, your guide is clear and straightforward: even I was able to follow along and get it to work (I think). My only stumble was right between changing the permissions for the Mautic folder and going to the webpage and finishing up the install via browser.
    You have

    “Save the file and exit. You know now how by now”

    I wasn’t sure which file, hoping I haven’t missed anything crucial.

    Thanks again for the guide!

    Reply
  • jayson eballena

    says:

    Hi Joey! great work I followed your guide and successfully installed it.
    But the problem is that, I already put the domain name as the serverName and added ssl certificate to the subdomain just like you mentioned, but still when I access the url it says “URL not found” with the mautic logo and mautic 404 page. Just for info also, I also set AllowOverride to all. Thanks for the help.

    Reply
    • jos0405

      says:

      Hi,
      Sorry that you have trouble. Does your subdomain resolve to Mautic? You said you can see a Mautic logo. Did you install successfully?

      Reply
    • jos0405

      says:

      Hello Jason,
      Did you apply SSL? What is the exact error you see? Is it like 404 Page not Found, Domain not found or 503 Connection error?

      Reply
  • Andres Berger

    says:

    I finished this installation. Thank you Joey for this, really appreaciate this.

    But. running every cron simultaneously every minute is not against the recommendations? will not be excessive burden for the VPS?

    Reply
    • jos0405

      says:

      Hallo Andreas!
      The goal is to make sure you set limitations for running the cron in such a way, that all scripts are ending within 1 minute.
      This way if you are running them every min, you’ll be totally fine.

      Reply
      • Andres Berger

        says:

        Still. Why don’t run them every hour or so and 10 minutes gaps between them, most of us are not super desperate to send the email super fast.

        if your email is not transactional, then running all crons every minute is wasting a lot of server resources…. I think….

        Reply
  • Willie

    says:

    What’s better: this way or docker? I’m seeing more and more FOSS platforms push docker as the default install method. Are there any advantages to this non-containerized install?

    Reply
    • jos0405

      says:

      Hi, you can do this in a linux container if you want, the commands are the same.
      If you know how to work with docker, there is no reason why not to use it. We at Friendly.ch are using LXC containers.
      I’m a huge fan of containers, I containerise everything 🙂 But managing containers need more skills, it’s not for everyone.

      Reply
  • Antenaina Flavio Steven Rakotoarivelo

    says:

    Hello , nice tutorial !! Appreciate it !
    Is it the same tuto if i’m using UBUNTU 20.04 please ? Thank you !

    Reply
  • Victor Hugo

    says:

    Hi joey is it possible to do this installation without using https? in this case the certificate? I have an error that I can’t get past the first post installation step

    Reply
    • jos0405

      says:

      There are many ways to add SSL, and you should definetly do it.
      I didn’t add to this tutorial, but you can find many good guides out there. Any SSL tutorial will do.

      Reply
  • Andres

    says:

    Joey

    That cron jobs doesn’t work. Campaigns are only sending the first email.
    I tried to run one of the crons manually like this:

    php /var/www/html/mautic/bin/console mautic:campaigns:trigger

    and got:

    _______________________________________

    In ConnectionFactory.php line 134:

    An exception occurred while establishing a connection to figure out your platform version.
    You can circumvent this by setting a ‘server_version’ configuration value

    For further information have a look at:
    https://github.com/doctrine/DoctrineBundle/issues/673

    In AbstractMySQLDriver.php line 112:

    An exception occurred in driver: Access denied for user ‘tjzkuwtj_maut698’@’localhost’ (using password: YES)

    In ConnectionFailed.php line 19:

    Access denied for user ‘tjzkuwtj_maut698’@’localhost’ (using password: YES)

    ————————

    I will read the thing on Github, but I never created those database users…

    Reply
  • Andres

    says:

    Hi Joey

    There is one more crazy stuff to add to Mautic.

    I found in some place that maybe changing the type of sending from marketing to transaccional could make the difference and really did, I received the complete sequence of emails after changing that…. (I was in the verge of deleting Mautic and the server)

    Previously I was wondering why the tracking button not worked and I thought maybe the variable is stored within the emails themselves, so deleted all emails, recreated them and the click tracking was gone (Google really hate those, so I prefer to not track than client not being able to open the links sent).

    There should be a video explaining users all these potential problems when you are on your way to test Mautic in order to not go crazy.

    And by the way, your crons work correctly!

    Regards

    Reply
    • jos0405

      says:

      Hello Andres,
      There is a video. Your issue was probably this: https://youtu.be/Pz8vLl-Lmww
      Your emails were queued up due to daily email limit settings.
      Regarding the tracking: I’m talking about how to test your emails and how the admin cookie changes the way you experience Mautic.
      Check my free course, it’s in there.

      Reply
  • John Tourgee

    says:

    Joey,
    Thanks for this tutorial! Every thing seemed to work but I ended up with at the “I broke it” screen and no logs. where do I start to look to fix it?

    Reply
  • Chirayu

    says:

    Hi… Thank you for this step-by-step guide. It is really very helpful for a person like me, who is non-technical.
    I followed your every step as it is and installed the 4.2.1 version of mautic. And unable to active SSL due to crossing the limit of 5 certi per week. So right now I am handling mautic through http://myipaddress
    Now I am facing 2 problems:
    1) Showing OPEN EMAIL, even without opening it! And it triggers the next action set in the campaign.
    2) Not able to track landing page visits and WordPress website visits (After setup of “Tracking Setting”)
    3) It’s Take too much time to load the “configuration” page
    (Not showing any error in log file)

    My server @ AWS
    Instance Type: t3a.small | vCPUs : 2 | Memory(GiB): 2

    Please guide me. Thank you

    Reply
    • jos0405

      says:

      Hello!
      Once you pass the 5 = week limit it will be okay. Just redo your SSL, and try not to mess up 🙂
      1. This happens on apple devices. Nothing you can do about it. I wouldn’t base my campaigns on email opens.
      2. This happens because you don’t have SSL
      3. This can happen if you have a slow instance. 2 GIG / 2 CPU is small.

      Reply
      • Chirayu

        says:

        Thank you very much for your quick responce.
        1) I tried to send an email to xyz@gmail.com and it was android based mobile. The sender’s and receiver’s both devices were NON-APPLE devices. Though facing the same problem.
        2) Ok. Got it.
        3) Can you guide me that which instance type is more suitable to handle 5k contact?

        Thank you again!

        Reply
  • Nicolas Jardillier

    says:

    Hi and thanks for sharing a lot 😉

    In the cron script, why there is not :
    php $MAUTICCONSOLE mautic:emails:send

    in the condition :
    if [ -z “$(ls -A /var/www/html/mautic/var/spool)” ]; then

    Best

    Reply
  • erico

    says:

    Hello Joey

    Im using aaPanel adding a shell script but getting this weird error

    +———+——–+———-+
    | Channel | # sent | # failed |
    +———+——–+———-+
    Webhook Bundle is in immediate process mode. To use the command function change to command mode.
    Scheduler has finished
    This will permanently delete data older than 365 days! Please make a backup before proceeding. Run this command with –dry-run to get approximate records to be deleted. Continue? (y/n) —————————————————————————-
    ★[2022-11-10 19:56:08] Successful

    Reply
  • jos0405

    says:

    This is not an error.
    It happens when you run the cleanup script.

    | Channel | # sent | # failed |
    will only be populated if you send emails. So you would see the numbers under the respective columns.

    Reply
  • Garret Acott

    says:

    Hey man, great stuff, but why aren’t you using composer? Doesn’t it bring more functionality? Like the Market Place?

    Reply
    • jos0405

      says:

      Hey, for 2 reasons:
      1. this article is before Marketplace was launched.
      2. composer update is bumpy at the momment (2022.DEC), you might delete you whole Mautic db upon a composer update.

      Reply
  • Rahul

    says:

    Hi i have installed mautic 4.1 in ubuntu 22.04 via nginx
    evrything seems to be fine the test emails are going out but when i create a segment email and send it out its just gets stuck and the emails are not sent out im not able to figure out the issue
    here are my cron jobs:
    */5 * * * * /usr/bin/php8.0 /var/www/mautic/bin/console mautic:segments:update > /dev/null 2>&1
    */15 * * * * /usr/bin/php8.0 /var/www/mautic/bin/console mautic:webhooks:process > /dev/null 2>&1
    */10 * * * * /usr/bin/php8.0 /var/www/mautic/bin/console mautic:leadlists:update > /dev/null 2>&1
    */10 * * * * /usr/bin/php8.0 /var/www/mautic/bin/console mautic:campaigns:update > /dev/null 2>&1
    */5 * * * * /usr/bin/php8.0 /var/www/mautic/bin/console mautic:campaigns:trigger > /dev/null 2>&1
    */10 * * * * /usr/bin/php8.0 /var/www/mautic/bin/console mautic:social:monitoring > /dev/null 2>&1
    */5 * * * * /usr/bin/php8.0 /var/www/mautic/bin/console mautic:emails:send > /dev/null 2>&1
    0 0 * * * /usr/bin/php8.0 /var/www/mautic/bin/console mautic:fetch:email > /dev/null 2>&1
    0 0 * * * /usr/bin/php8.0 /var/www/mautic/bin/console mautic:iplookup:download > /dev/null 2>&1
    */15 * * * * /usr/bin/php8.0 /var/www/mautic/bin/console mautic:campaigns:rebuild > /dev/null 2>&1
    */15 * * * * /usr/bin/php8.0 /var/www/mautic/bin/console mautic:reports:scheduler > /dev/null 2>&1
    */15 * * * * /usr/bin/php8.0 /var/www/mautic/bin/console mautic:email:process > /dev/null 2>&1

    can u please help

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *