Skip to content

Instantly share code, notes, and snippets.

@wturnerharris
Last active May 21, 2021 18:48
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save wturnerharris/257a2cb586efd9072f49 to your computer and use it in GitHub Desktop.
Save wturnerharris/257a2cb586efd9072f49 to your computer and use it in GitHub Desktop.
Install procedures to enable W3TC as a WordPress MU (must-use) plugin.

###W3TC MU-Plugins Install

  1. ####Add Apache Rewrite Rule -> .htaccess:

    • RewriteRule ^wp-content/plugins/w3-total-cache(/.*|)$ /wp-content/mu-plugins/w3-total-cache$1 [L,NC]
  2. ####Add WP-Config Option -> wp-config.php:

    • define('W3TC_DIR', dirname(FILE).'/wp-content/mu-plugins/w3-total-cache');
  3. ####Add w3tc plugin -> mu-plugins/:

    • Upload entire plugin to mu-plugins/w3-total-cache/
  4. ####Add mu-plugin wrapper file -> mu-plugins/w3-total-cache.php

    • <?php require WPMU_PLUGIN_DIR.'/w3-total-cache/w3-total-cache.php';
@wturnerharris
Copy link
Author

Some notes on the above.

  • The apache rewrite makes the wp-admin side pretty and redirects all assets for js/css to the mu-plugins url.
  • The wp-config.php constant simply ensures all php scripts for W3TC point to the mu-plugins path.
  • The latter two edits simply make the plugin must-use in WP so that it is always on, and cannot be updated automatically.

@wturnerharris
Copy link
Author

The most important config to setup is to enable all caching modes—page caching, browser cache and db caching.

@jazbek
Copy link

jazbek commented Mar 20, 2015

@wturnerharris These notes were fantastically helpful and saved me a lot of time, thanks!

Are you still using w3tc in the mu-plugins context? The problem I'm running into now is that the activation hook doesn't run when the plugin is in mu-plugins, so for new sites, the wp_x_w3tc_cdn_queue table doesn't get created. I'm working on a solution, but just thought I'd check if you'd also run into this.

@jazbek
Copy link

jazbek commented Mar 20, 2015

Also for whoever it helps, I have forked this gist and updated the rewrite rule for nginx as opposed to apache.

@g000m
Copy link

g000m commented May 21, 2021

I also had to set another constant:

define( 'W3TC_EXTENSION_DIR', WP_CONTENT_DIR' . '/mu-plugins' );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment