Running Mautic CRM Automation using PHP Docker with Buildah or Dockerfile

This post is only a notes on how to build a Dockerfile or PHP Docker Image for Mautic 5.x+ CRM Automation. The base image that’s used is docker.io/library/php:8.2-apache, which has no pdo, mysql, zip, intl, and imap. Mautic installation depends on those php extension, and the base php apache image doesn’t have it. To build it using buildah, you can start by reading how to use buildah here, in short, buildah is like a builder cli automation for container image. I sometimes like to use it because it can help me experiment much more freely than keep rebuilding the image using Dockerfile.

I assume everyone already has podman and buildah installed on their machine in order to run these commands. So we need to run several commands, sequentially, eg:

# pull the image 
buildah pull docker.io/library/php:8.2-apache
# create a new baseline container with buildah put it into a variable
container=$(buildah from php:8.2-apache)
# run several command to install the dependencies
buildah run $container -- apt-get update
buildah run $container -- apt-get install libicu-dev libc-client-dev libkrb5-dev libzip-dev -y
# clear up the apt folders
buildah run $container -- rm -rf /var/lib/apt/lists/* 
# enable rewrite on apache2
# @see https://forum.mautic.org/t/unable-to-resolve-binding-type-invalid-or-unsupported-http-request/16392/3
buildah run $container -- a2enmod rewrite
# install and enable php extensions
buildah run $container -- docker-php-ext-configure imap --with-kerberos --with-imap-ssl
buildah run $container -- docker-php-ext-install mysqli pdo pdo_mysql zip imap intl
# commit the image into new tag
buildah commit $container php:8.2-apache-mautic
# clean up the baseline builder
buildah rm $container

The 2nd way to run Mautic using Dockerfile is by copy pasting this Dockerfile, then build it, and use it for running using the same commands with podman

The Dockerfile :

# pull the image 
FROM docker.io/library/php:8.2-apache
# create a new baseline container with buildah put it into a variable
container=$(buildah from php:8.2-apache)
# run several command to install the dependencies
apt-get update
apt-get install libicu-dev libc-client-dev libkrb5-dev libzip-dev -y
# clear up the apt folders
rm -rf /var/lib/apt/lists/* 
# enable rewrite on apache2
# @see https://forum.mautic.org/t/unable-to-resolve-binding-type-invalid-or-unsupported-http-request/16392/3
a2enmod rewrite
# install and enable php extensions
docker-php-ext-configure imap --with-kerberos --with-imap-ssl
docker-php-ext-install mysqli pdo pdo_mysql zip imap intl

Building using podman

podman build . -t php:8.2-apache-mautic
# the rest commands to run are the same commands

Mautic also need several tweaks on the php.ini files to make it works, such as

; to not encounter any problems with high memory exhaustion
memory_limit=512M
; ........
[Assertion]
; Switch whether to compile assertions at all (to have no overhead at run-time)
; -1: Do not compile at all
; 0: Jump over assertion at run-time
; 1: Execute assertions
; Changing from or to a negative value is only possible in php.ini! (For turning assertions on and off at run-time, see assert.active, when zend.assertions = 1)
; Default Value: 1
; Development Value: 1
; Production Value: -1
; https://php.net/zend.assertions
zend.assertions = -1

Then after building the container image, you can run Mautic installation using the newly created image by

# if you need for development use this
podman unshare chmod 777 -R *
podman unshare chmod 777 .htaccess
podman unshare chmod 777 .

# only use this of you need to deploy to productions!
# set to www-data:www-data on linux
podman unshare chown 33:33 -R *
podman unshare chown 33:33 .
podman unshare chown 33:33 .htaccess

podman run --rm -it -p 8000:80 -v .:/var/www/html php:8.2-apache-mautic

This notes doesn’t include any mysql instalation, you need to have your own mysql server to connect and set up Mautic.
With it,you are ready to go with Mautic CRM installation by going to the :8000 (make sure the firewall allowing that port). As this only a container, if you need a webserver infront of it, well use nginx proxy manager or manual set up nginx instance on port 80.


Comments

Leave a Reply. I will come back and maybe we can have some conversation 🙂

This site uses Akismet to reduce spam. Learn how your comment data is processed.