How to Install Mautic on CentOS 7

Updated on November 21, 2023
How to Install Mautic on CentOS 7 header image

Mautic is powerful and versatile open source marketing automation software written in PHP. With the help of Mautic, online marketers can easily manage various daily marketing routines in one place, including social media engagement, contacts, email marketing, forms, campaign management, data analysis reports, etc.

In this article, I will show you how to deploy the latest stable release of Mautic, which was Mautic 2.9.2 at the time of this article was written, on a Vultr CentOS 7 server instance. Of course, before installing Mautic, we need to setup an up-to-date and functional LAMP/LEMP stack as the infrastructure of the system. For your information, instructions for setting up a qualified LAMP stack are included herein.

Prerequisites

  • A fresh Vultr CentOS 7 server instance with sufficient RAM, 1GB or more of RAM recommended. Say its IP address is 203.0.113.1, and the domain bound to this server is example.com.
  • A sudo user.

Step 1: Setup a swap file (Optional)

First of all, open your favorite SSH terminal, log into your Vultr server instance as a sudo user.

In order to get better performance when performing massive parallel campaign tasks, you can setup a swap file using the following commands:

sudo dd if=/dev/zero of=/swapfile count=2048 bs=1M
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile   none    swap    sw    0   0' | sudo tee -a /etc/fstab

Note: the swap size 2048MB herein is an optimized value for machines with 1GB of RAM. If the amount of your machine's RAM is different from that, you probably need to modify the value accordingly.

Step 2: Update the system

For security purposes, you are always suggested to update the system to the latest stable status:

sudo yum install epel-release -y
sudo yum update -y && sudo shutdown -r now

After the system reboot, log back in as the same sudo user.

Step 3: Install and configure Apache

Use the following command to install the latest stable release of Apache, which was Apache 2.4.6 when I wrote this article:

sudo yum install httpd -y

In a production environment, you need to remove the default welcome page by commenting out the whole /etc/httpd/conf.d/welcome.conf file:

sudo sed -i 's/^/#&/g' /etc/httpd/conf.d/welcome.conf

Still for security reasons, you need to restrict Apache from displaying file URLs in visitors' web browsers:

sudo sed -i "s/Options Indexes FollowSymLinks/Options FollowSymLinks/" /etc/httpd/conf/httpd.conf

Now, you need to start the Apache service and make it start every time the system boots up:

sudo systemctl start httpd.service
sudo systemctl enable httpd.service

Step 4: Install and secure MariaDB 10.2.x

4.1 Install MariaDB 10.2.x

You can use the following commands to install and start the latest stable release of MariaDB on your system, which was MariaDB 10.2.8 at the time I wrote this article:

curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
sudo yum install MariaDB-server MariaDB-client -y
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

4.2 Secure the MariaDB installation

In order to secure the MariaDB installation on your system, you need to run the following command before using MariaDB:

sudo /usr/bin/mysql_secure_installation

When prompted, answer questions as shown below. Be sure to use your own MariaDB root password rather than the sample password shown here:

  • Enter current password for root (enter for none): Just press the Enter button
  • Set root password? [Y/n]: Y
  • New password: your-MariaDB-root-password
  • Re-enter new password: your-MariaDB-root-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

Step 5: Install and configure PHP 7.0.x

5.1 Install PHP 7.0.x

Since Mautic is not compatible with PHP 7.1.x yet, you can install necessary PHP 7.0.x components using the Webtatic repositories:

sudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
sudo yum install -y php70w php70w-mysqlnd php70w-common php70w-cli php70w-xml php70w-mbstring php70w-gd php70w-mcrypt php70w-opcache php70w-imap php70w-process php70w-intl

Having these PHP 7.0.x components properly installed, you need to modify several default PHP configurations by editing the /etc/php.ini file. But in order to prevent unintended errors, you should make a backup for the /etc/php.ini file before editing it:

sudo cp /etc/php.ini /etc/php.ini.bak

5.2 Setup the timezone value

Use the vi editor to open the /etc/php.ini file:

sudo vi /etc/php.ini

In order to get correct numbers for your campaigns, it is important to setup a reasonable timezone value for Mautic.

Find the line:

;date.timezone =

Replace it with:

date.timezone = America/Los_Angeles

_Note: America/Los_Angeles is the proper timezone value for my machine. In accordance with the exact location of your own server instance, you may need to choose another timezone value. See the list of supported timezones on this page.

5.3 Increase the memory limit

In order to prevent Mautic from running out of memory while executing various consuming tasks, such as sending mass email campaigns, you should increase the memory limit for running a PHP script.

Still in the /etc/php.ini file, find the line:

memory_limit = 128M

Replace it with:

memory_limit = 256M

Save and quit:

:wq!

Step 6: Install Composer and git

For dependency management and version control purposes, you should install Composer and git before starting to install Mautic.

6.1 Install Composer

Composer is a dependency managing tool in PHP, which can help you easily manage dependencies for Mautic. You can use the following commands to install Composer 1.5.1, the latest stable release of Composer at the time of this article was written:

cd
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer

Note: The instructions for installing Composer may vary in the future. You should always check out the up to date instructions on the official Composer download page.

6.2 Install Git

Git is also needed when deploying Mautic on your own machine, and you can easily install Git using the following command:

sudo yum install git -y

Step 7: Install Mautic

7.1 Create a MariaDB database and a dedicated database user for Mautic

Before you can install Mautic, you need to create a database and a dedicated database user to handle all of the Mautic data.

Log into the MariaDB shell as MariaDB root:

mysql -u root -p

In the MySQL/MariaDB shell, enter the following commands to create a database named mautic, a database user named mauticuser, and this user's password yourpassword.

Notice: For security purposes, when operating on your own server instance, be sure to replace parameter values mentioned above with your own ones.

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

7.2 Prepare Mautic installation files

You can always get the latest stable release of Mautic from the Mautic GitHub repository. At the time I wrote this article, the latest stable release of Mautic was Mautic 2.9.2.

cd
wget https://github.com/mautic/mautic/archive/2.9.2.tar.gz

Uncompress this archive file:

tar -zxvf 2.9.2.tar.gz

Use Git and Composer to install dependencies for Mautic:

cd mautic-2.9.2
git init
composer install

In order to simplify future updates, move all Mautic files to /opt and then create a soft link file /var/www/html/mautic pointing to this directory from the web root directory:

sudo mv ~/mautic-2.9.2 /opt
sudo ln -s /opt/mautic-2.9.2 /var/www/html/mautic

Modify the ownership of the Mautic directory, allowing Apache to access files within:

sudo chown -R apache:apache /opt/mautic-2.9.2

7.3 Setup an Apache virtual host for Mautic

You can use the following code segment to setup an Apache virtual host for running Mautic. Just copy the whole code segment into your SSH terminal and then press the Enter button.

Note: Remember to modify the values of ServerAdmin, ServerName, and ServerAlias on your machine accordingly.

cat <<EOF | sudo tee -a /etc/httpd/conf.d/mautic.conf
<VirtualHost *:80>
ServerAdmin admin@example.com
DocumentRoot /var/www/html/mautic/
ServerName mautic.example.com
ServerAlias www.mautic.example.com
<Directory /var/www/html/mautic/>
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/httpd/mautic.example.com-error_log
CustomLog /var/log/httpd/mautic.example.com-access_log common
</VirtualHost>
EOF

Next, restart Apache in order to put all of your changes into effect:

sudo systemctl restart httpd.service

7.4 Modify firewall rules

In order to allow visitors to access Mautic from a web browser, you need to modify firewall rules as shown below:

sudo firewall-cmd --zone=public --permanent --add-service=http
sudo firewall-cmd --reload

7.5 Finish installing Mautic from a web browser

Point your favorite web browser to http://203.0.113.1, and then you will be brought into the Mautic web installer interface.

On the Mautic Installation - Environment Check page, you will see the Ready to install! prompt message. Just click the Next Step button to move on.

On the Mautic Installation - Database Setup page, input all required database info, leaving other fields untouched, and then click the Next Step button.

For example, all required database info from this guide is listed below:

  • Database Driver: MySQL PDO (Recommended)
  • Database Host: localhost
  • Database Name: mautic
  • Database Username: mauticuser
  • Database Password: yourpassword

On the Mautic Installation - Administrative User page, input the required admin user info as follows, and then click the Next Step button.

For example, my administrative user info is:

  • Admin Username: <admin>
  • Admin Password: <mautic-admin-password>
  • First name: John
  • Last name: Doe
  • E-mail Address: admin@example.com

On the Mautic Installation - Email Configuration page, choose a proper mailer transport method, and then click the Next Step button to finish the web installation wizard.

On the Mautic login page, log in with your administrative user's credentials.

7.6 Post-installation Maintenance

In order to keep Mautic up and running, you need to setup several cron jobs to execute maintenance tasks at regular intervals. For performance purposes, you should not run more than one cron job at the same time.

For example, you can setup some cron jobs for the apache user using the following command:

sudo crontab -u apache -e

Press i to enter the insert mode, and then populate the file with:

0,15,30,45 * * * * php /opt/mautic-2.9.2/app/console mautic:segments:update
3,18,33,48 * * * * php /opt/mautic-2.9.2/app/console mautic:campaigns:rebuild
6,21,36,51 * * * * php /opt/mautic-2.9.2/app/console mautic:campaigns:trigger
9,24,39,54 * * * * php /opt/mautic-2.9.2/app/console mautic:messages:send

After the modification, press the Esc button to quit the insert mode.

Save and quit:

:wq!

In the future, you can add more Mautic cron jobs in the same fashion.

Finally, Mautic is ready for use. You can try to create your first campaign from the Mautic dashboard now. Enjoy your new Mautic instance.