A Complete Guide on How to Migrate Your Linux Hosted Website to Hetzner Webhosting

Introduction

Migrating a website to a different provider can be a nerve-racking process, especially if you are doing it for the first time. But it’s not as hard as it seems. In this guide, I will walk you through all the steps needed for migrating a website from any Linux-based host to Hetzner’s webhosting. The guide assumes you won’t migrate your domain to Hetzner and don’t have webmail or don’t want to migrate it. If you need information on migrating those, please check Martin Badstübner’s awesome guide on Hetzner’s community site!

Step 1 – Backup

It’s important to have constant backups of your site. Never move files directly from your old website host to the new host! As it WILL cause errors! Also, you don’t necessarily want to lose access to your website on the old host’s servers before the migration is completed.

When migrating to Hetzner’s web hosting servers, you need to have backed up all the files from your website’s public_html folder as well as the database. So a home directory backup and a database backup should be enough.

1.1 Download Your Website’s Files

If your old host has a backup and restore feature, go to your old host’s admin interface and try downloading the backups from there. Alternatively, if your host allows, you can use an FTP client like FileZilla to download the website files to your computer.

In FileZilla, connect to the current web server (you should get the FTP login details from your host). Contact the old hosting provider in case you don’t have all the necessary login details. It’s recommended to use port 22 and access the files via SFTP. It uses SSH to connect to the remote server and is therefore a more secure way to move your files across different machines.

FileZilla default view. The local files are on the left and remote files on the right. You can move your files to the Webhosting server via FTP client like FileZilla.
Basic view of FileZilla. The remote host is on the right and your local files are on the left.

After connecting to the remote server, select your preferred download folder on the left side of the window and then navigate to the public_html on the right side. Enter the folder and choose any file from it. Then press ctrl-a to select all the files in the folder. After selecting the files, right-click the files and select “download” from the menu. The files should start downloading to your local machine. Depending on your site’s size and your network connection, this might take some time.

Step 2 – Website Migration

Once you’ve finished downloading all the files from your website to your local machine, it’s time to upload those to your new Hetzner webserver. Check your new hosting server’s FTP/SFTP details from the KonsoleH interface (which is Hetzner’s admin interface for web hosting) by navigating to Services –> Login data. After you’ve established a connection to your hosting server, you should see that there are already some files on the server and one of them is public_html. Navigate to your local files on the left, select the folder you just downloaded, and upload its contents to the public_html folder on your Hetzner web server. Again, this might take some time so be patient. You can observe the process from the tab at the bottom of the window.

Once finished, remember to check that all the important files and folders have been transferred. There might be some files the client couldn’t properly transfer. This might happen for various reasons though most likely due to interruptions on your internet connection. You could try re-queuing them and uploading them again but sometimes they just won’t get uploaded. If they aren’t important, you can ignore them. The most important folders are the ones that have the actual content on your website, like all your data and configurations. Remember to also check for .htaccess and some sort of index file like index.html or index.php. An index file is your site’s homepage and the one to which your domain will direct people.

Step 3 – Database Migration

Database is one of the key elements of your site. It has all the options, posts, and accounts for your site, etc. Therefore, proper migration of the database is mandatory.

In KonsoleH, go to Services –> Databases and choose your database type (MariaDB/MySQL or PostgreSQL). Then create a new database with the same name and username as the one your old hosting server uses. This will create a new empty database for you.

Then log in to your old host’s admin interface and check if you have access to phpMyAdmin which is the administration interface for managing MySQL/MariaDB databases. From phpMyAdmin, you can just export the whole database as it is to your local machine. It will download a .db file on your computer.

To import the database to the one you created earlier, you need to log in to the database admin interface on Hetzner’s servers. You can do it by going to the databases tab on KonsoleH and clicking the pencil icon on the right side of the database view. It will redirect you once again to phpMyAdmin. This time to the KonsoleH one. There you can click “import” from the top menu and after a few seconds, you should see your database and its files on the “structure” view of the database. The database name will also appear on the panel on the left side of the window.

phpMyAdmin interface that can be accessed via Hetzner's KonsoleH interface.
The main view of phpMyAdmin. On the left, you will see all your databases.

Step 4 – Configuring Your Webhosting

Now that you’ve uploaded all the necessary data from your old website host’s servers to Hetzner’s web servers, it’s time to configure your server to make sure it displays your website properly.

First, head to the server configuration menu in KonsoleH. You can access it by going to Services –> Server configuration. From there, it’s important to make sure your document root is public_html (it should be on default). After confirming that your root folder is set to the correct one, click the wrench icon on the public_html folder and click Index Page from the menu. It will allow you to specify your own index file and override the default one. If you don’t remember the name of your site’s index page, you can check that with FileZilla by opening the public_html folder and checking its contents. One of the files should be called “index.something”. Type that into the text field and click save.

Modify index page in KonsoleH. This is an important step in configuring your webhosting.
For example, I used index.php as my index (home) page.

4.1 Check Your Site

After doing all the steps mentioned above, you can check whether your site is working or not. I found modifying your computer’s hosts file a rather efficient method for checking the site. Modifying the hosts file will force your computer to connect to the IP address specified on the file and to skip all DNS servers. Just copy your server’s IP followed by your site’s address to the hosts file and save it. Then use any browser and type your site’s address on the address bar. If the website on the new server works, you should be redirected to http-version of your site. This is because Hetzner doesn’t really allow creating an SSL certificate for your site before modifying the actual DNS records of your domain.

4.2 Troubleshooting

If you’re having trouble connecting to the site, you might want to take a look at the error log to determine what’s causing your site not to work or to malfunction. You can access the logs via KonsoleH by going to Statistics –> Live Logs. From there you can see all the errors from the past few days. Those are very case-specific so make sure to read them correctly and proceed accordingly. Most commonly there might be problems with permissions, you are lacking important files or your configuration is incorrect. So make sure to double-check those!

If you’re still unable to resolve the problem, you can always contact Hetzner’s support by selecting “Administration” on the top menu in KonsoleH and navigating to Support –> Support request. There you are asked to specify the problem. Make sure to be as clear as possible so that they can understand your situation and the problem/problems you’re facing.

Step 5 – DNS Records

If you have successfully completed every other step in this guide and your site is working, congratulations! It’s now time to actually redirect the traffic from your old host’s servers to Hetzner’s servers. You can do this by logging in to your domain provider’s admin interface and looking for its DNS console. There you should see all the DNS records your domain has. In case you only have a website, there will be only a few records, A and AAAA records. A record is for IPV4 and AAAA is for IPV6.

5.1 Updating the Records

Notice how they still point to your old host’s IP address. If you want your traffic to be redirected to your new host’s server, you should modify those records to point to your new host’s IP address. Of course, this will cause some downtime since you completely remove the link to your old server and it will take up to 48 hours until the updates are propagated everywhere on the public internet. However, if you don’t mind a short downtime, you can modify them directly. You can see your server’s IP from the KonsoleH main screen on the “Details” tab. Just replace the old IPs on the records with the new ones.

5.2 Countering Downtime

But if your site is a bit more important and can’t stand any downtime or you want it to be accessible the whole time, you can alternatively create new A and AAAA records for the domain. Remember to also wait for the propagation period to end until removing the old records. DNS records are usually created as follows:

Record Type : Name : Value : TTL

Where the record type is either A or AAAA for IP addresses, the name parameter tells the name server which domain to point, and the value tells the server where to point it. TTL specifies how long the DNS data will live, hence the name TTL (Time To Live). Setting up a lower TTL will make the name server refresh the data more often therefore speeding up the propagation. Usually the default TTL time is 3600 seconds or one hour.

Inserting DNS records in order to reroute your traffic from your old provider to Hetzner's servers.
This is how it looks in Hetzner’s DNS console. The exact view can vary depending on your provider.

There are also other types of records. For example, MX is the default for mail and it can be specified with SPF, DKIM, and DMARC records but those are an entirely different subject.

Conclusion

Migrating your server from another Linux-based host to Hetzner’s web hosting servers is not a fundamentally hard process. It’s actually a rather straightforward process and with the proper basic understanding of how web hosting works, you should be able to successfully migrate your website over to Hetzner’s servers.

I wrote this guide since when I was migrating one of my own websites I noticed there were very little Hetzner specific migration guides for webhosting. So I hope this helps you with your migration process!

image_pdf
Kotisivu » Artikkelit » A Complete Guide on How to Migrate Your Linux Hosted Website to Hetzner Webhosting

Ei vielä kommentteja

Harkitsehan kommentin jättämistä!