Skip to content

Gondew Life

AI·ML 개발, 맥 생산성, 웹 디자인 기록

Menu
  • English
  • 한국어
  • about
  • Contact
  • Privacy
Menu

Migrating WordPress from PHP 7.4 to 8.4: Fixing Fatal sprintf() Bugs & Cutting Mobile LCP from 4.3s to 0.8s

Dec 3, 20262026년 12월 04일
이 글은 한국어로도 읽을 수 있습니다.한국어 버전으로 읽기 →
Key Takeaways (TL;DR): Upgrading a legacy WordPress site from PHP 7.4 to PHP 8.4 requires three safeguards before touching the server: zero-server-disk SSH streaming backups, auditing child themes for strict PHP 8 sprintf() / ArgumentCountError crashes on percent-encoded URLs, and verifying .htaccess permissions for Let’s Encrypt SSL renewal. Combining PHP 8.4 with image resizing (1600px), REST API loopback fixes, and Jetpack Boost CSS/JS deferral cut our real-world Mobile LCP from 4.3s–5.6s down to 0.8s and Desktop TBT from 310ms to 20ms.

Running an older WordPress blog on a small managed hosting plan eventually hits three walls at once: an end-of-life PHP 7.4 runtime, a nearly full 500MB disk quota, and sluggish Core Web Vitals on mobile. This engineering walkthrough documents an actual production migration from PHP 7.4.33 / WordPress 6.6.11 to PHP 8.4.28 / WordPress 7.1.5, including the hidden theme crash we caught before cutover and the exact steps that cut Mobile LCP by more than 80%.

1. Before vs. After Production Metrics

MetricBefore MigrationAfter Migration (Verified)
PHP / DatabasePHP 7.4.33 / MariaDB 10.xPHP 8.4.28 / MariaDB 10.6.17
WordPress Core6.6.117.1.5
Web Disk Usage463 MB / 500 MB (92%)~290 MB / 500 MB (Healthy)
Mobile LCP (PageSpeed Insights)4.3s – 5.6s (Poor)0.8s (Good)
Desktop TBT (PageSpeed Insights)310 ms (Needs Improvement)20 ms (Good)

2. Streaming Zero-Disk Backups Over SSH When Disk Is 92% Full

Many managed WordPress hosts (such as Cafe24 Managed WordPress) provision a brand-new server environment when switching from PHP 7.x to PHP 8.x, wiping all web files, databases, and automatic backups. If your server only has 30–40 MB free, running a server-side tar or backup plugin will fail with a disk-full error.

Instead, stream both mysqldump and tar directly to your local machine over an SSH ControlMaster socket—using zero bytes of extra disk space on the remote server:

# 1) Open a reusable SSH ControlMaster session (authenticate once)
ssh -MNf -o ControlPath=~/.ssh/cm-wp.sock USER@HOST

# 2) Stream MariaDB/MySQL dump directly to local gzip file
ssh -S ~/.ssh/cm-wp.sock USER@HOST \
  'mysqldump --single-transaction --quick --default-character-set=utf8mb4 -u DB_USER -p DB_NAME | gzip -c' \
  > ./db_backup.sql.gz

# 3) Stream the full web root without creating temp files on the host
ssh -S ~/.ssh/cm-wp.sock USER@HOST \
  'tar czf - -C /home/hosting_users/USER www' \
  > ./www_backup.tar.gz

# 4) Verify integrity locally before resetting the server
gzip -t ./db_backup.sql.gz && tar tzf ./www_backup.tar.gz | wc -l

3. The Hidden PHP 8.4 Killer: sprintf() on Non-ASCII Permalinks

Before switching to PHP 8.4, always audit custom child theme files (functions.php) for legacy PHP 7 patterns. In our child theme, a seemingly harmless helper function was silently failing on PHP 7.4 and would have crashed every non-ASCII post with an HTTP 500 error on PHP 8:

// Broken legacy child theme code
$posted_on = sprintf(
    '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
);

When a permalink contains URL-encoded multibyte characters (such as Korean or Japanese slugs like %EC%9D%B8%ED%8A%9C...), passing the concatenated string as the first argument to sprintf() makes PHP interpret %E and %C as format specifiers:

  • On PHP 7.4: sprintf() emitted a silent warning and returned an empty string, making post dates vanish on every non-English post while English posts rendered normally.
  • On PHP 8.x: Missing arguments throw a fatal Uncaught ArgumentCountError, crashing every non-ASCII post and category archive with HTTP 500.
// Fixed for PHP 8.4: direct concatenation without redundant sprintf()
$posted_on = '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>';
$byline    = '';

4. Avoiding SSL Renewal & Plugin Traps During Restore

  1. Keep the new server’s DB password and force utf8mb4: When restoring www onto a freshly provisioned PHP 8.4 host, preserve the new DB_PASSWORD from the host’s generated wp-config.php while keeping define( 'DB_CHARSET', 'utf8mb4' );.
  2. Deactivate PHP-7-bound plugins before cutover: Any plugin with a PHP 8–only update (such as older wpDiscuz builds) should be deactivated prior to backup, then updated and re-activated immediately after PHP 8.4 comes online.
  3. Unlock .htaccess for Let’s Encrypt HTTP-01: Security plugins sometimes lock .htaccess to read-only (0444) or place a .well-known rewrite rule before RewriteEngine On. Reset permissions to 0644 and place an explicit pass-through rule at the top so free SSL reissues cleanly.
# BEGIN Let's Encrypt
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^\.well-known/(.*)$ - [L]
</IfModule>
# END Let's Encrypt

5. Cutting Mobile LCP from 4.3s to 0.8s

  • Unblock REST API loopback checks: Our security plugin had Disable JSON REST API enabled, returning 401 on unauthenticated /wp-json/ calls and breaking both WordPress Site Health loopback tests and Jetpack Boost’s page-cache engine check. Keeping XML-RPC blocked while restoring REST API immediately restored page caching.
  • Shrink oversized originals and delete bloat: Removing leftover web-root files (an old 64MB phpMyAdmin folder, unused theme zips, and inactive security plugins) plus bulk-resizing 28 oversized original photos to 1600px (JPEG quality 82) via Imsanity—then uninstalling the optimizer plugin—cut disk usage by over 170MB.
  • Defer JS, concatenate CSS/JS, and remove duplicate GA4 tags: Turning on Jetpack Boost’s Defer Non-Essential JavaScript, Concatenate CSS/JS, regenerating Critical CSS, and eliminating duplicate GA4/GTM firing brought Mobile LCP to 0.8s and Desktop LCP to 0.2s with zero console errors.

FAQ

Q. Why does WordPress keep redirecting in a slash loop (///) after switching PHP servers?

When a host migrates your domain to a new IP for PHP 8.4, local OS and browser DNS caches may still point to the detached old server until the DNS TTL (often 30 minutes) expires. Flushing local DNS cache (sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder on macOS) and restarting your browser resolves it immediately.

Q. Does WordPress 7 require PHP 8.4?

WordPress 7.x still sets PHP 7.4 as its technical minimum floor, but the official WordPress requirements recommend PHP 8.3 or greater because PHP 7.4 is past end-of-life and no longer receives security patches.

Q. Should I keep image optimizer plugins installed after bulk resizing?

If your hosting disk quota is tight (such as 500MB), you can safely deactivate and delete heavy bulk-optimization plugins after resizing existing media, since the optimized files remain permanently in wp-content/uploads.

글 탐색

← Git vs GitHub Explained: Core Differences, Essential Commands, and PR Workflows
[2026년 최신] Git Worktree로 AI 코딩 에이전트(Claude Code·Codex·Antigravity) 병렬 실행하는 실전 워크플로우 →
© 2026 Gondew Life | Powered by Minimalist Blog WordPress Theme