Variable ENV - LocaleWP

Hi everyone,

I’m looking to define environment variables (using define or something like SetEnv WP_DB_HOST "localhost" in PHP directives) outside of my WordPress project directory when working with LocalWP.
I want a clean setup without adding any external libraries (like Composer, dotenv, etc.) or modifying the project files directly.

Does LocalWP offer a native way to inject these constants globally or via some preload config before WordPress loads?
If so, how can I set this up?

Thanks in advance for your help!


System Details

  • Local Version: Version 9.2.4+6788

  • Operating System (OS) and OS version: MAC OS


We don’t have anything like that from within the Local UI.

If you’re comfortable with doing something a little hacky, with the knowledge that you might have to re-make the changes after upgrading Local, you might be able to use the local-bootstrap.php file.

This is a file that Local prepends to each request and is located at Contents/Resources/extraResources/local-bootstrap.php within the Local app’s folder. On a Mac, that would be at /Applications/Local.app/

One thing I’m not 100% sure of is if this would also be present when running wpcli commands. I think that this file is probably included in wpcli calls, but just something to be aware of.

1 Like