Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

How to Fix a Slow WordPress Site on a LEMP Server

· 4 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

If your WordPress site on a LEMP (Linux, Nginx, MySQL/MariaDB, PHP) server is loading slowly, this guide walks you through the most common causes and their fixes. You'll learn how to diagnose performance bottlenecks, apply caching, optimize your database, and fine-tune server settings—all without needing to be a sysadmin expert.

What You'll Need

  • SSH access to your server (root or sudo privileges).
  • WordPress admin credentials.
  • Basic comfort with the command line.

Step-by-Step

  1. Measure your current speed. Use a tool like GTmetrix or Pingdom to get a baseline. Note the page load time, total page size, and number of requests. This helps you track improvement.
  2. Check server resource usage. Run htop or top to see CPU and memory usage. If the server is constantly at 100% CPU or swapping memory, you may need to optimize or upgrade.
  3. Enable page caching. Install a caching plugin like WP Super Cache or W3 Total Cache. For LEMP, the best option is often to use Nginx FastCGI cache. Add this to your Nginx server block:
    fastcgi_cache_path /var/run/nginx-cache levels=1:2 keys_zone=WORDPRESS:100m inactive=60m;
    fastcgi_cache_key "$scheme$request_method$host$request_uri";
    Then in the location ~ \.php$ block, add:
    fastcgi_cache WORDPRESS;
    fastcgi_cache_valid 200 60m;
    Reload Nginx with sudo systemctl reload nginx.
  4. Enable browser caching. Add expires headers for static assets (images, CSS, JS) in your Nginx config:
    location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
        expires 30d;
        add_header Cache-Control "public, immutable";
    }
  5. Optimize images. Use a plugin like Smush or ShortPixel to compress images without losing quality. Also consider using WebP format.
  6. Minify CSS and JavaScript. Use a plugin like Autoptimize or the built-in features of W3 Total Cache. This reduces the number of requests and file sizes.
  7. Optimize the database. Install and run WP-Optimize or use phpMyAdmin to run OPTIMIZE TABLE on all tables. Also clean up post revisions, spam comments, and transient options.
  8. Use a CDN. Services like Cloudflare or StackPath can serve static files from edge locations, reducing server load and latency.
  9. Check PHP settings. Ensure PHP-FPM is configured with enough workers. In /etc/php/7.4/fpm/pool.d/www.conf, adjust pm.max_children based on your server memory. A good rule: max_children = (RAM - 1GB) / 200MB for typical WordPress sites.
  10. Enable OpCache. In php.ini, set opcache.enable=1 and opcache.memory_consumption=128. This caches compiled PHP scripts.
  11. Check for slow plugins. Use a plugin like Query Monitor to identify which plugins are causing slow queries. Deactivate and delete any that are not essential.
  12. Review Nginx configuration. Ensure keepalive_timeout is set to 15-30 seconds, and gzip is enabled for text-based files.
  13. Update everything. Keep WordPress core, themes, and plugins up to date. Outdated software can have performance issues and security vulnerabilities.

Common Mistakes

  • Over-caching. Caching everything can cause stale content or broken dynamic features. Exclude pages like cart, checkout, and login.
  • Ignoring server logs. Always check /var/log/nginx/error.log and /var/log/mysql/error.log for clues.
  • Using too many plugins. Each plugin adds overhead. Delete any that are not actively used.
  • Not testing after changes. Always re-run speed tests after each optimization to see what actually helped.

Tips

  • Use a lightweight theme like GeneratePress or Astra instead of heavy page builders.
  • Keep your WordPress installation on an SSD for faster disk I/O.
  • Consider using a managed WordPress host if you don't want to handle server maintenance.
  • Schedule regular database cleanups with WP-Cron or a server cron job.

Troubleshooting

If your site becomes completely inaccessible after making changes, revert the last change. For Nginx config errors, run sudo nginx -t to test the configuration before reloading. If you get a 502 Bad Gateway, it usually means PHP-FPM is down—restart it with sudo systemctl restart php7.4-fpm. If the site is still slow, check if the issue is on the server side by running curl -w "@time_total\n" -o /dev/null http://yoursite.com from the server. If it's fast locally but slow externally, it might be network latency or a CDN issue.

Frequently Asked Questions

Why is my WordPress site slow even with caching?

Caching helps with page load time, but if your database queries are inefficient or your server is underpowered, you may still see slowness. Check your server logs and use Query Monitor to find bottlenecks.

Should I use a plugin or Nginx caching?

For best performance, use Nginx FastCGI cache. It's faster than PHP-based plugins because it serves cached pages before PHP even runs. Plugins are easier to configure but add overhead.

How do I know if my server is the problem?

If your server's CPU or memory usage is consistently high during normal traffic, it's likely underpowered. Use htop to monitor. If you have plenty of resources, the issue is likely in your WordPress configuration.

What is the best caching plugin for LEMP?

WP Super Cache is simple and reliable. W3 Total Cache offers more options but can be complex. For LEMP, Nginx FastCGI cache is often the best choice.

How often should I optimize my database?

Once a week is a good baseline. Use a plugin to schedule automatic cleanups of revisions, spam, and transient options.

Will a CDN really help?

Yes, if your audience is global. A CDN reduces latency by serving static files from a server close to the visitor. It also offloads traffic from your origin server.