Config.inc.php - relative paths (Docker local environment)

Hello Everyone!

I’m creating a development environment on windows 10 + wsl ubuntu + docker.
I use this repo GitHub - modxcms/docker-modx: Docker image for MODX (with some changes to match my needs), docker-compose up runs and everything is getting built as expected.

I have two scenarios:

  1. I have a new project to start - that’s sorted i can quickly begin to developing with the current state of my development environment.
  2. I have an existing project on the live site and I need to add some features and then publish it on the server. What i need to do now is import the live database into my docker database and download all MODx files into Docker. The problem is that on the live site, I have different paths than on the local machine (/home/user/public_html/ on live site and /var/www/html/ on the local machine) so i will need to manually change paths and i wondering if there is way to make these paths relative (config.inc.php - in core folder) during installation for example in some environmental variables or something.
    Ideal scenario i download files and DB, put in to correct places, clear the cache and its works on my local machine.

Please let me know any thoughts.
thank you!

Hi there, at least on 2X what I’ll do is to run the installer after copying the db and all the files to fix all paths, you can try that on 3X, also why you have different paths if you are using docker? I mean, the whole idea behind containers is that you keep the exact same configuration across enviroments

Hello,
Thank you for your response!
The reason why paths are different is that the live site is published on cPanel where the absolute directory is “/home/user/public_html” and on the local docker web server(apache2) is “/var/www/html/”.
Do you have anything in mind to make them the same (like on live site)?

thanks in advance

No problem and wellcome to the community!, you could create a simlink inside your Dockerfile or just totally update the routes of the base image, and then update the routes of the config.xlm inside your docker-entrypoint.sh to mimic what you have on your cPanel

Also would be a good idea to check at Gitify, this is the kind of tool I normally use to manage versions and deploy to different servers since you can cherry pick what you are moving, and many times you just want to move things like chunks, snippets and resources, but preserve user information

usually, you have to set these pathes only once in the config.inc.php and in the config.core.php files on each installation.
When exporting stuff from one installation to the other, you don’t include them.

1 Like

Yes, that is also an option just take everything expect config files.
thank you

Thank you for this response.
Correct me if I’m wrong, if I update my docker env variables to match the live site path “/home/user/public_html” I think MODx would not find these files unless I create these directories inside “/var/www/html”. However, the full path to the core would need to be “/var/www/html/home/user/public_html/core/” - not sure if that make sense or maybe i misunderstood you.

thank you!

You could use dirname instead

In our case we have the core folder outside of the public_html:

if (!defined('MODX_CORE_PATH')) {
    $modx_core_path = dirname(__FILE__, 3) .'/core/';
    define('MODX_CORE_PATH', $modx_core_path);
}
if (!defined('MODX_PROCESSORS_PATH')) {
    $modx_processors_path = dirname(__FILE__, 3) .'/core/model/modx/processors/';
    define('MODX_PROCESSORS_PATH', $modx_processors_path);
}
if (!defined('MODX_CONNECTORS_PATH')) {
    $modx_connectors_path = dirname(__FILE__, 3) .'/public_html/connectors/';
    $modx_connectors_url  = '/connectors/';
    define('MODX_CONNECTORS_PATH', $modx_connectors_path);
    define('MODX_CONNECTORS_URL', $modx_connectors_url);
}
if (!defined('MODX_MANAGER_PATH')) {
    $modx_manager_path = dirname(__FILE__, 3) .'/public_html/manager/';
    $modx_manager_url  = '/manager/';
    define('MODX_MANAGER_PATH', $modx_manager_path);
    define('MODX_MANAGER_URL', $modx_manager_url);
}
if (!defined('MODX_BASE_PATH')) {
    $modx_base_path = dirname(__FILE__, 3) .'/public_html/';
    $modx_base_url  = '/';
    define('MODX_BASE_PATH', $modx_base_path);
    define('MODX_BASE_URL', $modx_base_url);
}

Be aware that the config file is replaced in its entirety when running the setup. So any customisation to it, other than adding static values to the $config_options array, will be removed the next time you run an upgrade.

2 Likes

I think that @bruno17 sugestion would be the best, related to the docker changes, is a bit more complex than just changing the env vars, you’ll have to modify the base Dockerfile and then update the values inside your docker-entrypoint.sh betwen lines 106~112

Here is a explanation on how to update the document root inside the PHP docker image

1 Like

Oh this is great, i think i would go in this direction!
I have .env file with all information for yml config part, so the only thing to update will be Dockerfile.

thank you!

1 Like

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.