{"record":{"id":"61d9dd4780131e38","repo":"Dolibarr/dolibarr","slug":"value-for-parameter-dolibarr-main-url-root-is-not-defined-in","errorCode":null,"errorMessage":"Value for parameter 'dolibarr_main_url_root' is not defined in your 'htdocs\\conf\\conf.php' file. You must add this parameter with your full Dolibarr root Url (Example: http://myvirtualdomain/ or http://mydomain/mydolibarrurl/)","messagePattern":"Value for parameter 'dolibarr_main_url_root' is not defined in your 'htdocs\\\\conf\\\\conf\\.php' file\\. You must add this parameter with your full Dolibarr root Url \\(Example: http://myvirtualdomain/ or http://mydomain/mydolibarrurl/\\)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"htdocs/filefunc.inc.php","lineNumber":365,"sourceCode":"\t\t}\n\t\tif ($csrfattack) {\n\t\t\t//print 'NOCSRFCHECK='.defined('NOCSRFCHECK').' REQUEST_METHOD='.$_SERVER['REQUEST_METHOD'].' HTTP_HOST='.$_SERVER['HTTP_HOST'].' HTTP_REFERER='.$_SERVER['HTTP_REFERER'];\n\t\t\t// Note: We can't use dol_escape_htmltag here to escape output because lib functions.lib.ph is not yet loaded.\n\t\t\tdol_syslog(\"--- Access to \".(empty($_SERVER[\"REQUEST_METHOD\"]) ? '' : $_SERVER[\"REQUEST_METHOD\"].' ').$_SERVER[\"PHP_SELF\"].\" refused by CSRF protection (Bad referrer).\", LOG_WARNING);\n\t\t\tprint \"Access refused by CSRF protection in main.inc.php. Referrer of form (\".htmlentities(empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'], ENT_COMPAT, 'UTF-8').\") is outside the server that serve this page (with method = \".htmlentities($_SERVER['REQUEST_METHOD'], ENT_COMPAT, 'UTF-8').\").\\n\";\n\t\t\tprint \"If you access your server behind a proxy using url rewriting, you might check that all HTTP headers are propagated (or add the line \\$dolibarr_nocsrfcheck=1 into your conf.php file to remove this security check).\\n\";\n\t\t\tdie;\n\t\t}\n\t}\n\t// Another test is done later on token if option MAIN_SECURITY_CSRF_WITH_TOKEN is on.\n}\nif (empty($dolibarr_main_db_host) && !defined('NOREQUIREDB')) {\n\tprint '<div class=\"center\">Dolibarr setup is not yet complete.<br><br>'.\"\\n\";\n\tprint '<a href=\"install/index.php\">Click here to finish Dolibarr install process</a> ...</div>'.\"\\n\";\n\tdie;\n}\nif (empty($dolibarr_main_url_root) && !defined('NOREQUIREVIRTUALURL')) {\n\tprint 'Value for parameter \\'dolibarr_main_url_root\\' is not defined in your \\'htdocs\\conf\\conf.php\\' file.<br>'.\"\\n\";\n\tprint 'You must add this parameter with your full Dolibarr root Url (Example: http://myvirtualdomain/ or http://mydomain/mydolibarrurl/)'.\"\\n\";\n\tdie;\n}\n\nif (empty($dolibarr_main_url_root_alt)) {\n\t$dolibarr_main_url_root_alt = '/custom';\n}\nif (empty($dolibarr_main_document_root_alt)) {\n\t$dolibarr_main_document_root_alt = $dolibarr_main_document_root.'/custom';\n}\n\nif (empty($dolibarr_main_data_root)) {\n\t// If directory not defined, we use the default hardcoded value\n\t$dolibarr_main_data_root = str_replace(\"/htdocs\", \"\", $dolibarr_main_document_root);\n\t$dolibarr_main_data_root .= \"/documents\";\n}\n\n// Define some constants","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/Dolibarr/dolibarr/blob/598aa4bdada683d17ca04b1842548821ff0eb6c6/htdocs/filefunc.inc.php#L347-L383","documentation":"filefunc.inc.php requires dolibarr_main_url_root (the full public root URL of the Dolibarr install) to be set in conf.php unless NOREQUIREVIRTUALURL is defined. When it is empty, Dolibarr prints this instruction with an example URL and dies. Unlike older versions, this parameter is mandatory because it is used to build absolute URLs.","triggerScenarios":"Any page load with a conf.php that omits or leaves empty $dolibarr_main_url_root, on an entry point that does not define NOREQUIREVIRTUALURL (command-line scripts normally define it, web pages do not).","commonSituations":"Hand-copied or partially migrated conf.php missing the URL section; fresh install aborted before the URL step; automated provisioning templates that only set DB parameters; hosts migrated to a new domain with the parameter left blank.","solutions":["Add the full root URL to htdocs/conf/conf.php, e.g. $dolibarr_main_url_root='http://mydomain/'; or with subdirectory 'http://mydomain/mydolibarrurl/'.","Use the exact externally reachable scheme/host (https, correct port, no trailing slash) so generated links and CSRF checks work.","For CLI scripts that legitimately have no virtual URL, define('NOREQUIREVIRTUALURL') before including main.inc.php.","After fixing, restart/refresh and verify generated emails/links contain the correct base URL.","Complete /install if this conf.php came from an interrupted setup."],"exampleFix":"// before (htdocs/conf/conf.php)\n$dolibarr_main_url_root = '';\n// after\n$dolibarr_main_url_root = 'https://doli.example.com';   // or 'https://doli.example.com/dolibarr'","handlingStrategy":"validation","validationCode":"// fail fast in provisioning when the public URL is missing\n$conf = file_get_contents('/var/www/dolibarr/htdocs/conf/conf.php');\nif (!preg_match(\"/\\$dolibarr_main_url_root\\s*=\\s*'https?:\\/\\/[^']+'/\", $conf)) {\n    throw new RuntimeException('dolibarr_main_url_root must be set to the full public root URL');\n}","typeGuard":"function urlRootIsValid(?string $url): bool {\n    return is_string($url) && $url !== '' && filter_var($url, FILTER_VALIDATE_URL) !== false\n        && str_starts_with($url, 'http');\n}","tryCatchPattern":null,"preventionTips":["Always set $dolibarr_main_url_root to the scheme+host(+path) users actually browse, no trailing slash.","For CLI/cron scripts without a URL context, define('NOREQUIREVIRTUALURL') before including main.inc.php.","Re-check this parameter after any domain/protocol migration (http->https, new vhost).","Keep conf.php in config management so the key is never omitted by templates.","Remember the value feeds absolute URLs in emails/links, so precision matters."],"tags":["configuration","url","install"],"backgroundTag":"missing-config-value","analyzedSha":"598aa4bdada683d17ca04b1842548821ff0eb6c6","analyzedAt":"2026-09-14T11:12:15.309Z","contentChangedAt":"2026-09-14T11:12:15.309Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}