TL;DR: If you encounter the error, "The provided host name is not valid for this server. " while trying to install Drupal 8, and you have just created a new virtual host in Apache for your site,you may have forgotten to a2ensite your new host!
For example (in Ubuntu):
sudo a2ensite examplesite.conf
Then restart Apache for your site enable to take effect:
sudo service apache2 restart
Recently I ran into this error while trying to install a new Drupal 8 site. After some searching I found this error has to do with a Drupal 8 feature that protects against HTTP host header attacks. From Stackexchange:
Essentially, is was possible to spoof the HTTP Host header for nefarious purposes, and trick Drupal into using a different domain name in several subsystems (particularly link generation). In other words, the HTTP Host header needs to be considered user input, and not trusted.
To combat this, a new setting,
$settings['trusted_host_patterns'], was added to Drupal 8 to configure a list of "trusted" hostnames that the site can run from. The setting needs to be an array of regular expression patterns, without delimiters, representing the hostnames you would like to allow to run from.
So now in settings.php you can set an array with the hostname(s) you're using for your site. However, by default this setting is turned off. I hadn't even installed Drupal yet - this error was showing up on install.php and the site root.
I had just switched the DNS servers for this website, so I was worried this had something to do with the error. I came back a few hours later, cleared my cache and tried again. Same error, DNS was not the problem.
I tried to edit settings.php anyway, and start using the trusted_host_patterns array. This wasn't working, and I kept trying different hosts, adding onto the array, by the end it looked like this:
$settings['trusted_host_patterns'] = array( '^mysite\.com$', '^www\.mysite\.com$', '^localhost$', '^123\.456\.789\.11', );
But still no luck! That's when I backed up a bit, and realized I had made a silly mistake: forgetting to turn on my new site in Apache! A quick
a2ensite mysite.conf and Apache restart later, and Drupal installed without any further problem.
I hesitated to write this post down out of some embarrassment, but I decided to do it anyways since it might be useful to someone out there forgetting the same thing. Drupal will throw this error pre-install if your virtual host is not set up correctly.