0

I'm trying to automate a site deployment/environment generation using profile installation, but I need to change the trusted_host_patterns key in the $settings variable of settings.php.

From what I've read in the API docs, the Settings class is read-only, which means I can't use the profile install hook to change it.

Has anyone experienced or tried to do this? What strategy did you use?

If I wanted to run a PHP script from the command line to do this, what would be the best way?

I'm new to Drupal, but any thoughts and comments are welcome!

  • change based on what? Do you know the domain in advance? This is not different than e.g. writing the database connection settings into settings.php during installation. Either you have a writable settings.php, then you do it during the installer, you do it while deploying the code or you set it dynamically in settings.php based on e.g. environment variables. That's now platform.sh works for example. – Berdir Jul 19 '17 at 0:19
  • @Berdir in this case, I have my codebase versioned with a settings.php file. My process involves cloning the repo, changing a few configs and then creating a new repo for the project. And yes, each time I deploy this, I'll know the domains in advance, that's why I need to change this at that time. – Joum Jul 19 '17 at 8:09
  • Then I don't understand the problem. just write whatever you want into the settings.php? Note that this is something that is environment specific, you might have staging and local development domains that need to work as well. Either put them all in there, or you move this into a settings.local.php that is not in Git where you can also put database connection and other settings that should not be in git – Berdir Jul 19 '17 at 11:46
  • @Berdir the settings.php is versioned, but it is supposed to change when I create a new version of the repo. So I would need a way to programmatically change the settings in the file, and was wondering what was the best way to do that. I thought about what you said regarding environment vars and it's a good solution. Thanks for the advice! – Joum Jul 19 '17 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.