Skip to content

setup/cli-install.php breaks Windows paths by prepending / #16890

@biz87

Description

@biz87

Description

setup/cli-install.php corrupts Windows file paths during the path normalization step, making CLI installation impossible on Windows.

Steps to Reproduce

  1. Clone MODX 3.x on Windows (e.g. via Laragon)
  2. Run php setup/cli-install.php with all required parameters
  3. Installation fails with pre-install check errors:
Pre-Install Tests Failed! Errors:
context_web_exists: Failed! - context_mgr_exists: Failed! - context_connectors_exists: Failed! -
context_web_writable: Failed! - context_mgr_writable: Failed! - context_connectors_writable: Failed! -

Root Cause

The path normalization code unconditionally prepends / to all path values:

if (strpos($key, '_path') !== false || strpos($key, '_url') !== false) {
    $data[$key] = preg_replace('#/+#', '/', ('/' . trim($data[$key], '/') . '/'));
}

On Linux this works fine:
/var/www/site/core/ → trim → var/www/site/core → prepend //var/www/site/core/

On Windows it breaks:
D:/laragon/www/site/core/ → trim → D:/laragon/www/site/core → prepend //D:/laragon/www/site/core/

The resulting config.xml contains invalid paths like:

<core_path>/D:\laragon\www\site/core/</core_path>

Suggested Fix

Skip the / prepend when the path starts with a Windows drive letter:

if (strpos($key, '_path') !== false || strpos($key, '_url') !== false) {
    $value = trim($data[$key], '/');
    // Don't prepend / for Windows absolute paths (e.g. D:/...)
    if (!preg_match('#^[A-Za-z]:#', $value)) {
        $value = '/' . $value;
    }
    $data[$key] = preg_replace('#/+#', '/', $value . '/');
}

Workaround

Generate setup/config.xml manually with correct Windows paths, then run:

php setup/index.php --installmode=new --core_path=D:/path/to/site/core/ --config=D:/path/to/site/setup/config.xml

Environment

  • MODX 3.x (branch 3.x, commit dd8b86c)
  • Windows 10/11
  • PHP 8.3
  • Laragon local development environment

Metadata

Metadata

Assignees

Labels

bugThe issue in the code or project, which should be addressed.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions