Mautic – for the Nth time… (Ubuntu 20.04.1 / nginx)

Mautic – for the Nth time… (Ubuntu 20.04.1 / nginx)

Always having difficulties with having Mautic run on our server, basically because we are trying to run Mautic with other web apps, using nginx.

This time I took some time to research carefully on php-fpm, and finally got Mautic run with other web apps.

Nginx’s mautic.conf was not properly configured (I just copied my other config hoping it work, which didn’t – but got certbot to issue SSL certificate all right), and this one helped me a lot:

https://gist.github.com/proffalken/ebfa9debc4eef929b0163d11a80af349

Basically I copied the whole config and pasted it, and added certbot’s SSL config.

However, installation process stopped with CSRF error.

The CSRF token is invalid. Please try to resubmit the form.

Nginx error log says:

2021/05/16 12:04:11 [error] 358173#358173: *1 FastCGI sent in stderr: “PHP message: PHP Warning: SessionHandler::read(): open(/var/lib/php/session/sess_00f42598e44d48be2e05b9fbcb266cd3, O_RDWR) failed: No such file or directory (2) in /var/www/html/mautic.3.2.4/vendor/symfony/http-foundation/Session/Storage/Handler/StrictSessionHandler.php on line 48PHP message: PHP Warning: SessionHandler::write(): open(/var/lib/php/session/sess_00f42598e44d48be2e05b9fbcb266cd3, O_RDWR) failed: No such file or directory (2) in /var/www/html/mautic.3.2.4/vendor/symfony/http-foundation/Session/Storage/Handler/StrictSessionHandler.php on line 64PHP message: PHP Warning: session_write_close(): Failed to write session data using user defined save handler. (session.save_path: /var/lib/php/session) in /var/www/html/mautic.3.2.4/vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php on line 268” while reading response header from upstream, client: 157.147.140.142, server: mydomain.com, request: “POST /installer/step/0 HTTP/1.1”, upstream: “fastcgi://127.0.0.1:9000”, host: “mydomain.com”, referrer: “https://mydomain.com/installer/step/0”

According to discussion here:

https://forum.mautic.org/t/invalid-csrf-token-at-install/2580/10

I configured php-fpm session save path to /var/lib/php/fpm-session, and changed the owner of the directory to nginx’s user, www-data:www-data.

$ ls -l /var/lib/php/
total 12
drwxr-xr-x 2 www-data www-data 4096 May 16 12:15 fpm-session
drwxr-xr-x 3 root root 4096 May 15 21:56 modules
drwx-wx-wt 2 root root 4096 Mar 27 2020 sessions

And restarted php-fpm:

sudo systemctl restart php7.4-fpm

Finally Mautic is up and running (again).