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

2 Answers 2


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
    Commented Apr 11, 2017 at 5:15
  • 2
    Is it possible to set IP Address, Instead of domain?
    – AshwinP
    Commented Dec 11, 2017 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
    Commented Jan 8, 2019 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. Commented Oct 8, 2021 at 15:12
  • 1
    I don't know if env variable approach worked in the past, but at the moment it's not supported. I think there is an issue on d.o to introduce a similar approach to how symfony allows is using the %env(COOKIE_DOMAIN) construct. drupal.org/project/drupal/issues/2879846
    – awm
    Commented May 6, 2022 at 12:57
  • Setting a COOKIE_DOMAIN env var and expecting it to work by itself will not work no. You need to insert it into the services.yml file as shown in the answer. You could use any name for the env var that you like.
    – Darvanen
    Commented May 18, 2022 at 2:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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