I am trying to set $cookie_domain in my settings.php within Drupal 8.

In Drupal 7, I add this in settings.php to set it up, but I am not sure how to do it in Drupal 8:

$cookie_domain = ".domain.com";

Thanks a lot


This is a container parameter now.

Put this in services.yml or another service definition YAML file:

    cookie_domain: '.domain.com'

Since it is in a yaml file, it can't easily be dynamic, one option you have is having multiple yml files, and you dynamically add the one for the right environment, or you have a services.local.yml, just like settings.local.php that you have on each environment and not in git.

  • 2
    You are right. I'm just adding that any additional YAML file can be loaded in the settings or local.settings files like this : $settings['container_yamls'][] = __DIR__ . '/ENV.services.yml';
    – Renrhaf
    Apr 11 '17 at 5:15
  • 2
    Is it possible to set IP Address, Instead of domain?
    – AshwinP
    Dec 11 '17 at 14:34
  • 3
    @AshwinP There should be hostname what the browsers will see, so if your users access site by IP address it will work like this. But usually users use domain name. :-)
    – Bobík
    Jan 8 '19 at 17:51

Another option for multiple environments rather than keeping multiple files is to use environment variables.

Create an environment variable the way you normally would, if you're using Docker that would usually be by loading an .env file with contents such as:


Then use that environment variable in your services.yml file (or other YAML file) like this:

    cookie_domain: ${COOKIE_DOMAIN}
  • 1
    This is really neat, didn't know you could use environment variables in container yamls. Oct 8 at 15:12

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.