A friend asked me to take over his photo blog. It had lived for years on OVH shared hosting, the kind you pick when you just want things to work: you drop WordPress in, and the host runs the web server, the database, the backups, the mail and the DNS. He wanted the site to live on my dedicated server from now on. On paper that’s an rsync and an SQL export. In practice it’s a series of small decisions the host was making for you without you knowing, and that you now have to make yourself, one by one.
This is that move as it happened, with the numbers measured during the operation and the mistakes I made along the way. The site weighs 146 GiB across 1,124,853 files, with a MariaDB database of about 550 MB. That’s not huge for a server, but it’s big enough that several usual habits stop working, starting with backing up into a compressed archive.

Listing what the host was doing
Before copying anything, I listed the services shared hosting provided. There were five: hosting the files, running the database, backing both up, carrying the domain’s mail, and serving the DNS zone. Each needed a clear answer: I take it over, I replace it with something else, or we decide it’s no longer needed. The diagram below sums up where each service ended up.
Two answers weren’t mine to give. The DNS zone is in my friend’s OVH account and stays there: I have no access to it, and every record will have to be entered by hand by him. And when I asked which mailboxes he used, he told me he didn’t really use the domain’s mail. Those two constraints shaped everything else: no automatic DNS validation for the certificate, and no mailbox migration.
The last inventory item is how long DNS records live. The domain’s records had a TTL of 3600 seconds. At cut-over time, a resolver that has just read the old address keeps it for up to an hour. So the TTL has to come down, to 300 seconds for example, at least an hour before the cut-over, otherwise the lowering itself takes an hour to propagate.
Copying 146 GiB out of shared hosting
The hosting plan offered SSH access, which makes the copy simple in principle. I ran rsync from the destination server against the host’s SSH account, pulling the files rather than pushing them: the shared host doesn’t need to know a key from the new server, and the new server drives the transfer.
cd /data/www
rsync -avz --progress -e "ssh -p 22" compte@ssh.hebergeur.example:www/site .
For the first few hours throughput sat between 7 and 10 MiB/s. Then it dropped to about 3 MiB/s and stayed there, although the destination server was idle: 88% CPU free, 8% I/O wait. The reason appeared when I measured the folders already copied. From 2017 to 2020, each year holds a few thousand photos of 1 to 3 MB. From 2021 on, WordPress kept a host of intermediate sizes for every image, and the folders fill up with thumbnails: 129,160 files averaging 130 KB in 2022, 316,912 files of 70 KB in 2026.
rsync pays a fixed cost for every file whatever its size: it has to list it, compare size and date, create it under a temporary name, then rename it. On 3 MB photos that cost disappears in the transfer. On 70 KB thumbnails it dominates, and throughput in MiB/s collapses even when the number of files per second holds up. The -z option, which I’d added out of habit, is useless here anyway: a JPEG is already compressed, and compression only burns CPU on the host’s side, on a shared machine.

The copy took a good ten hours, and the first run stopped midway without my finding out why. A copy that long belongs in tmux or screen, not straight in the terminal: if the SSH connection breaks, rsync dies with it. Fortunately restarting rsync costs almost nothing, since it skips files that are already identical.
The two traps of restarting
Restarting is where I made two mistakes worth knowing about, because they go unnoticed. First: in the meantime I had edited wp-config.php on the new server to point at the new database. The restart overwrote it with the host’s version, since the two files differed in size and date. The test site lost its database in a second. I had copied it aside just before and put it back, but since then every catch-up copy excludes that file.
The second is sneakier. rsync ran as root with -a, which implies -o and -g: keep owner and group. For the files it copies, that’s expected. But rsync also applies attributes to the files it skips because they’re already up to date. The last check copy therefore put the host user’s numeric ID back on every file of the site, including the ones I had given to nginx the day before. The site stayed readable, but WordPress could no longer write to its folders. The right command for a catch-up copy is this one, followed by putting the ownership back in order:
rsync -rlptv --exclude=wp-config.php -e "ssh -p 22" \
compte@ssh.hebergeur.example:www/site/ /data/www/example.org/
chown -R nginx:nginx /data/www/example.org
restorecon -R /data/www/example.org
-rlpt keeps recursion, symlinks, permissions and timestamps, but leaves ownership alone. restorecon restores the expected SELinux contexts: httpd_sys_content_t for the site, httpd_sys_rw_content_t for wp-content, where WordPress must be able to write. On 1.1 million files, both commands together took 14 seconds.
The database, and a line inherited from the host
The database export comes from the host’s tool, and the import goes into a dedicated database with a user that only has rights on it. Then wp-config.php needs adapting: database name, user, password, and localhost as the host so it goes through the local socket. Reading the file again, I found a line added for the host:
// what the shared host's wp-config.php contained (its HTTPS proxy sets this header)
if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') $_SERVER['HTTPS']='on';
// what I left on the new server: same meaning, no warning when the header is absent
if (($_SERVER['HTTP_X_FORWARDED_PROTO'] ?? '') === 'https') $_SERVER['HTTPS'] = 'on';
At the host, HTTPS is terminated by a proxy that forwards the request in clear to the PHP server, with an X-Forwarded-Proto header saying the visitor was on HTTPS. This line copies that information so WordPress doesn’t think it’s serving a page over HTTP and loop on redirects. On my server there’s no proxy in front of PHP and the header doesn’t exist. The original line wouldn’t have broken anything, but on PHP 8 it raises an “Undefined array key” warning on every page. The rewritten version keeps the same meaning and stays quiet when the header is absent.
Testing under another name without touching the public site
I wanted my friend to be able to check the site at my place while the old one stayed online. That takes a test name, here photos.example.net, a subdomain of a domain of mine that benefits from the wildcard certificate I already have. The problem is that WordPress writes its address into the database: in the home and siteurl settings, but also in every image link and every post’s identifier. Without rewriting, the test site redirects to the real domain and loads its images from the old hosting.
cd /tmp
WP="sudo -u nginx wp --path=/data/www/example.org --skip-plugins --skip-themes"
$WP search-replace "https://example.org" "https://photos.example.net" --all-tables-with-prefix --report-changed-only --precise
$WP search-replace "http://example.org" "https://photos.example.net" --all-tables-with-prefix --report-changed-only --precise
$WP option get home
wp search-replace is the tool to use, because part of WordPress’s settings is stored serialised by PHP, with each string’s length written next to it. A plain SQL REPLACE would change the text but not the length, and PHP would then refuse to read the value back. --precise forces every row through PHP, which recomputes those lengths everywhere. It’s slow: nearly two hours for the first pass, over 250,000 metadata rows and 68,000 posts, and a first attempt was even cut off after thirty minutes by a time limit. Both patterns include ://, which leaves the domain’s e-mail addresses untouched.
== https://example.org
wp_options option_value 1 PHP
wp_posts guid 102254 PHP
...
Success: Made 152143 replacements.
== http://example.org
wp_posts post_content 1166 PHP
wp_posts guid 1962 PHP
...
Success: Made 3680 replacements.
What isn’t replaced is instructive too. In the export taken before the rewrite, I counted 523 addresses written as https:\/\/example.org, with escaped slashes: that’s how JSON writes them. They came from messages received through the contact form, from the AMP plugin’s caches, and from a gallery attribute in a single post. None of them is visible to a visitor, and I left them. Only a third pattern would have caught them.
The most important point of this step is that you don’t undo it. For the cut-over, I re-import a fresh export of the host’s database, which still holds the original addresses. A reverse rewrite would have turned the 5,643 old http:// links into https:// along the way, among them 775 internal identifiers of old posts, which some feed readers use to tell whether a post is new.
Two web server configurations for one site
The site has two names during the transition, so two configuration files. The test name serves the site over HTTPS with the wildcard certificate. The real domain has no certificate yet, and can’t get one while its DNS points to the host: Let’s Encrypt validates the request by fetching a file from whichever server answers for that name. Its configuration therefore starts in plain HTTP, with the validation path already in place.
server {
listen 80;
server_name example.org www.example.org;
location /.well-known/acme-challenge/ {
root /var/lib/certbot/webroot;
try_files $uri =404;
}
root /data/www/example.org;
# ... the usual WordPress protections: no xmlrpc.php, no PHP in uploads, wp-config denied ...
}
One detail cost me ten minutes: testing from the server itself on 127.0.0.1, I got a 404 on this vhost. An internal service has a block listening precisely on 127.0.0.1:80, and nginx first narrows the blocks to those whose listen address exactly matches the connection, before looking at names. My local request therefore landed on that block, never on the site’s. Tested on the public address, the way Let’s Encrypt will reach it, the validation file answered 200. Once the certificate is issued, a single Ansible variable flips to true and the configuration switches to HTTPS, redirecting port 80 and www to the bare domain.
The site also has its own PHP-FPM pool. That isolates its processes and limits from the server’s other sites, and gives it its own error log. That log is what saved me at the next step.
One symlink, two outages
During the copy the folder kept the host’s name, and I had created a symlink with the final name so the configuration was ready. Once the copy finished, I replaced the link with the real folder. The site immediately answered 500:
PHP Fatal error: Uncaught Error: Failed opening required
'/data/www/old-name/wp-content/plugins/jetpack/jetpack_vendor/automattic/jetpack-stats/src/class-wpcom-stats.php'
The path shown was the old one. PHP-FPM keeps two path-dependent things in memory: OPcache, which holds compiled scripts, and the realpath cache, which remembers where each symlink leads. Both still pointed at a folder that no longer existed under that name. A systemctl reload php-fpm set everything right after about a minute of errors. I also checked that the database held no absolute path, neither the old one nor the host’s: some plugins store them, and they would have needed rewriting too.
The second outage came from another service. My friend wanted to be able to upload files to his site, and I gave him a virtual folder in SFTPGo, the SFTP and WebDAV server I use. SFTPGo runs with ProtectSystem=strict: systemd mounts the whole system read-only for it, except the paths listed in ReadWritePaths. I added the site’s folder to that list while it was still a symlink, and SFTPGo stopped starting:
sftpgo.service: Failed to set up mount namespacing: /data/www/example.org: Permission denied
sftpgo.service: Failed at step NAMESPACE spawning /usr/bin/chown: Permission denied
avc: denied { read } for comm="(chown)" name="example.org"
scontext=system_u:system_r:init_t:s0 tcontext=system_u:object_r:httpd_sys_content_t:s0 tclass=lnk_file
To set up the service’s namespace, systemd follows the link, and SELinux forbids the init process from reading a link labelled as web content. The - prefix in front of the path doesn’t help: it tolerates a missing path, not a refused one. I removed the line by hand, the service was back after eleven seconds, and the Ansible role now checks that each path is a real directory before writing the configuration.
Backing up 146 GiB without an archive
My application backups make tar.gz archives every night. At 146 GiB that would mean recompressing and resending the whole site every night, for content that changes by a few photos a day. So I built a mirror: every night rsync sends only the differences to the NAS at home, through the home server that mounts the NAS.
The receiving account can do exactly one thing. Its key is only accepted from the dedicated server’s address inside the WireGuard tunnel, and it’s forced into rrsync -wo, a script shipped with rsync that locks the session into one folder and only allows writing. If the dedicated server were compromised, the attacker could write into that folder, but not read the backups, leave the folder, or open a shell.
# ~site-files-receiver/.ssh/authorized_keys on the home server
from="10.99.0.3",command="rrsync -wo /mnt/nas/site-files",restrict ssh-ed25519 AAAA... site-files-backup
A pure mirror has a flaw: if a file is deleted or encrypted on the server, the next night propagates it. --backup-dir fixes that. Any file rsync is about to overwrite or delete is first moved into a dated “attic” folder, kept thirty days. Setting it up brought three surprises. rsync won’t create two missing directory levels at once, hence --mkpath. rrsync refuses any path containing ../, so the attic is written from the root of the jail. And the first night reported a failure although it had sent 108 GB in 2 h 17: rsync returned code 24, which only means files vanished during the transfer. They were the temporary files of my own copy, still running. The script now treats that code as a warning.
rsync -rlpt --mkpath --delete --partial --stats \
--backup --backup-dir="/$name/attic/$TODAY" \
--exclude=wp-content/cache/ --exclude=wp-content/wflogs/ \
-e "$SSH" "$path/" "$DEST:$name/current/"
code=$?
# 24 = "some files vanished before they could be transferred": not a failure
[ $code -eq 0 ] || [ $code -eq 24 ] || fail
I checked every behaviour with a fake site before trusting the real one. A modified file and a deleted file both landed in the day’s attic, and an attempt to read the backups back with the same key was refused.
The database is already covered by the nightly backup of every database on the server, and by a replica at home. But my friend also wanted his own copy, reachable without me. Every night at 02:40 a script drops a compressed dump into his SFTP folder and keeps fourteen.
mariadb-dump --defaults-extra-file=/etc/mysql/backup.cnf \
--single-transaction --quick --routines --triggers --events \
--default-character-set=utf8mb4 --databases "$db" | gzip -6 > "$tmp" && gzip -t "$tmp" \
&& chown nginx:nginx "$tmp" && chmod 0640 "$tmp" && mv -f "$tmp" "$final"
# keep 14 dumps: anything older than 14 days minus one hour
find "$dir" -maxdepth 1 -type f -name "$db-*.sql.gz" -mmin +$(( 14 * 1440 - 60 )) -delete
Every table being InnoDB, --single-transaction gives a consistent snapshot without locking the site. The file is written under a hidden name, checked with gzip -t, then renamed: my friend never sees a half-written dump. And the retention takes an hour off the fourteen days, otherwise the dump from exactly fourteen days ago, only a few seconds older, would stay one night too long. A dump is about 43 MB, so 0.6 GB for fourteen.
The contact form, and the domain’s mail
The contact form uses PHP’s mail function, so Postfix on my server, which relays to my mail server. I sent a real message through the form: it reached my friend, but in the spam folder. And looking at the headers, I found a worse problem. The visitor’s address, which the form puts in Reply-To, had been replaced by the server’s technical address. Replying to the message would have written to the server, not to the visitor.
# before: sender_canonical_classes = envelope_sender, header_sender
From: "Visitor Name" <root@example.net>
Reply-To: root@example.net <- the visitor's address was gone
# /etc/postfix/header_checks_from (regexp), with sender_canonical_classes = envelope_sender
/^From:(.*)<[^>]*>(.*)$/ REPLACE From:${1}<root@example.net>${2}
/^From:[[:space:]]*[^[:space:]<]+(.*)$/ REPLACE From: root@example.net${1}
# after
From: "Visitor Name" <root@example.net>
Reply-To: visitor@example.com
The cause was in my own configuration. My mail server only accepts a relayed message whose sender matches the authenticated account, so all my servers rewrote the sender. But header_sender rewrites every sender header, and Postfix files Reply-To in that category. I limited canonical rewriting to the envelope and added a header_checks rule that only touches From: and Sender:, keeping the display name. The fix was tested from every running server. For the spam folder I have no certainty: authentication is correct on my side, and what counts is probably reputation, a sender new to that recipient and a visitor’s name in front of a technical address. The usual remedy is for the recipient to mark the first message as legitimate.
As for the domain’s mail, my friend no longer used it, so we don’t migrate it. He keeps his hosting subscription for two months, to be sure nothing’s missing, then cancels it. At that point, deleting the MX records won’t be enough: a domain with no MX and no SPF is a domain anyone can spoof. The contact form already shows traces of it: bots, most likely, typed fake addresses from the domain as the sender. So he’ll enter this by hand:
| Name | Type | Value | Purpose |
|---|---|---|---|
| example.org | MX | 0 . | “null MX” (RFC 7505): the domain receives no mail, and senders are told at once |
| example.org | TXT | v=spf1 -all | no server may send for the domain |
| _dmarc.example.org | TXT | v=DMARC1; p=reject; | receivers reject fake mail in the domain’s name |
He’ll also delete the host’s MX records, and the client autoconfiguration records (autoconfig, autodiscover, SRV) that would point at mailboxes that no longer exist.
The cut-over
The cut-over happened on a weekday evening at 7 pm, and everything above was there to make it short. Order matters more than speed: freeze the old site, bring over its last data, move the DNS, and only then set up HTTPS on the new server. Here is what really happened, minute by minute, including what didn’t go as planned.
The TTL that wouldn’t come down
The main record’s TTL had been at 300 seconds since the morning. The www one was supposed to follow, but the host’s interface refused the change with a cryptic message: “CNAME and other data”. That’s a DNS rule: a name carrying a CNAME can’t carry any other record, and www also had MX and TXT records, leftovers of the host’s mail. The interface presented www as an alias, while the host’s servers actually published it as a plain A record; I checked directly against them with dig. So there was no need to turn it into a CNAME: changing its address was enough.
Accepted consequence: for up to an hour after the cut-over, some www visitors could still reach the old host. Harmless, since the old site stayed online, identical, and nobody published there any more. That’s the whole point of freezing the old site rather than switching it off.
; before: the host's addresses (TTL 300 on the apex, but 3600 left on www)
example.org. 300 IN A 198.51.100.20
example.org. 300 IN AAAA 2001:db8:51::28
www.example.org. 3600 IN A 198.51.100.20
www.example.org. 3600 IN AAAA 2001:db8:51::28
www.example.org. 3600 IN MX 1 mx1.host.example.
www.example.org. 3600 IN TXT "l|fr"
; after: A records to the new server, both AAAA deleted, the rest untouched
example.org. 300 IN A 203.0.113.10
www.example.org. 3600 IN A 203.0.113.10
Freeze, then bring the database over
My friend stopped publishing, then started a database export from the host’s interface. The file comes as a download link; before importing anything, I look at what’s inside. These exports sometimes carry a CREATE DATABASE and a USE with the database’s name at the host, which would send the import into a ghost database. This one had neither, came from MySQL 8, and used the same character sets as the copy already in place, which MariaDB 12.3 knows.
zcat dump.sql.gz | head -5 # MySQL 8 (Percona), "Database: hostdb"
zcat dump.sql.gz | grep -E '^(CREATE DATABASE|USE )' # nothing: it imports where I say
zcat dump.sql.gz | grep -c '^DROP TABLE IF EXISTS' # 16: every table is replaced
zcat dump.sql.gz | grep -oE '(DEFAULT CHARSET|COLLATE)=[a-z0-9_]+' | sort | uniq -c
zcat dump.sql.gz | tail -1 # -- Dump completed on ... 18:40:58
The import took 66 seconds, after a backup of the test database, just in case. As planned, it brought back the original addresses: no reverse rewrite was needed. The latest post was from 6:22 pm, proof that the export did hold the latest additions. I then flushed WordPress’s caches so nothing from the test period would survive.
mariadb-dump --single-transaction blogdb | gzip > test-db-before-import.sql.gz # the way back
zcat dump.sql.gz | mariadb blogdb # 66 seconds
sudo -u nginx wp option get home # https://example.org: the original URLs are back
sudo -u nginx wp cache flush
sudo -u nginx wp transient delete --all # 222 leftovers from the test period
That left the final file copy, in case the database export came with new photos. I ran it from the new server, with the no-ownership options and excluding wp-config.php. It took 1 h 27, almost all of it spent comparing: 1,165,434 entries checked, 154 GB in total, and only five files transferred, 4 MB. Four Jetpack firewall rules and a cache log, no photos: my friend’s last change hadn’t added any. That copy doesn’t need to finish before switching DNS, since it goes from the host to the new server whatever DNS says; it actually ran through everything that follows, and put ownership and SELinux contexts back in order as it ended.
The DNS, and the forgotten AAAA records
When I looked at 7:35 pm, both A records already pointed to the new server. But both AAAA records, the IPv6 ones, still named the host. That’s the classic moving trap: IPv6 visitors, a good share of mobile connections and many home boxes, would have kept landing on the old server. Worse, Let’s Encrypt prefers IPv6 when an AAAA exists: certificate validation would have gone to the host and failed. My server only listens on IPv4 for this site, so the right answer was to delete both AAAA records, not to point them elsewhere.
My friend deleted them; at 7:48 pm I checked on both of the host’s DNS servers that the zone’s serial number matched and that the AAAA records were gone, then that a public resolver did see the new address.
The certificate, rehearsed first
The web server configuration for the real domain had been serving Let’s Encrypt’s validation path on port 80 since the day before. Once DNS was in place, all that was left was asking for the certificate. I always rehearse on Let’s Encrypt’s staging environment: a failure there is free, whereas the real service limits failed validations per hour, and a lagging DNS cache can be enough to cause some.
# rehearse on Let's Encrypt's staging service first: failures there cost nothing
certbot certonly --webroot -w /var/lib/certbot/webroot -d example.org -d www.example.org --dry-run
# The dry run was successful.
certbot certonly --webroot -w /var/lib/certbot/webroot -d example.org -d www.example.org
# This certificate expires on 2027-02-15.
The rehearsal passed, the real certificate followed within the minute. One variable flipped to true in Ansible switched the configuration to HTTPS: port 80 and www redirect to the bare domain. Between the DNS change and that moment, the site was unreachable over HTTPS for a few minutes, since WordPress forces HTTPS and the new server had no certificate yet. That’s the price of HTTP validation; DNS validation would have allowed getting the certificate beforehand, but it required one more record in a zone I don’t manage.
http://example.org/ 301 -> https://example.org/
http://www.example.org/ 301 -> https://example.org/
https://www.example.org/ 301 -> https://example.org/
https://example.org/ 200 0.22 s
https://example.org/contact/ 200 0.17 s
# in the home page: 38 links to https://example.org, 0 to the test name, 0 in http://
Final checks: every page returns a 200, all links point to the final domain, none to the test name or over HTTP, photos load from the new server, and a public resolver sees the new address with no IPv6. The move was done, about an hour after it started.
What I take away
Leaving shared hosting means taking back decisions the host was making quietly. Copying the files and the database is the easy part. The work is listing the services provided, then giving each an explicit answer. Here the files and database are taken over, the backup is replaced by a mirror with history, the mail is dropped but locked down, and the DNS stays with its owner.
The mistakes I made all have the same shape: a tool doing a bit more than you think. rsync applies ownership to files it doesn’t copy. Postfix files Reply-To among the senders. systemd follows a link SELinux forbids it to read. PHP-FPM remembers a path that no longer exists. None of them shows in a quick test, and all of them show when you read the logs and headers instead of settling for a 200.
The post From shared hosting to self-hosting: moving a 146 GiB WordPress photo blog appeared first on Hécate Regnier - Neurozone.
Top comments (0)