Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple "environments" on the same machine? #4

Open
beporter opened this issue Jun 10, 2015 · 2 comments
Open

Multiple "environments" on the same machine? #4

beporter opened this issue Jun 10, 2015 · 2 comments
Labels

Comments

@beporter
Copy link
Owner

I'm responding to Gareth's questions via Twitter (here and here) in an issue because it's a little easier without a character limit and because I like having this discussion right here with the code and slides.

Quoting from above tweets:

Hey Brian, regarding your environment awareness stuff from #Cakefest, any suggestions on how to handle 2 envs on same server? We have staging & demo environments on same server :-) IIS env variables can handle HTTP, but shell might be tricky?

Windows makes this a little harder than *nix does, since on linux, Mac, etc, you can run individual commands with a specific env var using this style:

# In this example, APP_ENV will be set to "demo"
# for this **single** execution of bin/cake
$ APP_ENV=demo bin/cake some_shell arg1 arg2

This approach is a little harder in Windows. That said, the there are a couple things you can do here:

First, I'd recommend choosing one of the environments as "primary" (if that's applicable) and setting a machine-wide global command line environment variable for that. (The thinking here is that if you ever forget to manually set the environment, the "important" one should be in effect regardless. I like making it as hard as possible to "forget" something like this, although there are probably cases where "neither" is a better option but ask me about that separately.) Then you can use a batch script to override that environment var and put you in a CLI for the "other" environment. You'll have to use that script to set up the proper secondary environment, but that's kind of unavoidable when you have two envs on a single machine.

In this kind of situation, the most important goal (in my opinion) is to make as easy as possible to put yourself into each environment reliably and repeatably, so even if you end up just placing two shortcuts on your Desktop that open a command prompt, set the proper env var and cd to the proper webroot for you, that should get the job done. And really, this is actually pretty similar to the "shortcuts" you use to access the different environments on that machine from a browser (via different URLs).

A third option would be to maintain two different login accounts for each environment, with per-user env vars set for each, but that's getting a little extreme and probably more complicated than it's worth.

Like I said: Just try to give yourself quick, reliable ways to get to each env. If anyone has better suggestions, I'm definitely all ears.

@beporter beporter changed the title Multiple "environments" on the same machine Multiple "environments" on the same machine? Jun 10, 2015
@garethellis36
Copy link

Thanks for the detailed answer, Brian. I've added the conversion of our current switch block based on $_SERVER["HTTP_HOST"] (and a nasty shim for CLI) over to your eloquent solution on my to-do list. I'll report back with the solution I land on for the above issue. I tend to write simple batch scripts on each environment for running Cake shell commands anyway (because I'm too lazy to "cd" to the app directory to run the Console\cake command), so adding an environment variable line should be trivial.

@cwbit
Copy link

cwbit commented Jun 10, 2015

Is there any reason you're not able to use something like Vagrant to spool up different environments? or even to use the Windows equivalent of MAMP Pro (Mac server app). MAMP for example lets me do things like this where i can have two hosts pointing to the same webroot, but with different environment variables.
screenshot 2015-06-10 10 42 49
Not sure if that makes sense, helps, or is even applicable to your situation - but it's how I easily do multiple ENVs on same code base.

It's coming to me now that maybe your question was more about how to pull it off at the CLI level... oh well I'll leave all that in case it helps someone else 💨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants