Let’s talk about home servers. Running my WordPress site on my own PC was a fantastic experience in terms of control and performance, but electricity bills in Mauritius are no joke! I loved the speed my home setup provided, but with the costs adding up, I knew I had to find a more budget-friendly solution. Enter Hetzner—a hosting provider offering virtual machines at a fraction of what it costs to keep my PC running. Here’s my step-by-step migration from my home PC to Hetzner, including some lessons and gotchas.
Why Move?
Running my WordPress site on a home PC meant high performance, but that performance came with a price. Electricity costs in Mauritius made it unsustainable to keep the setup running full-time, so I decided to host the site on a virtual machine at Hetzner instead. Although my home server was a bit faster, the affordable pricing on Hetzner made the switch worthwhile.
Migrating WordPress: The Plan
Moving WordPress isn’t just about copying files; it’s about ensuring everything is set up properly on the new environment. Below is a breakdown of each step, from backing up my database and files to configuring the new server.
Step 1: Backing Up the Essentials
The first task was creating backups of my WordPress files and database. This keeps the site’s content intact and makes the transition smoother.
Database Backup Command
mysqldump -u DB_user -p DB_name > wordpress_db_$(date +%Y-%m-%d_%H-%M-%S).sql
File Backup Command
tar -zcvf wordpress_files.tar.gz /var/www/html/*
My WordPress data was on /var/www/html, so feel free to edit your path.
Send Backup Files to the New Server
After creating backups of both the WordPress files and database, we need to transfer these backup files to the new server. The scp
(secure copy) command is a straightforward and secure way to move files over SSH between servers. Here’s how it works in our migration:
scp wordpress_files.tar.gz wordpress_db_2024-10-28_18-07-05.sql [email protected]:/opt/
scp
– This command stands for “secure copy,” using SSH encryption to transfer files securely between systems(Stay updated with the website to learn more about transferring data securely using commands like scp
, rsync
, and cp
).
Step 2: Setting Up the New Server on Hetzner
Now, we need to recreate the environment on Hetzner by installing Apache, MariaDB, and PHP.
apt update && apt upgrade
apt install apache2 mariadb-server mariadb-client php php-mysql
To lock down MariaDB, run the following to set up secure configurations:
mysql_secure_installation
Step 3: Configuring the Database
Next, I created a database and user on the new server to match my WordPress setup:
CREATE USER 'DB_user'@'localhost' IDENTIFIED BY 'DB_password';
CREATE DATABASE DB_name;
GRANT ALL PRIVILEGES ON DB_name.* TO 'DB_user'@'localhost' IDENTIFIED BY 'DB_password';
FLUSH PRIVILEGES;
These steps set up the database environment, allowing WordPress to connect and manage the data.
Step 4: Restoring Files and Database
With the setup in place, I restored my WordPress database and files:
Database Restore
mysql -u root -p DB_name < wordpress_db_2024-10-28_18-07-05.sql
File Restoration and Apache Config Setup
cp wordpress_files.tar.gz /var/www/html/
cd /var/www/html/
tar -zxvf wordpress_files.tar.gz
Copying the Apache configuration from my old setup ensured continuity, so I moved the existing Apache settings to the new server and reloaded Apache to apply them. You can use scp as well to copy the configuration.
Step 5: Resolving .htaccess and Rewrite Module Issues
One issue I encountered was that I initially missed transferring .htaccess
and enabling Apache’s rewrite module. This caused broken links and routing issues. Here’s how I fixed it:
Enable Rewrite Module
a2enmod rewrite
Copy .htaccess
Make sure .htaccess
is in /var/www/html/
and configured correctly.
Restart Apache
systemctl restart apache2
Final Step: Updating the DNS
After setting up the new server, one final (but crucial) step was updating the DNS records to point to the new IP address. This change directs traffic to the new Hetzner server, ensuring my site is accessible at its domain. It’s an easy step to overlook, but essential for a smooth transition!
Final Thoughts
Although the Hetzner VM doesn’t quite match the performance I had at home, the savings on electricity make up for it. Mauritius’s energy costs make running a home server full-time pretty expensive, so a cost-effective, low-maintenance setup like Hetzner’s is a win for my WordPress site. This migration was a good experience, and I hope these steps help anyone looking to make a similar move!