0%

Loading Experience...

Complete Guide: Self-Hosted Mautic Marketing Automation on Ubuntu

Master Mautic installation on Ubuntu 24 with this comprehensive guide. Learn to set up a powerful open-source marketing automation platform with NGINX, PHP 8.0, and MySQL.

Complete Guide: Self-Hosted Mautic Marketing Automation on Ubuntu
Read Time7 min read
Written on
By 0xAquaWolf
Last updated

Complete Guide: Self-Hosted Mautic Marketing Automation on Ubuntu#

Mautic is a powerful open-source marketing automation platform that gives you complete control over your email marketing, lead generation, and customer journeys. This comprehensive guide walks you through installing Mautic on Ubuntu 24, creating a professional marketing automation setup that rivals commercial solutions.

Why Self-Host Mautic?#

Before diving into the installation, let's understand why self-hosting Mautic is a game-changer for marketers and developers:

Complete Data Ownership: Your contact data, email templates, and analytics stay on your server - no third-party data sharing concerns.

Cost-Effective: No monthly subscription fees or contact limits. Pay only for your server hosting.

Custom Integration Freedom: Full API access allows deep integration with your existing tools and custom workflows.

Advanced Features: Email marketing, lead scoring, campaign management, landing pages, forms, and detailed analytics - all included.

Professional Control: Customize every aspect of your marketing automation without vendor limitations.

Prerequisites#

Before starting this installation, ensure you have:

  • Ubuntu 24 server (or Ubuntu 22.04 LTS) with at least 2GB RAM and 2 CPU cores
  • Root or sudo access for system administration
  • Domain name pointed to your server's IP address (recommended for SSL)
  • Basic Linux command line knowledge for troubleshooting
  • 15-30 minutes for complete installation

Server Requirements#

For optimal Mautic performance, your server should meet these specifications:

Minimum Requirements:

  • 2GB RAM, 2 CPU cores
  • 20GB SSD storage
  • Ubuntu 22.04 LTS or 24.04 LTS

Recommended for Production:

  • 4GB+ RAM, 4+ CPU cores
  • 50GB+ SSD storage
  • Dedicated server or VPS
  • SSL certificate (Let's Encrypt recommended)

Step 1: System Preparation and Updates#

First, let's prepare your Ubuntu server by updating all packages and securing the system:

# Update package lists and upgrade existing packages
sudo apt update && sudo apt upgrade -y
 
# Install essential system utilities
sudo apt install curl wget unzip software-properties-common apt-transport-https -y
 
# Configure system timezone (important for email scheduling)
sudo timedatectl set-timezone UTC

This ensures your server has the latest security patches and necessary tools for Mautic installation.

Step 2: Installing NGINX Web Server#

NGINX will serve as your web server, handling HTTP requests and providing excellent performance for Mautic:

# Install NGINX
sudo apt install nginx -y
 
# Start and enable NGINX service
sudo systemctl start nginx
sudo systemctl enable nginx
 
# Verify NGINX is running
sudo systemctl status nginx

NGINX is now installed and running on your server. You can test it by visiting your server's IP address in a web browser - you should see the NGINX welcome page.

Step 3: Installing PHP 8.0 and Required Extensions#

Mautic requires PHP with several extensions for optimal performance. We'll install PHP 8.0 with all necessary modules:

# Add PHP repository (for latest PHP versions)
sudo add-apt-repository ppa:ondrej/php -y
sudo apt update
 
# Install PHP 8.0 with all required extensions for Mautic
sudo apt install php8.0 php8.0-fpm php8.0-mysql php8.0-xml php8.0-curl php8.0-gd php8.0-intl php8.0-mbstring php8.0-zip php8.0-bcmath php8.0-imap php8.0-ldap -y
 
# Set PHP 8.0 as the default system version
sudo update-alternatives --set php /usr/bin/php8.0
sudo update-alternatives --set phar /usr/bin/phar8.0
sudo update-alternatives --set phar.phar /usr/bin/phar.phar8.0
 
# Start and enable PHP-FPM service
sudo systemctl start php8.0-fpm
sudo systemctl enable php8.0-fpm
 
# Verify PHP installation
php -v

PHP Extensions Explained:

  • php8.0-fpm: FastCGI Process Manager for NGINX integration
  • php8.0-mysql: Database connectivity
  • php8.0-xml: XML processing for imports/exports
  • php8.0-curl: HTTP requests for webhooks and APIs
  • php8.0-gd: Image processing for email templates
  • php8.0-intl: Internationalization support
  • php8.0-mbstring: Multi-byte string handling
  • php8.0-zip: Archive handling for file uploads
  • php8.0-bcmath: Mathematical functions
  • php8.0-imap: Email functionality
  • php8.0-ldap: Directory service integration

Step 4: Installing and Configuring MySQL Database#

MySQL will store all your Mautic data - contacts, campaigns, emails, and analytics. Let's install and secure it:

# Install MySQL server
sudo apt install mysql-server -y
 
# Start and enable MySQL service
sudo systemctl start mysql
sudo systemctl enable mysql
 
# Run MySQL security installation
sudo mysql_secure_installation

During the mysql_secure_installation process, follow these recommendations:

  • Set up the Validate Password Component (recommended)
  • Choose a password strength level (2 is good for production)
  • Set a strong root password
  • Remove anonymous users
  • Disallow root login remotely
  • Remove test database
  • Reload privileges when prompted

Step 5: Creating Mautic Database and User#

Now let's create a dedicated database and user for Mautic with proper security:

# Log into MySQL as root
sudo mysql
 
# Or if you set a root password:
mysql -u root -p

Once in the MySQL prompt, execute these commands:

-- Create the main Mautic database
CREATE DATABASE mautic CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
 
-- Create a dedicated database user with strong password
CREATE USER 'mauticuser'@'localhost' IDENTIFIED BY 'YourSecurePassword123!';
 
-- Grant all privileges on the Mautic database
GRANT ALL PRIVILEGES ON mautic.* TO 'mauticuser'@'localhost';
 
-- Apply changes and exit
FLUSH PRIVILEGES;
EXIT;

Security Notes:

  • Replace YourSecurePassword123! with a strong, unique password
  • Use utf8mb4 character set for full Unicode support (emoji, international characters)
  • The dedicated user limits database access to Mautic only

Step 6: Installing Composer Package Manager#

sudo apt install php-cli unzip
curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php
HASH=`curl -sS https://composer.github.io/installer.sig`
php -r "if (hash_file('SHA384', '/tmp/composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
sudo php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer

Step 7: Download and Set Up Mautic#

cd /var/www
sudo mkdir example.com
cd example.com
sudo wget https://github.com/mautic/mautic/releases/download/5.1.0/5.1.0.zip
sudo unzip 5.1.0.zip
sudo rm 5.1.0.zip

Set proper permissions:

sudo chown -R www-data:www-data /var/www/example.com
sudo find /var/www/example.com -type d -exec chmod 755 {} \;
sudo find /var/www/example.com -type f -exec chmod 644 {} \;

Step 8: Configure NGINX#

Create a new NGINX server block:

sudo vim /etc/nginx/sites-available/example.com

Paste the following configuration:

server {
    listen 443 ssl http2;
    server_name mautic.example.com;
    root /var/www/example.com;
    index index.php;
 
    # SSL configuration (Certbot will modify these lines)
    ssl_certificate /etc/letsencrypt/live/mautic.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/mautic.example.com/privkey.pem;
 
    # Add security headers
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";
 
    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }
 
    location ~ ^/index.php(/|$) {
        fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
        fastcgi_index index.php;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_intercept_errors on;
    }
 
    location ~* ^/app/bundles/ {
        root /var/www/example.com;
        try_files $uri =404;
    }
 
    location ~* \.(woff2|woff|ttf|otf|eot|svg)$ {
        root /var/www/example.com;
        add_header Access-Control-Allow-Origin "*";
        expires max;
        access_log off;
        try_files $uri =404;
    }
 
    # Deny access to .htaccess files
    location ~ /\.ht {
        deny all;
    }
 
    # Mautic specific rules
    location ~* ^/app/bundles/ {
        deny all;
        return 403;
    }
 
    location ~* ^/app/cache/ {
        deny all;
        return 403;
    }
 
    location ~* ^/app/logs/ {
        deny all;
        return 403;
    }
 
    # For real-time updates
    location /index.php/notifications {
        try_files $uri /index.php$is_args$args;
    }
 
    # Caching static assets
    location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
        expires 365d;
        add_header Cache-Control "public, no-transform";
    }
}
 
server {
    listen 80;
    server_name mautic.example.com;
    return 301 https://$server_name$request_uri;
}

Enable the new configuration:

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

Step 9: Install SSL Certificate#

sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d mautic.example.com

Follow the prompts to obtain and install the SSL certificate.

Step 10: Final Setup#

  1. Open your browser and navigate to https://mautic.example.com.
  2. Follow the on-screen instructions to complete the Mautic installation.
  3. Use the database credentials you set up in Step 5.

Troubleshooting#

If you encounter any issues, check the NGINX error logs:

sudo tail -f /var/log/nginx/error.log

Ensure all file permissions are correct:

sudo chown -R www-data:www-data /var/www/example.com
sudo find /var/www/example.com -type d -exec chmod 755 {} \;
sudo find /var/www/example.com -type f -exec chmod 644 {} \;

Remember to replace mautic.example.com with your actual domain name throughout this guide.

🎉 Installation Complete! What's Next?#

Congratulations! You now have a fully functional, self-hosted Mautic installation. Here are the essential next steps to maximize your marketing automation platform:

Immediate Next Steps#

  1. Complete Web Setup: Navigate to your domain and finish the Mautic web installer
  2. Configure Email Settings: Set up your sending domain and email service
  3. Create Your First Campaign: Start building automated email sequences
  4. Install Tracking Code: Add Mautic's tracking script to your website
  5. Import Contacts: Migrate your existing contact lists

Performance Optimization#

# Set up regular database maintenance
crontab -e
 
# Add these lines for automated maintenance:
# 0 2 * * * /usr/bin/php /var/www/your-domain.com/app/console mautic:segments:update
# 0 3 * * * /usr/bin/php /var/www/your-domain.com/app/console mautic:campaigns:update
# 0 4 * * * /usr/bin/php /var/www/your-domain.com/app/console mautic:email:send

Security Hardening#

  • Regular Updates: Keep PHP, MySQL, and Mautic updated
  • Backup Strategy: Implement automated database and file backups
  • Monitor Logs: Regularly check access and error logs
  • SSL Certificate: Renew your Let's Encrypt certificate automatically

Scaling Considerations#

As your contact list grows, consider:

  • Upgrading Server Resources: More RAM and CPU for better performance
  • CDN Integration: Faster content delivery globally
  • Load Balancing: Multiple servers for high-availability setups
  • Email Service Provider: Professional email delivery services

Why This Setup Works#

This self-hosted Mautic installation gives you:

  • Complete data control and privacy compliance
  • Unlimited contacts without additional costs
  • Full customization capabilities
  • API access for custom integrations
  • Professional marketing automation comparable to enterprise solutions

You've now built a powerful marketing automation platform that would cost thousands of dollars monthly with commercial providers, all hosted on your own terms!

Additional Resources#