Setup Environment Variable

Sorry, this might be a bit of the beginner question, but I can’t seem to figure out how to add an environment variable for a specific install. After I SSH to the install and I’m in the shell, where do I go from there?


Hi Justin,

You can add the variables to ~/.bashrc in the site’s SSH window. nano ~/.bashrc will bring it up in a pretty simple editor. Ctrl+ W then Ctrl + V (on Mac) will send you to the end of the file in nano. Then to save you just have to press Ctrl + X then Y

This may not work for your particular use case so if you can provide more info on what you need it for that’d be great.

What I’m trying to do is use getenv in PHP to get environment variables for things like API KEYS where I don’t want those things in code.

Will your suggestion work for that?

PHP dotenv may be a better fit. Check this out:

@clay Thanks for the suggestion, but I’d really like to just add an environment variable to the system like I would in production. Is this not possible with Local?

Hi Justin,

In that case you’ll need to go to that site’s folder then conf/php/VERSION/etc/php-fpm.d/www.conf and add the variables there.

The syntax looks like:

env[VARIABLE] = value

Once you change www.conf you’ll need to restart the site in Local.

That did it. Thank you!

1 Like