.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.

1 Like