Getting up and running with Mautic on your Mac with Docker
When I started to try out the Mautic community version on my local instance, it was a bit of a hassle and not very straightforward, for I was new to Mautic, and I am not very familiar with Docker as well.
Some of the issues I stumbled into include -
- PHP docker image is very bare bone. Doesn’t come loaded with even the most common of drivers like MySQL. Causing the installation page to not show “MYSQL” as an option. (Mautic issue link)
- A regression in Mautic currently doesn’t show the right message on screen for any database connectivity problems during installation. (Mautic issue link). This only made the earlier #1 issue not very obvious
- Connecting from the PHP container to MySQL was not getting through either via 127.0.0.1 or via localhost (Mautic issue link)
- Mautic doesn’t insist on enabling mod_rewrite during installation. But fails on first login.
- Mautic requires Composer 1 and not the latest version 2
- Enabling PHP extension like sendmail on docker containers is not straightforward and requires use of docker-php-ext-install script
All of these meant getting Mautic with PHP+Apache+MySQL up and running on Docker wasn’t as simple of a “Hello World” process as I thought it would be.
Sharing below the dockerfile and dockercompose.yml that worked for me addressing the above challenges, along with step-by-step instructions for using them.
Steps:
- Install Docker for Mac - https://docs.docker.com/docker-for-mac/install/
- Download Mautic community edition from https://www.mautic.org/download
- In the root of Mautic codebase, copy the docker-compose.yml - https://gist.github.com/saitanay/2a5617cd7ff875780e1b503d9a0bae2f
(this can be in a separate folder as well, you just need to update the addresses in lines 16 and 30 accordingly if you are using relative paths) - Also in the same location copy the Dockerfile - https://gist.github.com/saitanay/72363544254f12a4ace97d17c3a05f32
This needs to be in the same folder as your docker-compose.yml - else update the path in thebuild: .
command in your docker-compose.yml file. - As you might have seen the Dockerfile expects a php.ini file in the same folder. The contents of that php.ini can be as below
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE
display_errors = On
display_startup_errors = On
log_errors = On
error_log = /dev/stderr
sendmail_path = "env -i /usr/sbin/sendmail -t -i"
- Once both files are in place - you can run the below command from root of your mautic folder (where you also have the docker-compose.yml file)
docker-compose up --build - Furthermore, you should be able to access Mautic from localhost/ on your browser.
- Your DB connection details would look like the below, and you should be able to proceed with installation of Mautic by pointing your browser to localhost.
Note the use of host.docker.internal instead of localhost or 127.0.0.1 in DB connection
'db_driver' => 'pdo_mysql',
'db_host' => 'host.docker.internal',
'db_table_prefix' => null,
'db_port' => '3306',
'db_name' => 'mauticcomm',
'db_user' => 'root',
'db_password' => 'example',