Skip to main content

Issue

Trying to run a Drupal 9 localhost site on a Mac through Docker that uses a Wodby base.

 

Normally when using Docker and it's correctly set-up you don't need to add to the etc/hosts file.  However, reading through the Wodby local domains content, it seems this step is required.

Off to the /etc/hosts file

sudo vim /etc/hosts

Add the required package.  In this instance I'm using Drupal

127.0.0.1 drupal.docker.localhost

Changes made to this file will be applied instantly.  So no need to restart.  However, if ping yourdomain.com still gives you the wrong IP, try clearing your DNS cache.

sudo killall -HUP mDNSResponder

 

A step forward, yet another error

Following this step I'm getting the error

The provided host name is not valid for this server.

This error message is caused by a security feature that was added to Drupal 8.  In order to prevent this from happening, Drupal utilises a feature of the Symfony framework being trusted host mechanism.  Here you can whitelist hostnames. Trusted hosts can now be configured in Drupal through a new setting in settings.php:

$settings['trusted_host_patterns']

If you are running your Drupal website from www.yourdomain.com, add the following in your settings.php:

$settings['trusted_host_patterns'] = array(
  '^www\.yourdomain\.com$',
);

Other local development environments, you can use the following in your local.settings.php:

$settings['trusted_host_patterns'] = array(
  '^127\.0.\0.\1$',
  '^localhost$',
);

 

Getting closer

Now the error is showing as

This website encountered an unexpected problem. Please try again

You need to clear cache.  As you don't have access to the site and Drush is installed, you can use the drush clear cache command

drush cr

Remember to run this through your Docker container.

 

The site is now up and running.