> ## Content Index
> Fetch the complete content index at: https://blog.sudowl.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Moving a XenForo Forum to a New Server: Empty Pages and a Forgotten Hosts Entry
- URL: https://blog.sudowl.com/xenforo-server-move-empty-pages-hosts-file-letsencrypt/
- Published: 2026-11-26T15:00:00.000Z
- Updated: 2026-12-04T12:22:14.000Z
- Description: Moving a XenForo forum to a KeyHelp box: pre-run, --final sync, why skipping code_cache gives empty 200 pages, and how /etc/hosts broke Let's Encrypt.
- Author: Lukas
- Tags: Linux

A community forum I run sat on an old server that I wanted gone for weeks. The day before this move, the hosting provider blocked that box's IP after an abuse report and the forum was simply offline. I never found out what triggered the report. The IP came back, but that settled it. The forum moved the next day.

The target was my new server with KeyHelp. I had already built a full test copy there earlier ([test copy first, then DNS](/server-migration-test-copy-before-dns/)), so this was the real cutover. It worked, but two things bit me, and both were my own fault.

**TL;DR:** One sync script on the new box, run twice. Pre-run: the old board stays live, the new board stays closed. `--final` after the DNS flip: close the old board, last sync, open the new board, move the crons. Gotcha 1: I excluded `internal_data/code_cache` from rsync and XenForo answered every page with HTTP 200 and an empty body. Gotcha 2: a leftover `/etc/hosts` test entry on the new server pointed the forum's domain at the old IP, so KeyHelp's local Let's Encrypt pre-check hit the old box, got a 404, and the apex domain served the panel's certificate for a while. Afterwards: compare row counts old vs new, and check that forum mail leaves the new box DKIM-signed.

## The sync script

It runs on the new server and only reads from the old one. Same idea as before: pull with `ssh -A`, never push from the old box.

```bash
#!/bin/bash
# runs on the NEW box, pulls from the old one
#   ./forum-sync.sh          pre-run: old board stays live, new board stays closed
#   ./forum-sync.sh --final  after the DNS flip
set -euo pipefail
OLD=root@203.0.113.10
FINAL=0; [[ "${1:-}" == --final ]] && FINAL=1

xfopt() {  # xfopt <php-binary> <xf-root> <0|1>  -> set boardActive
  "$1" -r 'require $argv[1]."/src/XF.php"; XF::start($argv[1]);
    $o=XF::em()->find("XF:Option","boardActive");
    $o->option_value=(int)$argv[2]; $o->save();
    echo "boardActive=",$argv[2],"\n";' "$2" "$3"
}

if (( FINAL )); then
  # close the OLD board first, so nobody writes there anymore
  ssh $OLD "php -r '...same boardActive=0 snippet...'"
fi

ssh $OLD "mysqldump --single-transaction --quick xf_db | gzip" > /root/in/db/xf_db.sql.gz

rsync -aH --delete --exclude 'internal_data/temp/' \
  --exclude 'src/config.php' \
  $OLD:/var/www/vhosts/forum.example.com/httpdocs/ "$XF_ROOT/"

# import dump, chown to the KeyHelp user, then:
xfopt "$PHP" "$XF_ROOT" "$FINAL"   # pre-run: closed, final: open

```

`src/config.php` stays out because the new box has its own database credentials. The board switch goes through XenForo's own entity manager instead of a raw SQL update on `xf_option`, so XenForo handles the option and its cache itself. In the final run the script also switches the forum crons off on the old box and on on the new one: the nightly DB dump, a stats job, the generated `llms.txt` and a small status script.

The pre-run pulled a 3.8 MB compressed dump plus the webroot. Then the script curls a few URLs against the new box:

```text
503  https://forum.example.com/
301  https://www.forum.example.com/
503  https://forum.example.com/pages/wiki/
503  https://forum.example.com/threads/44/

```

503 is correct here. A closed XenForo board answers 503 to guests. To actually test, I opened the board for a moment, curled, and closed it again.

## Gotcha: HTTP 200 with an empty body

Every page came back 200\. Every page had zero bytes.

```text
HTTP/2 200
x-xf-debug-stats: {"time":0.0399,"queries":13,"memory":2.44}
content-length: 0
content-type: text/html; charset=utf-8
server: Apache

```

No PHP error, 13 queries ran. XenForo started and rendered nothing.

The cause was in my first version of the rsync line:

```bash
rsync -aH --delete --exclude 'internal_data/code_cache/' --exclude 'internal_data/temp/' ...

```

I skipped `code_cache` on purpose because "cache" sounded like something that rebuilds itself. In XenForo it holds the compiled templates, phrases and navigation. Without it, there is nothing to render. The fix is to drop that exclude and keep only `temp`:

```bash
# code_cache (compiled templates) MUST come along, XF renders empty pages without it
rsync -aH --delete --exclude 'internal_data/temp/' \
  --exclude 'src/config.php' "$IN/files/forum-httpdocs/" "$XF_ROOT/"

```

Second sync, board open for a moment, and the pages had real bodies: 85,497 bytes for the start page, 123,829 for the biggest thread, 57,455 for the wiki page. Lesson: `200` in your test loop means nothing. Check the size or grep for the `<title>`.

## The DNS flip and the final run

I changed DNS with a small script against my registrar's API. Dry run first, then the real run. It moved 6 A records (apex, www, mail, webmail and their www variants) from the old IP to the new one and replaced SPF and DKIM with the new box's values. MX, DMARC and a verification TXT record stayed as they were. Why you want a short TTL for this step: [lower your DNS TTL first](/lower-dns-ttl-before-migration/).

Then right away:

```bash
./forum-sync.sh --final

```

Old board closed, final dump and rsync, import, new board open, old crons off. The test lines flipped from 503 to 200\. Next was Let's Encrypt in KeyHelp for the apex and www.

## Gotcha: a hosts entry from testing broke Let's Encrypt

www got its certificate. The apex didn't. Worse, from outside the apex now served the panel's own hostname certificate, and my Windows curl said:

```text
schannel: SNI or certificate check failed: SEC_E_WRONG_PRINCIPAL (0x80090322)
- The target principal name is incorrect.

```

Before Let's Encrypt validates anything, KeyHelp drops a token into the webroot and fetches it locally over HTTP. That local check failed:

```text
URL: http://forum.example.com/.well-known/acme-challenge/local-check-... | HTTP code: 404
ERROR | Apache: a Let's Encrypt error occurred: Local resolving checks failed for
domain "forum.example.com". Please ensure that your domain is locally resolvable!

```

A 404 means it reached a web server, just not this one. So: what does the new server think the domain resolves to?

```bash
getent hosts forum.example.com
# 203.0.113.10  forum.example.com   <- the OLD box
grep forum.example.com /etc/hosts
# 203.0.113.10  forum.example.com

```

At some point during testing I had pinned the domain to the old IP in the new server's `/etc/hosts`. I never took it out. Public DNS was right, but the server itself still went to the old box for its own domain, and the old box naturally didn't have KeyHelp's token. In my test-copy post I even warned that a forgotten hosts entry (on the laptop, back then) costs you an hour after the switch. Then I left one on the server.

Fix, in this order:

```bash
cp /etc/hosts /etc/hosts.bak-$(date +%F)
sed -i '/forum\.example\.com/d' /etc/hosts
getent hosts forum.example.com     # must now show the NEW IP

```

To stop the wrong-certificate problem while Let's Encrypt was retried, I assigned the old Let's Encrypt cert from the old box (imported earlier for testing, still valid for weeks) to the apex in KeyHelp. Re-triggering LE flipped the apex back to the panel cert once more, so I assigned the old one again and did the third attempt with an automatic fallback to it in case it failed. It went through.

Then check that the served cert and the key on disk belong together:

```bash
d=/etc/ssl/keyhelp/letsencrypt/<user>/forum.example.com
openssl x509 -noout -modulus -in $d/cert.pem    | md5sum | cut -c1-8
openssl rsa  -noout -modulus -in $d/private.pem | md5sum | cut -c1-8
echo | openssl s_client -connect forum.example.com:443 -servername forum.example.com 2>/dev/null \
  | openssl x509 -noout -subject -enddate

```

Same hash for cert and key, the right subject served from outside. All in all the apex showed a wrong certificate twice, about 20 minutes together. If something goes wrong with KeyHelp's certificate jobs, also read about [the time two cert jobs took Apache down](/keyhelp-letsencrypt-race-apache-down/). And if the local check fails without a hosts entry, [check for a duplicate A record](/lets-encrypt-fails-duplicate-a-record/).

My new rule: `getent hosts <domain>` on the server itself before every Let's Encrypt switch.

## Did all the data make it?

The board on the old box was closed before the final dump, so nothing could be written after it. I still compared both databases with the same query:

```sql
SELECT (SELECT MAX(post_id) FROM xf_post),
       (SELECT COUNT(*) FROM xf_post),
       (SELECT MAX(thread_id) FROM xf_thread),
       (SELECT MAX(user_id) FROM xf_user),
       (SELECT COUNT(*) FROM xf_attachment),
       (SELECT MAX(conversation_id) FROM xf_conversation_master),
       (SELECT FROM_UNIXTIME(MAX(post_date)) FROM xf_post);

```

|                                   | old      | new      |
| --------------------------------- | -------- | -------- |
| max post id / posts               | 106 / 95 | 106 / 95 |
| max thread id / max user id       | 77 / 88  | 77 / 88  |
| attachments / conversations       | 24 / 3   | 24 / 3   |
| uploaded files (attachments etc.) | 278      | 278      |

One trap: the latest post date showed 08:41 on the old box and 09:41 on the new one. Same row. `FROM_UNIXTIME` uses the session time zone, and the two servers had different ones. Compare raw IDs and counts, not formatted dates.

## Does the forum mail still work?

New box means new outgoing IP, new SPF, new DKIM key. I sent a test mail through the local Postfix and checked the logs:

```text
postfix/smtp: ... to=<me@example.com>, relay=127.0.0.1[127.0.0.1]:10027, status=sent
postfix/smtp: ... relay=<receiver's MX>:25, dsn=2.0.0, status=sent (250 2.0.0 OK ...)
rspamd: ... DKIM_SIGNED(0.00){forum.example.com:s=default;}

```

Accepted by the receiving side and signed with the new key. Whether it landed in the inbox or in spam I can't see from the server, so that part still needs a look in a real mailbox. The DNS side of this is in [new mail domain: SPF, DKIM, DMARC from zero](/new-mail-domain-spf-dkim-dmarc-from-zero/).

One thing I didn't touch: `$config['debug'] = true` was already set on the old box and came along. That's on my list, but changing config during a cutover is how you get a third gotcha.

The same afternoon I made the final backup of the old server and deleted it. That's the next post, including the DNS records I almost left dangling.

---

### Related posts

- [Lower Your DNS TTL Before You Migrate a Server (A Checklist)](https://blog.sudowl.com/lower-dns-ttl-before-migration/)
- [Reskinning Ghost's Source Theme with Nothing but Code Injection](https://blog.sudowl.com/ghost-source-theme-code-injection-css/)
- [Serving a Static SPA on Apache: .htaccess Fallback, Caching, and the Container Nobody Used](https://blog.sudowl.com/static-spa-apache-htaccess-fallback/)