Roots Discourse

Bedrock on WPEngine

I have this project that needs to be deployed on WPEngine. I have dozens of other Bedrock projects on shared hosting but I can’t just copy my usual workflow.

In this particular case, I’m deploying with deployHQ which works like a charm. All dependencies are added and build files are generated on deployHQ’s servers and then migrated to the WPEngine server.

On other shared hosting, I always have a .htaccess file to load the web/index.php file. It would typically look similar to this:

RewriteCond %{REQUEST_URI} !web/
RewriteRule (.*) /web/$1 [L]

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /web
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Edit

WPEngine only uses the .htaccess file when using php 7.3, and will stop supporting this in the near future. Currently, when I’m testing the above .htaccess file with php7.3, I receive the wordpress white screen of death for the homepage. The /admin page forwards and loads the /wp/wp-login.php page, but all other requests from that page (css, js, images, …) get a 404 response (despite having a correct path and being there on the server).

From php7.4, WPengine has “redirect rules” that you could set in their admin panel.
I think (not sure) it should work if I translate those rules to WPEngine rules (they use common Regex).

Right now, I have 1 redirect rule in WPEngine with source ^/(?!web\/)(.*)?$ (which should ignore requests to the web directory) and destination /web/$1.

Does anyone here know

  1. If it is even possible to run Bedrock on Wpengine, with htaccess?
    and
  2. If it would work, how to set those redirect rules?

Hi!

I’m in the same situation now. How did it end up for you?

Hi Jonas

I created a new setup somewhat based on Bedrock. There were a number of issues that I wasn’t able to fix. For example, WPEngine already has a custom wordpress install when you create a new environment, and won’t support anything if you try to overwrite it. They can’t guarantee their speed and security they’re supposed to be good at. At least, this setup enables you to use composer for plugin management.

Here’s the structure of the setup:

config/install.sh
.deployignore
.gitignore
composer.json
wp-config.php

config/install.sh

curl -O https://wordpress.org/latest.zip
unzip latest.zip
mv wordpress/* ./
rm latest.zip && rm -r wordpress

.gitignore

# WordPress
wp-admin
wp-content/plugins/*
wp-content/mu-plugins/*/
wp-content/themes/index.php
wp-content/upgrade
wp-content/upgrade
wp-content/uploads/*
wp-content/index.php
wp-includes
/index.php
/wp-*.php
!/wp-config.php
readme.html
license.txt
xmlrpc.php

# Composer
/vendor

# Auto-generated files
.DS_Store
Thumbs.db

.deployignore
The .deployignore file is used by deployHQ, the ignored files are generated when building on deployHQ servers, but are not copied to WPE.

.deployignore
.gitignore
composer.json
composer.lock
README.md
wp-content/themes/*/.editorconfig
wp-content/themes/*/.eslintrc.js
wp-content/themes/*/.gitignore
wp-content/themes/*/.stylelintrc.js
wp-content/themes/*/CHANGELOG.md
wp-content/themes/*/CODE_OF_CONDUCT.md
wp-content/themes/*/composer.json
wp-content/themes/*/composer.lock
wp-content/themes/*/package.json
wp-content/themes/*/phpcs.xml
wp-content/themes/*/README.md
wp-content/themes/*/yarn.lock
wp-content/themes/*/resources/assets/config.json
wp-content/themes/*/resources/assets/build/**
wp-content/themes/*/resources/assets/build/
wp-content/themes/*/resources/assets/images/**
wp-content/themes/*/resources/assets/images/
wp-content/themes/*/resources/assets/scripts/**
wp-content/themes/*/resources/assets/scripts/
wp-content/themes/*/resources/assets/styles/**
wp-content/themes/*/resources/assets/styles/
wp-content/themes/*/node_modules/**
wp-content/themes/*/node_modules/
wp-content/themes/*/node_modules/**

composer.json
My composer file only requires roots/wp-password-bcrypt and roots/bedrock-disallow-indexing (aside from the wordpress plugins and other php libraries added with composer).

I did some tests with dotenv as well (vlucas/phpdotenv and oscarotero/env) but I can’t remember if I got that working though.

wp-config.php
Copy the wp-config.php file from your WPE environment, as generated by WPE on install.

Workflow
So basically I git clone my setup, remove git and init git so I have a new local repo for the new project.

Run the install.sh script to install wordpress in your local repo.
Next, install sage, composer require your plugins, do what you usually do :slight_smile:

Please let me know here how this worked out for you and especially when you manage to improve it! There’s more WPE + Sage projects coming up in the near future.