keepcalculator

06 Numbers and Powers

WordPress W3 Total Cache on Lighttpd Setup

Card No. 06·71924 · Updated · Standard formula, shown below

Setting up WordPress with W3 Total Cache on a Lighttpd web server can significantly improve your site’s performance by enabling page caching, browser caching, and minification. This guide walks you through the configuration steps, from installing the plugin to creating the necessary rewrite rules for Lighttpd. You’ll need root or sudo access to your server, and basic familiarity with the command line.

What You’ll Need

  • A WordPress site running on Lighttpd (version 1.4.x or later).
  • SSH (Secure Shell) access to your server with sudo privileges.
  • Text editor (e.g., nano, vim) for editing configuration files.
  • W3 Total Cache plugin (free version is sufficient).

Step-by-Step

  1. Install and activate W3 Total Cache – In your WordPress admin dashboard, go to Plugins → Add New, search for “W3 Total Cache”, install, and activate it. After activation, you’ll see a notice to set up the plugin.
  2. Enable page cache – Navigate to Performance → General Settings. Under Page Cache, check the Enable box and select Disk: Basic as the method. This stores cached pages as static files on your server.
  3. Enable browser cache – In the same General Settings page, scroll to Browser Cache and check the Enable box. This adds cache-control headers to static assets like images, CSS, and JavaScript.
  4. Enable minify (optional) – If you want to minify HTML, CSS, and JS, check the Enable box under Minify. Choose Disk as the method. Be careful with this step; test your site after enabling.
  5. Save settings – Click the Save Settings button at the bottom of the page. W3 Total Cache will now create the necessary cache directories (usually under wp-content/cache).
  6. Edit Lighttpd configuration – Open your Lighttpd configuration file (typically /etc/lighttpd/lighttpd.conf or a file in /etc/lighttpd/conf.d/) with sudo. You’ll need to add rewrite rules to serve cached files and set proper headers.
  7. Add rewrite rules for page cache – Insert the following block inside the server.modules section (ensure mod_rewrite is enabled). This tells Lighttpd to serve the cached HTML file if it exists:
    url.rewrite-if-not-file = (
      "^/[^?]*\.(?:php|html)$" => "/wp-content/cache/page_enhanced/$0/_index.html",
      "^/[^?]*/?$" => "/wp-content/cache/page_enhanced/$0/_index.html"
    )
        

    Note: The exact path may vary if you changed the cache location. For most setups, this works.

  8. Add browser caching headers – In the same config file, add a block to set cache headers for static files. You can place this inside an $HTTP["url"] condition:
    $HTTP["url"] =~ "\.(css|js|jpg|jpeg|png|gif|ico|svg|woff|woff2)$" {
      expire.url = ( "" => "access plus 30 days" )
      add-header = ( "Cache-Control" => "public, max-age=2592000" )
    }
        

    Adjust the expiration time as needed.

  9. Enable mod_expire and mod_setenv – Ensure that mod_expire and mod_setenv are included in server.modules at the top of the config. If not, add them.
  10. Test and restart Lighttpd – Run sudo lighttpd -t -f /etc/lighttpd/lighttpd.conf to test the configuration for syntax errors. If it passes, restart Lighttpd with sudo systemctl restart lighttpd (or sudo service lighttpd restart on older systems).
  11. Verify caching works – Visit your site in a browser. View the page source and look for a comment like <!-- Page Cached by W3 Total Cache -->. Also check the response headers for X-Cache-Engine: disk or similar.
  12. Configure W3 Total Cache for Lighttpd – In the W3 Total Cache settings, go to Performance → General Settings and scroll to Advanced. Under Rewrite Rules, you may see a note that Lighttpd is detected. If not, you can manually add the rules as above. Also, under Page Cache → Advanced, ensure the cache file permissions are writable.

Common Mistakes

  • Incorrect cache path – The rewrite rule uses the absolute path from the web root. If your WordPress is in a subdirectory, adjust the rule accordingly (e.g., /blog/wp-content/cache/...).
  • Forgetting to enable mod_rewrite – Without it, the rewrite rules won’t work. Check your Lighttpd modules list.
  • Not restarting Lighttpd – Configuration changes won’t take effect until you restart the service.
  • Minify conflicts – Enabling minify without testing can break your site’s CSS/JS. Always test after enabling, and if issues occur, disable minify or exclude problematic files.
  • Cache not purging – When you update posts or pages, W3 Total Cache should purge the cache automatically. If not, check that the file permissions allow deletion and that the wp-content/cache directory is writable.

Tips

  • Use a staging site – Test the configuration on a staging copy of your site to avoid downtime.
  • Monitor disk space – Page caching creates many files. Ensure you have enough disk space, especially on high-traffic sites.
  • Combine with a CDN – W3 Total Cache supports CDN integration for static assets, which can further reduce server load.
  • Set proper file permissions – The cache directory should be owned by the web server user (e.g., www-data). Use chown -R www-data:www-data wp-content/cache if needed.
  • Keep W3 Total Cache updated – Regular updates fix bugs and improve compatibility with new WordPress versions.

Troubleshooting

  • Site shows 404 errors – This usually means the rewrite rule is incorrect. Double-check the path to the cache directory. You can find it by looking at the wp-content/cache/page_enhanced/ folder structure. The rule should end with _index.html.
  • Cache not being created – If no cache files appear in wp-content/cache, check that the directory is writable and that W3 Total Cache is enabled. Also, ensure the mod_rewrite is not blocking requests.
  • Headers not showing – If browser caching headers aren’t present, verify that mod_expire is enabled and that the $HTTP["url"] condition matches your file extensions.
  • Minify breaks layout – Disable minify for CSS/JS individually to isolate the issue. Sometimes, a specific file causes problems; exclude it via the minify settings.
  • Logs show errors – Check Lighttpd error logs (/var/log/lighttpd/error.log) for rewrite or permission errors. Common fixes include adjusting the rewrite regex or changing file ownership.

Frequently Asked Questions

Do I need to modify .htaccess?

No, Lighttpd does not use .htaccess. All configuration is done in the server config file.

Can I use W3 Total Cache with Nginx instead?

Yes, but the rewrite rules differ. This guide is specific to Lighttpd.

Will this work with WordPress Multisite?

Yes, but you may need to adjust the rewrite rules to account for subdirectory or subdomain installations.

How do I clear the cache manually?

In the WordPress admin, go to Performance → Dashboard and click Empty Caches. Alternatively, delete the contents of wp-content/cache via FTP or SSH.

Is it safe to enable all caching options?

Not necessarily. Page and browser caching are safe, but minify can cause issues with some themes/plugins. Test each option individually.

Why is my cached page showing old content?

This is likely due to browser cache. Clear your browser cache or use a cache-busting query string. Also, ensure W3 Total Cache is set to purge on post updates.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →