NewCode CLOUD — 20% off your first month on all cloud VPSClaim

WordPress Speed Optimization on Your Own Server: Caching, Redis, PHP and Images

A slow WordPress site loses visitors and search rankings. On your own server you can go far beyond what a caching plugin alone can do: cache pages in Nginx, keep database results in Redis, tune PHP and the database, and fix the front end. This guide works through the changes in order of impact, so you can stop when the site is fast enough.

Measure first

Without numbers you cannot tell whether a change helped.

  • Server response time (TTFB):
curl -o /dev/null -s -w "TTFB: %{time_starttransfer}s  Total: %{time_total}s\n" https://example.com/

Run it several times. Uncached WordPress pages often take 0.3–1.5 s to generate; a cached page should take well under 0.1 s plus network latency.

  • Full page load: PageSpeed Insights, WebPageTest or your browser’s Lighthouse. These show Core Web Vitals (LCP, CLS, INP) that search engines use.
  • What WordPress is doing: the free Query Monitor plugin shows slow database queries, hooks and which plugins are slow. Use it on a staging copy or briefly in production.

1. Full-page caching (biggest win)

Most visitors are not logged in and see the same page. Generating it once and serving the stored HTML avoids PHP and database work entirely.

Option A: a caching plugin

Plugins such as WP Super Cache, W3 Total Cache, or LiteSpeed Cache (on LiteSpeed servers) write static HTML files. Simple, and good enough for most sites.

Option B: Nginx FastCGI cache

Nginx caches PHP responses itself — very fast, no PHP involved for cached hits. In the http block (/etc/nginx/conf.d/fastcgi-cache.conf):

fastcgi_cache_path /var/cache/nginx/wp levels=1:2 keys_zone=WP:100m inactive=60m max_size=1g;
fastcgi_cache_key "$scheme$request_method$host$request_uri";

In the WordPress server block:

set $skip_cache 0;
if ($request_method = POST) { set $skip_cache 1; }
if ($query_string != "") { set $skip_cache 1; }
if ($request_uri ~* "/wp-admin/|/wp-json/|/xmlrpc.php|wp-.*\.php|/feed/|sitemap|/cart/|/checkout/|/my-account/") { set $skip_cache 1; }
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in|woocommerce_items_in_cart|woocommerce_cart_hash") { set $skip_cache 1; }

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php8.3-fpm.sock;
    fastcgi_cache WP;
    fastcgi_cache_valid 200 301 302 60m;
    fastcgi_cache_bypass $skip_cache;
    fastcgi_no_cache $skip_cache;
    add_header X-Cache $upstream_cache_status;
}

Check with curl -I https://example.com/ — the X-Cache header shows MISS on the first request and HIT afterwards. Use a plugin such as Nginx Helper to purge the cache when you publish or edit posts.

WooCommerce and membership sites: never cache cart, checkout, account pages or logged-in users — the skip rules above handle the common cases.

2. Redis object cache

WordPress repeats many identical database queries on every request (options, menus, widgets). A persistent object cache keeps the results in memory. This helps most for logged-in users, WooCommerce and admin pages — exactly the requests full-page caching cannot serve.

sudo apt install redis-server php-redis
sudo systemctl enable --now redis-server
sudo systemctl restart php8.3-fpm

Then install the Redis Object Cache plugin and enable it, or with WP-CLI:

wp plugin install redis-cache --activate
wp redis enable
wp redis status

If several sites share one Redis, give each a unique prefix in wp-config.php:

define('WP_CACHE_KEY_SALT', 'example.com:');

Keep Redis bound to 127.0.0.1 (the default) — never expose it to the internet.

3. PHP: version, OPcache, workers

  • Use a current PHP version (8.2 or 8.3). Each major release has been noticeably faster than PHP 7.x.
  • OPcache keeps compiled PHP in memory. Make sure it is on and large enough:
opcache.enable = 1
opcache.memory_consumption = 256
opcache.interned_strings_buffer = 16
opcache.max_accelerated_files = 20000
opcache.revalidate_freq = 60

4. Database

Over time WordPress databases fill with revisions, expired transients and spam.

wp post delete $(wp post list --post_type=revision --format=ids) --force   # if there are many revisions
wp transient delete --expired
wp comment delete $(wp comment list --status=spam --format=ids) --force

Limit future revisions in wp-config.php (WP_POST_REVISIONS 10).

Check autoloaded options — data loaded on every single request:

wp db query "SELECT SUM(LENGTH(option_value))/1024 AS autoload_kb FROM $(wp db prefix)options WHERE autoload IN ('yes','on');"

More than ~1 MB usually means a plugin is storing large data with autoload on. Find the largest entries and deal with the plugin responsible.

For MariaDB itself, the most important setting is the InnoDB buffer pool — see MariaDB tuning.

5. Plugins and theme

The most common cause of a slow WordPress site is not the server but too many or poorly written plugins, and heavy page-builder themes. With Query Monitor:

  • Deactivate plugins one by one on a staging site and measure.
  • Replace plugins that run expensive queries on every page.
  • Prefer a lightweight theme; page builders add a lot of CSS and JavaScript.

6. Images

Images are usually the largest part of a page.

  • Upload images at the size they are displayed, not 5000-pixel camera originals.
  • Serve WebP or AVIF (WordPress supports both; an optimisation plugin can convert existing images).
  • Lazy-loading is built into WordPress for images below the fold; make sure the main above-the-fold image is not lazy-loaded, as that hurts LCP.
  • Set width and height attributes to avoid layout shift (CLS).

7. Front end

  • Enable gzip or Brotli and long browser caching for static files — see Nginx compression and caching.
  • Enable HTTP/2 in Nginx (http2 on; or listen 443 ssl http2;).
  • Defer non-critical JavaScript; remove scripts you do not need (sliders, unused widgets).
  • Self-host fonts. For visitors in mainland China this is essential — Google Fonts can block rendering there. See speeding up a website for China.

8. Server location and network

Caching makes the server fast; the network decides how quickly the response reaches visitors. Host close to your audience: Hong Kong for mainland China and Southeast Asia, Japan for Japan and Korea, the US for the Americas — and on a China-optimised route if Chinese visitors matter. Enable BBR for long-distance visitors.

Typical results

Change Typical effect on uncached TTFB / load
Full-page cache 0.5–1.5 s → well under 0.1 s for anonymous visitors
Redis object cache Faster admin, WooCommerce and logged-in pages
PHP 7.4 → 8.3 + OPcache Noticeably faster page generation
Image optimisation Often halves page weight
Removing a heavy plugin Varies — sometimes the biggest single win

Checklist

  • Baseline measured (TTFB, Lighthouse)
  • Full-page cache with correct exclusions
  • Redis object cache enabled
  • PHP 8.2+, OPcache tuned, FPM workers sized to RAM
  • Database cleaned, autoload checked
  • Images resized and in WebP/AVIF
  • Compression, HTTP/2, browser caching
  • Re-measured after each change