I'm trying to migrate a drupal website from a server into my localhost but I trigger the error

The provided host name is not valid for this server.

I've seen I need to add the trusted host pattern, but looks like this is not working I still get the error

My server is run on port 9000

sudo php -S

My trusted hosts, and I've no Vhost

$settings['trusted_host_patterns'] = array(
  • Why don't you add ^127\.0\.0\.1$ or ^127\.0\.0\.1\:9000$ to this array?!
    – leymannx
    Commented Nov 20, 2019 at 10:03
  • I already tried to add ^127\.0\.0\.1\:9000$ but I still get the error
    – Minirock
    Commented Nov 20, 2019 at 10:05
  • Why don't you say this in your question then? Have you also flushed caches multiple times? Do you maybe have OPcache or some other server side caching enabled? And what's with just ^127\.0\.0\.1$ and just ^localhost$? And what happens when you completely remove this setting?
    – leymannx
    Commented Nov 20, 2019 at 10:06
  • 1
    An IP and a domain name are not the same. Blindly trusting all domain names on the same IP in a shared hosting environment would be a fiasco.
    – Hudri
    Commented Nov 20, 2019 at 10:23
  • 1
    Looks like removing all the array solved it.
    – Minirock
    Commented Nov 20, 2019 at 11:00

1 Answer 1


If this is a dev - env, simply add

$settings['trusted_host_patterns'] = [$_SERVER['SERVER_NAME']];

But never do this in production.

  • Or remove $settings['trusted_host_patterns'] completely.
    – leymannx
    Commented Nov 20, 2019 at 12:39

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.