Hello, I’m a module developer for Dolibarr with about 6 years of experience, and I have 3 modules on Dolistore (Purchases, Stocktransfers, TOTp 2FA) and two themes.
The issue I’d like to discuss is that in recent weeks, I’ve been contacted by a couple of customers (people who purchased my modules) who were having trouble getting them to work and were seeing the “Include of main fails” message in the browser on a blank screen. If you’re a module developer, you probably know what this means: the module script couldn’t locate the main.inc.php
file from the Dolibarr core.
With one of these customers facing this problem, the root cause was that their Dolibarr installation had been done using an automated script by their hosting provider (Bitnami on AWS), and as a result, the Dolibarr core was installed in an ABSOLUTE path DIFFERENT from that of the /custom
subdirectory. Therefore, the recommended “reverse search” system doesn’t work:
// Try main.inc.php using relative path
if (!$res && file_exists("../main.inc.php")) $res = @include "../main.inc.php";
if (!$res && file_exists("../../main.inc.php")) $res = @include "../../main.inc.php";
if (!$res && file_exists("../../../main.inc.php")) $res = @include "../../../main.inc.php";
if (!$res) die("Include of main fails");
So, for that customer, I simply added an @include($absolute_path)
with the absolute path of their installation:
/opt/bitnami/dolibarr/htdocs/main.inc.php
I realized that this path wasn’t dependent on their username or domain name, so it might be useful for other Dolibarr users using Bitnami.
That’s when I thought the IDEAL solution would be to develop a SINGLE PHP script to be included at the root of all my modules. This script would search for the main.inc.php
file in the usual locations but also in locations like the one used by Bitnami.
But that’s not all! The script I’ve created, instead of displaying a static message like “Include of main fails,” presents the user with a form in the browser, explaining the issue better and asking them to enter the absolute path of the main.inc.php
file in a text box. Then, my script checks if it can actually load it, and if successful, it saves that path in a plain text file called “load_main_inc_php,” stored in the root of /custom
. This way, it becomes the first thing to be read the next time the module is called and tries to load the main.inc.php
file, eliminating the need for repeated recursive searches.
I’ve published this script on Github along with the explanations I’m giving here, so that together, we can make this script more powerful and “smart.”
https://github.com/caos30/dolibarr_load_main_inc_php
Furthermore, I suggest to the Dolibarr core team that they consider incorporating this into the “module builder” by default.
What do you think? Am I doing something reckless or am I on the right track? Do you have any suggestions?
Best regards,
Sergi