WPEngine+Bedrock+Sage

I have put together a small script to deploy to WPEngine when you use Bedrock and Roots. WPEngine doesn’t support asset building or keeping WordPress in a different directory. The script creates a temporary branch that grabs the packages, dependencies and compiles the assets. It then moves the app folder back to wp-content and removes all other files. The .gitignore files are removed too so the compiled assets are staged. This is then pushed up to staging or production and once completed it’ll remove the branch and you’ll be back on the local working copy.

Feel free to give it a try and hopefully in the future WPE will support the Bedrock workflow.

https://github.com/schrapel/wpengine-roots-build

13 Likes

Hell yessss - can’t wait to try this - thanks for sharing.

I just changed it so rather than removing files physically it amends the gitignore and clears the git cache. Otherwise when you change back to the previous branch you would have to re-run composer, npm and bower and that’s just way too time consuming.

I’ve actually removed all the build steps and it assumes that the branch you’ve just checked out of has the latest built files.

1 Like

Thank goodness for Discourses ‘similar questions’. I mean, how epicly well marketed is Mercury! I was hoping to be able to have the best of both worlds, hopefully with this I can.

I’m really new at Vagrant, how would you set this up? Do you just add the Sage theme into the WPEngine box? As in, after vagrant uping WPEngine?

Wow I’m struggling to make sense so bad right now.

Edit oh are talking about the same thing?
http://wpengine.com/mercury

We are talking about different things. This is a script to use Bedrock to deploy to WPEngine by replacing capistrano. It doesn’t matter whether what environment you use. There is nothing stopping you using Bedrock, Sage and Mercury together but my script is not designed for that. It’s designed for going local->staging->production while still using Bedrock.

P.s I was thinking about setting this up with composer as well, so instead of running out the root it runs out the vendor folder but the process remains the same. Does anyone want this?

Thanks for explaining. I’m quite new to this but am really loving the functionality. Thank you for your time in answering :smile:

@JulienMelissas have you tried this out yet? I made a few changes today but pretty sure it works in most use cases now. The first version I released definitely didn’t work on most setups lol

Ha, actually I haven’t had the chance. Going to try to get to use it on the next project :+1:

@anon66789415 thanks so much for your great script. I have forked it, credited you in my sh file, and went in a different direction, introducing some flexibility and documentation. Linking here in case anyone is interested.

https://hellojason.net/blog/deploying-bedrock-sage-wordpress-to-wp-engine/

4 Likes

Hi guys!

How do you manage Bedrock autoloaded mu-plugins?
It breaks the site on my install, the autoloader makes some scripts load twice.

The manual solution I came up with is removing bedrock-autoloader.php and requiring the .php files in the plugins folders. Did you manage to automate this?

Sorry for the delay @fgilio. There should be a way to automate the mu-plugins directory as part of the process. Made an issue for it: https://github.com/hello-jason/bedrock-sage-deploy-to-wpengine/issues/14

1 Like

Awesome!

I’m actually using a modified version of your script to deploy some sites. But those only use Sage, not Bedrock, at least for now…

EDIT:
Maybe Bedrock could exclude WPEngine mu-plugins from the autoloading process. Because the problem is that WPEngine has a mu-plugin that takes care of loading some other scripts inside a subfolder… so Bedrock also loads those and it fails.
Maybe add an option to exclude certain directories?

EDIT 2: The point is that Bedrock Autoloader does work ok. But fails because of how WPEngine loads their mu-plugins.

  1. The most recent pull request pushes mu-plugins with your deploy (https://github.com/hello-jason/bedrock-deploy-to-wpengine/pull/18).

  2. The Bedrock Autoloader no longer triggers the error it used to on WP Engine.

1 Like

Awesome, thank you!!

I managed to make bedrock autoloader and WPEngine work together by modifying a few files:

  1. composer.json
    • change "web/app/mu-plugins/{$name}/" to "web/app/mu-plugins/bedrock/{$name}/"
  2. bedrock-autoloader.php
    • change self::$relative_path = '/../' . basename(__DIR__); to self::$relative_path = '/../' . basename(__DIR__) . '/bedrock';
    • change all instances of WPMU_PLUGIN_DIR to WPMU_PLUGIN_DIR . '/bedrock/'

You will then need to run composer update and likely delete the plugins within mu-plugins that are leftover and now within the bedrock subfolder (they weren’t auto removed for me).

I literally just got this working, so will report back if it fails, but so far so good.

Hey Jamie,

Anything to report? Looking to deploy to WPEngine myself and hoping I can use Bedrock without sinking too much time into it.

Cheers

@inthedeepend I’ve been deploying to a WPEngine staging build without issues yet! Are you deploying with this? https://github.com/hello-jason/bedrock-deploy-to-wpengine If yes, and if you’re also using Trellis, let me know and I’ll help you get that script working (depends how your git repo and folder structure is setup for your Trellis project).

@jamiechong I’m getting the following error on WPEngine
PHP Fatal error: Cannot redeclare class Roots\\Bedrock\\Autoloader in /nas/content/live/siteprod/wp-content/mu-plugins/bedrock/bedrock-autoloader.php on line 16
Have you seen this before?

hello, this is what i looking for. still work guys?

Same error here, any hint?