How to use CLI if env variables are set in Apache


How is it possible to properly use CLI when setting environment variables in Apache?

I’ll explain: If, as recommended, I don’t use .env to set environment variables then cli-script doesn’t have access to these variables. However, to run a dev/build (or any other task) you need to be logged in as admin or use the cli-script.

And if not through CLI, how should an automated task be run in SS4?
I know you can re-instantiate/inject custom classes to go around part of it but I must say I was expecting an out-of-the-box solution. Am I missing something?


Probably the reason that there’s no ‘out of the box’ solution is because all the boxes are different :wink:

Apache / Nginx / Windows / Linux / Lighttpd etc. so many possible variations. The .env file tries to provide a unified solution, but it obviously has some compromises as a result.

If you’re on a Linux style OS, you should be able to export the ENV variables in your CLI:

eg: export SS_ENVIRONMENT_TYPE=dev && php cli-script.php dev/tasks/dosomething

If you’re on Windows, I’m not so sure… but I think you can do something similar with a set command.

Yes, you’re right, thanks for your response. But I still feel like you have to define the env vars twice. Once in the Apache vars and once in your cli-script calls. I’m not sure people will get away from a .env file with this concept. It would be worth being able to call tasks over URL (instead of cli-script) using an identification token.
Anyhow, thanks for taking the time to respond to my post.