Installing WP Super Cache on Platform.sh
I plan on writing a more thorough guide on WordPress caching plugins on Platform.sh / Upsun on the DevCenter but I needed to write up a quick guide earlier this week for WP Super Cache. Until I can complete the more thorough guide, I thought I would go ahead and share this guide in case someone can use it.
While both Platform.sh and Upsun offer caching at the router, it's fairly simplistic, with no options. It's a great option if the site doesn't receive many changes, but if you need more flexibility, you'll most likely need something else.
There are numerous WordPress caching options. This guide is for running WP Super Cache, but most WordPress caching options will have similar setup requirements, and restrictions.
Assumptions:
- You already have a working site deployed on Platform.sh / Upsun
- Your public/root directory is named `wordpress`
- Your wp-content directory is located at `wordpress/wp-content`
- You're using a Composer-based management for your WordPress site
If any of the assumptions don't match up with your situation, you'll need to make adjustments.
- Install the WP Super Cache plugin
composer require "wpackagist-plugin/wp-super-cache" “^2.0.0” - In your wp-config.php file, add the following (near the bottom)
define('WPCACHECONFIGPATH',getenv('PLATFORM_APP_DIR').'/wordpress/wp-content/cache');define('WP_CACHE', getenv('WP_CACHE') ?? true);define('WPCACHEHOME',getenv('PLATFORM_APP_DIR').'/wordpress/wp-content/plugins/wp-super-cache/'); -
In your Platform.sh (
.platform.app.yaml) or Upsun (.upsun/config.yaml) configuration file, add a mount:mounts:“wordpress/wp-content/cache”:source: storagesource_path: “cache”
Note: on Platform.shsourceshould belocal - Every caching plugin will contain an
advanced-cache.phpfile. This file needs to be placed into the root of yourwp-contentdirectory. You can choose to either copy (cp) the file from the plugin's directory into wp-content during the build hook, or create a symlink between the two. In your Platform.sh (.platform.app.yaml) or Upsun (.upsun/config.yaml) configuration file, add the following to your build hook to create a symlink:ln -s -f "${PLATFORM_APP_DIR}/wordpress/wp-content/plugins/wp-super-cache/advanced-cache.php" "${PLATFORM_APP_DIR}/wordpress/wp-content/advanced-cache.php" -
git addandgit committhe changed files, push the changes - After the changes have deployed, log into the site's WordPress Admin console
- Enable the WP Super Cache plugins in the plugin panel
- Go to the settings page for WP Super Cache
- Go to the Advanced tab in the WP Super Cache settings page
Note: it may show an error about not being able to write. Ignore the error for now - Scroll down the page to Cache Location
- Change the cache location to a subdirectory of the currently listed location (ie
/app/wordpress/wp-content/cache/→/app/wordpress/wp-content/cache/cached/)
WP Super Cache needs to be able to write to the cache location and be able to write to its parent location. This is why we need to make the cache location a subdirectory of the mount we created in step 3. - Scroll down and click the Update Status button just beneath the Notes section
- Now you can enable caching in the Advanced tab.
WP Super Cache will now generate cached versions of your content inside the /app/wordpress/wp-content/cache/cached/ location. When visitor visit a cached location, WP Super Cache will intercept the request and serve the cached version instead of allowing WordPress to regenerate the page. You can verify if WP Super Cache is working by looking at the source of the page, and scroll all the way down to the bottom. There will be two comments at the end indicating the page was served from Super Cache and the timestamp the cache was generated.
Hope this helps someone. Be on the lookout for the more thorough guide here in the coming weeks!
Comments
Please sign in to leave a comment.