Skip to content

WP Packages is our new WPackagist replacement that's 17x faster and updates every 5 minutes

Acorn

Roots is an independent open source org, supported only by developers like you. We’ve been improving the WordPress developer experience since 2011, and your support keeps it independent.

Hosting Acorn on Managed WordPress Hosts

View as Markdown:

Acorn compiles Blade views and writes caches and logs to its storage directory at runtime. Most problems on managed hosts come from one of three things:

  • PHP can't write to the storage directory
  • WP-CLI and web requests use different storage directories
  • Each app server or container has its own disk

With the zero-config setup (Sage's default), the storage directory is [wp-content]/cache/acorn/, and Acorn creates it on boot if it's missing. Errors like these mean it isn't writable:

  • file_put_contents(.../framework/views/<hash>.php): Failed to open stream: Permission denied
  • mkdir(): Read-only file system
  • The .../framework/cache directory must be present and writable.

Choosing a storage path

The storage directory must be writable by PHP-FPM, shared with WP-CLI, and not publicly accessible, since compiled views are PHP files. Set it with the ACORN_STORAGE_PATH environment variable or constant. With Bedrock, add it to config/application.php:

Config::define('ACORN_STORAGE_PATH', '/path/to/writable/storage');

Without Bedrock, define() it in wp-config.php. To move only compiled views, set VIEW_COMPILED_PATH (see moving individual caches).

Avoid wp-content/uploads/ unless it's the only writable location your host offers, since it's publicly accessible.

Read-only filesystems

If the codebase is read-only after deploy, point ACORN_STORAGE_PATH at a writable directory outside the web root, or at /tmp if WP-CLI and web requests share it. /tmp is usually cleared on restarts and deploys.

You can also precompile views and their loaders with wp acorn view:cache during deploy. The file cache store and file logs still write at runtime, so point those at a writable path or use another driver. To serve precompiled views from a read-only path, publish Acorn's config/view.php and set:

'relative_hash' => true,
'check_cache_timestamps' => false,

relative_hash names compiled views after their path relative to wp-content (or the Acorn base directory when it's outside wp-content), so views compiled at a different absolute path still match. check_cache_timestamps stops Blade from recompiling when a deploy changes file modification times. With relative_hash enabled, separate WordPress installs need separate compiled view paths.

CLI and web see different files

When WP-CLI and PHP-FPM don't share a filesystem, wp acorn optimize, view:clear and optimize:clear report success without affecting what web requests read. Common causes are a private /tmp (PHP-FPM sets PrivateTmp=true on RHEL-based distributions), WP-CLI running in a separate container, and different users.

To check, clear compiled views from WP-CLI:

$ wp acorn view:clear

Load a page in your browser, then list the compiled views:

$ wp eval "print_r(glob(config('view.compiled') . '/*.php'));"

If the list is empty, WP-CLI and web requests aren't sharing the directory.

Multiple app servers

Each server or container compiles its own views, and wp acorn commands over SSH only affect the server you're connected to. Use Redis instead of the file cache store, and set LOG_CHANNEL to errorlog or stderr.

Don't deploy your local cache

Never upload your local [wp-content]/cache/acorn/ or storage/framework/ directory. Cached manifests and config contain absolute paths from your machine and cause errors like Target class [sage.view] does not exist. If you already have, delete them on the server.

Host notes

Hosts change their platforms often, so check their current documentation too.

Last updated

Sponsors

Roots is an independent open source org, supported only by developers like you. Become a sponsor.