Struggling to automate installation of Mautic

Your software
My Mautic version is: 5.1.0
My PHP version is: 8.2
My Database type and version is: mysql 8.0.37

Your problem
My problem is: I can not automate the installation of mautic!

Im working on OpenPanel and we received requests by a few of our users to create a Mautic Manager to allow them to install and manage Mautic installations.

So I browsed Mautic documentation and based on:

I manage to download mautic, extract, create db and user, edit the local.php file and run the install. Problem is in these 2 commands:

root@stefi:/home/stefan/stefi.openpanel.site# apt-get install git npm -y ; cd /home/stefan/stefi.openpanel.site && composer install --ignore-platform-req=ext-imap 
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
git is already the newest version (1:2.43.0-1ubuntu7.1).
npm is already the newest version (9.2.0~ds1-2).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Nothing to install, update or remove
Package sensio/framework-extra-bundle is abandoned, you should avoid using it. Use Symfony instead.
Generating autoload files
composer/package-versions-deprecated: Generating version class...
composer/package-versions-deprecated: ...done generating version class
150 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
phpstan/extension-installer: Extensions installed
> php -r "if(file_exists('./.git')&&file_exists('./build/hooks/pre-commit'.(PHP_OS=='WINNT'?'.win':''))){copy('./build/hooks/pre-commit'.(PHP_OS=='WINNT'?'.win':''),'./.git/hooks/pre-commit');} if(file_exists('./.git')&&file_exists('./build/hooks/post-checkout')){copy('./build/hooks/post-checkout','./.git/hooks/post-checkout');}"
> php -r "if(file_exists('./.git/hooks/pre-commit')&&(PHP_OS!='WINNT')){chmod('./.git/hooks/pre-commit',0755);} if(file_exists('./.git/hooks/post-checkout')&&(PHP_OS!='WINNT')){chmod('./.git/hooks/post-checkout',0755);}"
> npm ci --prefer-offline --no-audit
npm WARN deprecated @npmcli/move-file@1.1.2: This functionality has been moved to @npmcli/fs

> mautic@0.0.0 postinstall
> node_modules/modernizr/bin/modernizr -c modernizr-config.json -d node_modules/modernizr/modernizr-mautic-dist.js & npm run build


> mautic@0.0.0 build
> webpack --mode production  --config webpack.config.js

Modernizr build saved to node_modules/modernizr/modernizr-mautic-dist.js

^C

This command just gets stuck and I need to manually exit it to proceed.


root@stefi:/home/stefan/stefi.openpanel.site# php bin/console mautic:install -f https://stefi.openpanel.site

    
    
    
    
    Mautic Install
==============

Parsing options and arguments...

    0 - Checking installation requirements...
Missing optional settings:
  - [0] Install and enable the <strong>imap</strong> extension to support monitored email.
Ready to Install!
1 - Creating database...
Errors in database configuration/installation:
  [error] An error occured while attempting to connect to the database: Failed to start the session because headers have already been sent by "/home/stefan/stefi.openpanel.site/app/config/local.php" at line 1.
Install canceled
root@stefi:/home/stefan/stefi.openpanel.site# php bin/console mautic:install -f https://stefi.openpanel.site
Mautic Install
==============

Parsing options and arguments...
0 - Checking installation requirements...
Missing optional settings:
  - [0] Install and enable the <strong>imap</strong> extension to support monitored email.
Ready to Install!
1 - Creating database...
1.1 - Creating schema...
1.2 - Loading fixtures...
2 - Creating admin user...
3 - Final steps...

================
Install complete

this install command when run 1st time fails, but then run again and is successful.


So to summarize, problem is that 1st command needs to be exited manually, and 2nd command needs to be run 2x.

Im not that familiar with Mautic to properly troubleshoot this, and I want to avoid workarounds to repeat commands…

Does anyone have a working script to install and setup Mautic? Can you please share what works for you?

Hi,

I am interested in this challenge. A while ago I played around with the ansible script for this, but did not finish it, due to not having the time and the funds.

The route that is really interesting to me and I am playing around with it, these days is installation of Mautic via docker.

After a quick glance at your post, there are two things with your approach that could be improved:

  • the first is that you could eliminate the build step and on installation just copy already built assets (this is also done by official mautic docker image)
  • the second is that you appear to have some kind of output produce by installation script and esentially this is the reason way installation fails.

Anyway I am happy to help you automate installation of Mautic in scope of my services, so reach out if you are interested.

Have a great day.

Best, M.

thanks for the tip!

I switched to prebuilded .zip files from github releases, and now the build step is skipped.

However there still is an issue that the install command needs to be run 2x.

I’ll try to reproduce on a few other panels/php versions and then open issue on github.

I have scripted the install of my Mautic on Debian 12 using nginx and https.

This is intended to be run on a pristine install of Debian, and has very little error checking in it. It downloads and builds the GitHub repo, or installs the pre-prepared zip file.

This was written for my convenience, and only has rudimentary error checking built in, but is solid enough for me at the moment.

Please check out my repository on GitHub

1 Like

Hello, nice job!

If only I saw this days before, it would save me a day! :smiley:

As mzagmajster suggested, maybe wget already built zip files in order to avoid npm?
Its not used by Mautic after the build, so it can be removed.

I would also suggest not putting the version here, because this way you need to edit it manually :confused: - better to allow user to specify version and, if not, then fallback to the latest from the github api.

Thanks for the feedback. I’ll make that change!

I initially was using the prebuilt zip, but then I thought I needed the latest from GitHub, so modified the script to let me choose.

What I haven’t figured out is how to wget the 95_mautic-510.zip from the mautic website.