# Struggling to automate installation of Mautic

**URL:** <https://forum.mautic.org/t/struggling-to-automate-installation-of-mautic/32763>\
**Category:** Mautic 5 Install/Upgrade Support\
**Tags:** community, development\
**Created:** [July 15, 2024, 8:57am UTC](https://forum.mautic.org/t/struggling-to-automate-installation-of-mautic/32763 "2024-07-15T08:57:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![stefanpejcic](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/stefanpejcic/32/12322_2.png) [@stefanpejcic](https://forum.mautic.org/u/stefanpejcic)\
**Post date:** [July 15, 2024, 8:57am UTC](https://forum.mautic.org/t/struggling-to-automate-installation-of-mautic/32763/1 "2024-07-15T08:57:45Z")

</div>

**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:

- [How to install Mautic manually — Mautic Developer Documentation 3.0.0 documentation](https://devdocs.mautic.org/en/5.x/development-environment/setup.html)
- [Installation — Mautic Documentation 0.1 documentation](https://docs.mautic.org/en/5.x/getting_started/how_to_install_mautic.html)

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:

```auto
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.

* * *

```bash
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

```

```auto
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?

---

<div class="post-metadata">

**Author:** ![mzagmajster](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mzagmajster/32/687_2.png) [@mzagmajster](https://forum.mautic.org/u/mzagmajster)\
**Post date:** [July 15, 2024, 10:37am UTC](https://forum.mautic.org/t/struggling-to-automate-installation-of-mautic/32763/2 "2024-07-15T10:37:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![stefanpejcic](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/stefanpejcic/32/12322_2.png) [@stefanpejcic](https://forum.mautic.org/u/stefanpejcic)\
**Post date:** [July 15, 2024, 4:13pm UTC](https://forum.mautic.org/t/struggling-to-automate-installation-of-mautic/32763/3 "2024-07-15T16:13:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![itnavigate](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/itnavigate/32/12338_2.png) [@itnavigate](https://forum.mautic.org/u/itnavigate)\
**Post date:** [July 18, 2024, 7:24am UTC](https://forum.mautic.org/t/struggling-to-automate-installation-of-mautic/32763/4 "2024-07-18T07:24:17Z")

</div>

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

> **[GitHub - itnavigate/MauticSetup: Scripted setup of Mautic](https://github.com/itnavigate/MauticSetup)**
>
> Scripted setup of Mautic. Contribute to itnavigate/MauticSetup development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![stefanpejcic](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/stefanpejcic/32/12322_2.png) [@stefanpejcic](https://forum.mautic.org/u/stefanpejcic)\
**Post date:** [July 18, 2024, 7:41am UTC](https://forum.mautic.org/t/struggling-to-automate-installation-of-mautic/32763/5 "2024-07-18T07:41:55Z")

</div>

Hello, nice job!

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

As [mzagmajster](https://forum.mautic.org/u/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](https://github.com/itnavigate/MauticSetup/blob/4bf256dd974ca300eafcb2f060ea9d29787e3e64/install_mautic.sh#L63), because this way you need to edit it manually 😕 - better to allow user to specify version and, if not, then fallback to the latest [from the github api](https://api.github.com/repos/mautic/mautic/tags).

---

<div class="post-metadata">

**Author:** ![itnavigate](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/itnavigate/32/12338_2.png) [@itnavigate](https://forum.mautic.org/u/itnavigate)\
**Post date:** [July 18, 2024, 9:48am UTC](https://forum.mautic.org/t/struggling-to-automate-installation-of-mautic/32763/6 "2024-07-18T09:48:38Z")

</div>

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.
