.env and wp-config.php

Hi all, I am using Bedrock and need to deploy a plugin license key to shared hosting.

I want to keep the license key in .env and read it from config/application.php. What I am missing is how Bedrock expects the config to be deployed to shared hosting. I don’t see a generated web/wp-config.php that merges .env and the config.

Right now I am copying wp-content to the shared host. That works for themes and plugins, but I’m not sure how to include the Bedrock config or load the env vars. What is the correct deployment approach for Bedrock on shared hosting, and how should I handle the env vars for a plugin license key?

In your .env file you should be able to have something like:

LICENSE_KEY='ABC123'

Then in your application.php file you can reference it like this:

Config::define('LICENSE_KEY', env('LICENSE_KEY'));

It’s the env('LICENSE_KEY') bit that reads the value from the .env file and the Config::define bit defines the value as a constant that can be used throughout your application. Many paid plugins allow you to set the license key as a constant so this is how you would do it.

As far as shared hosting, how shared are we talking? Ideally you would have SSH access with composer and git installed, which I think most cPanel hosts allow these days. The fact that your manually copying over the wp-content folder kinda defeats the purpose of Bedrock.

Ideally you would be able to SSH into the server (even if a shared account) and run a composer install command to update plugins, based on the plugins in your `composer.json’ file.

You would also want to have your .env file outside of your publicly accessible web directory. On most shared hosts they default to a public_html directory but some control panels like Enhance allow you to change the web root directory, so you could change it to something like your-repo-name/web assuming you set up your project with a Git based workflow. This article might help, especially the part about getting code on the server.

If you don’t have SSH access and Git / Composer managing a Bedrock site on shared hosting will be difficult as you lose the ability to update the site using Composer which is the main point of Bedrock. You can get good shared web hosting with SSH / Git / Composer for as little as $5 from a host like MediaServe so if you want to use Bedrock and your host is a limitation it’s likely time for a new host.

I’m able to run composer install through a repository pipeline and then have the pipeline build the wp-content folder to be pushed to the remote environment. For now, we’re leaving the existing wp-config.php file in the remote environment there and managing a local wp-config.php for our Lando instance.

This is still worth it so that we can manage the plugins/themes as dependencies with proper version control. It’d be cool if we could deploy the full Bedrock repository and change the web root directory, but we still get the same effect in the background through the pipeline. We’re using WP Engine, hopefully they move towards a more Bedrock friendly shared hosting setup, which I could actually see them doing.

This is the current WP Engine documentation have on the process: Deploying a Composer-Based WordPress Site (Including Bedrock) to WP Engine - Builders