How do I move a site from a server to another one? I am trying to move a Drupal 8 site, but I get the following error:

The website encountered an unexpected error. Please try again later.
InvalidArgumentException: Class &quot;\Drupal\system\Controller\Http4xxController&quot; does not exist. in Drupal\Core\DependencyInjection\ClassResolver-&gt;getInstanceFromDefinition() (line 29 of core/lib/Drupal/Core/DependencyInjection/ClassResolver.php).

How do I properly move a Drupal 8 site from a server to another one?
What I did was importing the database, moving the files, and changing the database connection settings.
In a nutshell, moving a Drupal website from one host to another is just a matter of moving the files and the database, and then connecting the two.

However, there are several things you need to consider:


Server environment should be as close as possible to each other. This way you will avoid any errors that are a result of having different software/configuration on production and development servers. Compare PHP version, MySQL version, Apache modules, and setup of all of these components.
File permissions need to be set up properly. I've seen problems caused by this dozens of times. In short, the Apache user needs to have enough permissions to access and work with your Drupal website. Otherwise, it won't be able to write and even read files in some cases. Read more about how to secure correct file permissions here.
If you do this manually via FTP, make sure that all files are transferred. It often happens that one of the files wasn't uploaded completely. This usually results in broken Drupal site and random errors. Other ways to migrate a D8 website are Drush, Git or simply zipping the whole directory and using wget on the other server to transfer it directly from server to server.
You will need to clear all caches. Preferrably you won't have CSS/JS aggregation and page caching turned on when you migrate the database. You can do this through SQL/phpMyAdmin. See this answer for more information.
Update trusted hosts in /sites/default/settings.php file.
Once you can access your website, update the temporary directory path at /admin/config/media/file-system, as well as any other settings (e.g. of contrib modules) that store server paths/domain name.


See also docs on migrating a D7 site. Most items are still applicable for D8.



If you follow the guidelines above, you will avoid most issues. If you still have problems after migration, post here the exact log messages you're receiving.

Regarding the error you already posted: I'd make sure that all files are there, and that your cache is cleared before doing anything else.

Hope this helps.