Deploying Mautic 2.9.2 on CentOS 7 with LAMP Stack

Mautic is a feature-rich and adaptable open-source software for marketing automation, developed using PHP. It enables digital marketers to conveniently handle numerous everyday marketing operations from a centralized interface. These operations include managing social media interactions, contact databases, email campaigns, forms, campaign workflows, and generating analytical reports.

This tutorial walks you through the process of installing the then-latest stable version of Mautic—version 2.9.2 hosted on a CentOS 7 server. Before proceeding with Mautic’s installation, it’s essential to have a fully configured and current LAMP or LEMP stack in place to serve as the foundational system environment. You will also find instructions for setting up an appropriate LAMP stack within this guide.

Prerequisites

  • A new CentOS 7 server instance with a minimum of 1GB RAM is suggested. For illustration, let’s assume the server has the IP address 203.0.113.1 and is linked to the domain example.com.
  • A user account with sudo privileges.

Step 1: Creating a Swap File (Optional)

Begin by launching your preferred SSH terminal and connecting to your server as a sudo user.

To enhance performance—especially during resource-intensive parallel campaign executions—you may optionally configure a swap file using these 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 space defined above is 2048MB, which is tuned for servers with 1GB of RAM. If your server’s RAM is different, you should adjust this size to match your hardware accordingly.

Step 2: System Update

For enhanced security, it is strongly recommended to bring your system up to date with the most recent stable updates. Use the following commands to perform the update:

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

After your server reboots, log in again using the same sudo-enabled account.

Step 3: Installing and Setting Up Apache

Next, proceed to install the most recent stable version of Apache. At the time this guide was written, Apache 2.4.6 was the latest version provided via the package manager:

In production setups, it’s advisable to disable the default Apache welcome page. This can be done by commenting out all lines in the /etc/httpd/conf.d/welcome.conf file:

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

Additionally, for added security, you should prevent Apache from listing directory contents in users’ browsers by adjusting the httpd.conf file:

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

To finalize the setup, start the Apache service and configure it to launch automatically with each system boot:

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

Step 4: Installing and Securing MariaDB 10.2.x

4.1 Installing MariaDB 10.2.x

To set up the most current stable version of MariaDB—version 10.2.8 at the time of this writing—use the following commands to install, start, and enable the MariaDB service:

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 Securing the MariaDB Installation

Before starting to use MariaDB, it’s critical to secure the installation. This is accomplished by executing the secure installation script below:

sudo /usr/bin/mysql_secure_installation

When running the script, follow these prompts. Be sure to substitute your own secure root password instead of the example shown:

  • Enter current password for root (enter for none): Simply press Enter
  • 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: Installing and Configuring PHP 7.0.x

5.1 Install PHP 7.0.x

As Mautic is not yet compatible with PHP 7.1.x, you’ll need to use the Webtatic repository to install the required PHP 7.0.x packages. Run the commands below to do so:

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

Once these PHP components are installed, it’s necessary to adjust a few default configuration settings. To avoid any issues, create a backup of the existing PHP configuration file before making changes:

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

5.2 Set the Timezone

Next, open the /etc/php.ini file using the vi text editor:

To ensure accurate timing data in your marketing campaigns, set the appropriate timezone by locating the following line:

;date.timezone =

Then replace it with:

date.timezone = America/Los_Angeles

Note: America/Los_Angeles is used here as an example. Choose a timezone that matches the geographical location of your own server. A complete list of supported PHP timezones can be found on the official PHP website.

5.3 Increase the PHP Memory Limit

To avoid memory exhaustion during resource-heavy tasks such as sending mass emails, increase PHP’s memory allocation. Still in the same /etc/php.ini file, locate the following line:

memory_limit = 128M

And change it to:

memory_limit = 256M

Once finished, save the changes and exit the editor:

Step 6: Installing Composer and Git

To handle dependencies and manage version control while setting up Mautic, it is essential to install both Composer and Git beforehand.

6.1 Installing Composer

Composer is a PHP-based tool designed to simplify dependency management. The following commands install Composer version 1.5.1, which was the most current stable version when this guide was created:

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: These instructions reflect the process at the time of writing. Since installation steps for Composer may change over time, it is advisable to consult the official Composer download page for the latest guidance.

6.2 Installing Git

Git is also required to successfully deploy Mautic. It can be installed quickly using this command:

Step 7: Installing Mautic

7.1 Create a MariaDB Database and User for Mautic

Before installing Mautic, a dedicated database and user must be created to store and manage Mautic’s data.

Access the MariaDB shell as the root user:

Once inside the MariaDB prompt, run the following commands to create a database named mautic, a user named mauticuser, and assign privileges. Replace placeholder values with your actual credentials when using this on your server:

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 the Mautic Installation Files

You can download the latest stable version of Mautic from GitHub. At the time of writing, this was version 2.9.2:

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

Extract the archive:

Navigate to the Mautic directory and use Git and Composer to manage dependencies:

cd mautic-2.9.2
git init
composer install

Move the installation to the /opt directory and create a symbolic link in your web server root:

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

Adjust ownership to allow Apache access:

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

7.3 Configure an Apache Virtual Host

Use the following snippet to set up an Apache virtual host. Update the values such as ServerAdmin, ServerName, and ServerAlias to match your actual domain settings:

cat <
ServerAdmin admin@example.com
DocumentRoot /var/www/html/mautic/
ServerName mautic.example.com
ServerAlias www.mautic.example.com

Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all

ErrorLog /var/log/httpd/mautic.example.com-error_log
CustomLog /var/log/httpd/mautic.example.com-access_log common

EOF

Restart Apache to activate the configuration:

sudo systemctl restart httpd.service

7.4 Adjust Firewall Rules

Enable HTTP traffic so that Mautic is accessible via a browser:

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

7.5 Complete Mautic Installation via Web Interface

Open a web browser and go to http://203.0.113.1. This brings up the Mautic setup wizard.

On the Environment Check page, click Next Step when you see the “Ready to install!” message.

On the Database Setup screen, enter the database information as follows:

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

Click Next Step to continue.

On the Administrative User screen, enter your admin details. For instance:

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

After submitting, proceed to the Email Configuration page, select your preferred mail transport method, and finish the setup.

Finally, access the login page and authenticate with your new admin credentials.

7.6 Post-Installation Cron Job Configuration

To keep Mautic functioning smoothly, set up scheduled cron jobs for routine maintenance. Be careful not to run multiple cron jobs simultaneously for performance reasons.

Edit the crontab for the Apache user:

Press i to enter insert mode and add the following entries:

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

Exit insert mode with Esc, then save and close the file:

You can continue adding more Mautic cron jobs similarly in the future.

Conclusion

You’ve successfully completed the full deployment of Mautic 2.9.2 on a CentOS 7 server. From setting up the web and database servers to installing required packages, securing your system, and configuring scheduled tasks, your new marketing automation platform is now ready to use. Start exploring the Mautic dashboard and build your first campaign. Enjoy a powerful, open-source tool to streamline your marketing efforts!

Source: vultr.com

Create a Free Account

Register now and get access to our Cloud Services.

Posts you might be interested in: