15

In Drupal 7, we can quickly change the base URL of the website.
How can I do this, in Drupal 8?

14

In Drupal 8 this option has been removed. You don't have to configure base_url to run your site. Drupal 8 can detect this without your help. If not, you should first check your webserver configuration.

Instead of base_url you should configure trusted_host_patterns in settings.php. This is not needed to run the site, but important for security reasons.

More info: Removed base_url option from settings.php and New setting for trusted hostname configuration

Edit:

There are some special use cases when running drupal from command line or reverse proxy, that used $base_url in the past. This can no longer be supported in the same way because of symfony. There is a discussion going on how to provide a solution for these cases. This does not mean that you cannot run drupal from the command line or reverse proxy. The standard way is of course possible without problems.

You can follow the development here: https://www.drupal.org/node/2753591

  • 1
    Sorry but this answer is partially misleading. You can have a perfectly valid webserver configuration and still need a base_url. $base_url is also coming back here: drupal.org/node/2753591 – Fidelix Jul 30 '16 at 10:07
  • At the time I wrote the answer $base_url was gone. If it is coming back, OK. But most times you really don't need this, if you configure multiple installations on the same host with vhosts and dns, which most shared hosting environments offer as standard configuration option. – 4k4 Jul 30 '16 at 13:40
  • Agreed. But it is misleading to say the webserver configuration is broken if you need $base_url. There are plenty of valid use cases that warrant $base_url. – Fidelix Jul 30 '16 at 18:10
  • 2
    This was the motivation to remove $base_url: drupal.org/node/2528988 (plenty of valid use case: you can move drupal 8 to subdirectories any time and it will recognize this on the next request without configuration changes) – 4k4 Jul 31 '16 at 7:29
  • OK, I see now in the linked thread your point, I will change the answer. – 4k4 Jul 31 '16 at 7:39
5

I thought once some kind of tweaks were needed when moving between production (http:// example.com/) and dev (http:// localhost/~aviram/example.com/). But no, D8 is smart enough to fix links automatically.

After moving a complete site (PHP files and DB dump), just go through the D8 database update process (http://example.com/update.php) even if there is no update for the database model. This fixes the problem.

I learned this is a Drupal 8 cache-related problem probably because some pre-rendered content is kept in sites/default/files/php/. And the update.php process somehow cleans this cache.

  • 1
    Yes, /update.php always clears the cache, even if there are no updates to run. This is a nice trick to get a site running after moving it to a new place, if you don't want or can't access another method to clear the cache. – 4k4 Aug 3 '17 at 12:43

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.