So after a long time we decided to jump into Mautic 5 and wow what a change. The first thing that was the most challenging was getting the installation working with composer.
It should be noted there are mixed thoughts of installing with composer, at Mailertizer we are more inclined to install via zip files and have more control, but decided to jump into this.
In this tutorial, we’ll guide you through the process of installing Mautic 5.2.1 on a DigitalOcean Ubuntu 24.04 LTS server running Nginx, PHP8.1-FPM, Composer, Node.js, and npm. This guide is perfect for those who prefer to run Mautic with Nginx instead of Apache.
Prerequisites
- A DigitalOcean Ubuntu 24.04 LTS server.
- A domain name pointing to your server (for production use).
- Basic understanding of Linux commands and SSH.
- At least 2GB of RAM on the server (or make swap memory – composer will timeout and fail otherwise)
Step 1: Update the Server
Start by updating the server packages to ensure everything is up-to-date.
sudo apt update && sudo apt upgrade -y
Step 2: Install Required Dependencies
We need to install several packages, including PHP, Nginx, MariaDB, Composer, Node.js, and npm.
1. Install software properties and the necessary PPAs:
sudo apt install software-properties-common -y
sudo add-apt-repository ppa:ondrej/php -y
sudo apt update && sudo apt upgrade -y
2. Install PHP 8.1 and required extensions:
sudo apt install nginx mariadb-server php8.1 php8.1-{xml,mysql,imap,zip,intl,curl,gd,mbstring,bcmath} -y
Step 3: Configure PHP for Mautic
Next, we need to adjust PHP settings to optimize the performance for Mautic.
1. Edit the PHP configuration file:
sudo nano /etc/php/8.1/fpm/php.ini
2. Modify the following values:
allow_url_fopen = On
memory_limit = 512M
upload_max_filesize = 200M
post_max_size = 64M
max_execution_time = 300
file_uploads = On
session.gc_maxlifetime = 14400
opcache.memory_consumption=256
opcache.interned_strings_buffer=32
Save and exit (Ctrl + O, Enter, Ctrl + X).
3. Restart PHP-FPM to apply the changes:
sudo systemctl restart php8.1-fpm
Step 4: Install Node.js and npm
Mautic requires Node.js and npm to handle front-end assets.
1. Add the NodeSource repository and install Node.js:
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs
sudo apt install -y npm
Verify the installation:
node -v
npm -v
Step 5: Install Composer
Composer is required to manage Mautic’s PHP dependencies.
1. Install Composer:
sudo apt install composer -y
2. Verify the installation:
composer --version
Step 6: Install Mautic
Now that all dependencies are installed, let’s create a Mautic project using Composer.
1. Change to the web directory:
cd /var/www/html
2. Install Mautic 5.2.1 using Composer:
composer create-project mautic/recommended-project:5.2.1 mautic --no-interaction
3. Set the correct permissions for the Mautic files:
sudo chown -R www-data:www-data /var/www/html/mautic
sudo chmod -R 775 /var/www/html/mautic
Step 7: Configure Nginx
Let’s now configure Nginx to serve the Mautic application.
1. Create a new Nginx site configuration:
sudo nano /etc/nginx/conf.d/mautic.conf
2. Add the following configuration:
server {
listen 80;
listen [::]:80;
server_name your.mauticdomain.com;
root /var/www/mautic;
error_log /var/log/nginx/mautic.error;
access_log /var/log/nginx/mautic.access;
client_max_body_size 256M;
index index.php index.html index.htm index.nginx-debian.html;
location / {
try_files $uri /index.php$is_args$args;
}
location ~ /(mtc.js|.*\.js|mtracking.gif|.*\.gif|mtc) {
try_files $uri /index.php$is_args$args;
}
# redirect some entire folders
rewrite ^/(vendor|translations|build)/.* /index.php break;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
}
location ~* ^/index.php {
# try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_buffer_size 128k;
fastcgi_buffers 256 16k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}
# Deny everything else in /app folder except Assets folder in bundles
location ~ /app/bundles/.*/Assets/ {
allow all;
access_log off;
}
location ~ /app/ { deny all; }
# Deny everything else in /addons or /plugins folder except Assets folder in bundles
location ~ /(addons|plugins)/.*/Assets/ {
allow all;
access_log off;
}
# location ~ /(addons|plugins)/ { deny all; }
# Deny all php files in themes folder
location ~* ^/themes/(.*)\.php {
deny all;
}
# Don't log favicon
location = /favicon.ico {
log_not_found off;
access_log off;
}
# Don't log robots
location = /robots.txt {
access_log off;
log_not_found off;
}
# Deny yml, twig, markdown, init file access
location ~* /(.*)\.(?:markdown|md|twig|yaml|yml|ht|htaccess|ini)$ {
deny all;
access_log off;
log_not_found off;
}
# Allow access to certbot directory in order to obtain TLS certificate
location ~ /.well-known/acme-challenge {
allow all;
}
# Deny all attempts to access hidden files/folders such as .htaccess, .htpasswd, .DS_Store (Mac), etc...
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
# Deny all grunt, composer files
location ~* (Gruntfile|package|composer)\.(js|json)$ {
deny all;
access_log off;
log_not_found off;
}
# Deny access to any files with a .php extension in the uploads directory
location ~* /(?:uploads|files)/.*\.php$ {
deny all;
}
# A long browser cache lifetime can speed up repeat visits to your page
location ~* \.(jpg|jpeg|gif|png|webp|svg|woff|woff2|ttf|css|js|ico|xml)$ {
access_log off;
log_not_found off;
expires 360d;
}
}
3. Test Nginx configuration:
sudo nginx -t
4. Restart Nginx:
sudo systermctl restart nginx
Step 8: Set Up the Database
1. Run post installation security script
sudo mysql_secure_installation
2. Log into MySQL to create the database for Mautic
sudo mysql -u root (use -pPassword if you set a password)
3. Create a Mautic database and user:
CREATE DATABASE mautic DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
GRANT ALL ON mautic.* TO 'mauticuser'@'localhost' IDENTIFIED BY 'mautic_password';
FLUSH PRIVILEGES;
Step 9: Secure the Installation
1. Install Certbot:
sudo apt install certbot python3-certbot-nginx -y
2. Obtain the SSL certificate:
sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email you@example.com -d mautic.example.com
3. Follow the instructions to complete the setup
Step 10: Finalize Mautic Installation
Now, open your browser and navigate to your domain. You should see the Mautic installation wizard.
1. Enter the database details (mautic_user, your_password, mautic).
2. Complete the installation steps as per the wizard.