With my htaccess file, I'm setting this environment variable
SetEnv CI_ENV development
But I actually want to inherit the environment variable from the host. Something like
SetEnv CI_ENV %{CI_ENV}
I've tried:
SetEnv CI_ENV %{ENV:CI_ENV}
But that doesn't seem to work.
Reason: I'm using docker with a PHP/Apache container. Trying to pass configuration value into it so I'd like to not have anything hardcoded in the htaccess file if possible.
My current workaround is to have a .htaccess.config file with $CI_ENV in the file, and then using a script to substitute the env values, but would be nice to not have to do that.
You don't need to redeclare env variables if you use mod_setevif.
Use this directive in your root .htaccess:
SetEnvIf Host ^ CI_ENV=development
Then use it anywhere in sub-directories without any need of re-delcaring it.
EDIT: Based on comments below, it seems OP is trying to pass system (shell) env variables to Apache.
For that PassEnv directive can be used like this:
# pass system env CI_ENV to Apache
PassEnv CI_ENV
Now CI_ENV will be available as env variables in various Apache directives.
Related
In Linux/Ubuntu etc we have a file /etc/apache/envvars where we can define variables to be used across the Apache config but I cannot find such in MacOSX
What i'm trying to do is - create a variable - and use it inside a vhost.
# httpd.conf
SetEnv MY_PATH="/my/path/to/bin"
IncludeOptional="/home/user/website.conf"
# website.conf
<VirtualHost *:80>
SetEnv PATH "./current/app/bin:${MY_PATH}:${PATH}"
^^ ^^
not working works
</VirtualHost>
Since i have many websites - I want them all to use a "base" variable + app specific variables.
But the variable I created in httpd.conf can be used only the webapp itself ( os.getenv() i.e ) - it cannot be use with a ${MY_PATH} inside Apache.
I found somewhere that people edit this file - but it is not editable even with sudo, so i don't think it's the right choice:
/System/Library/LaunchDaemons/org.apache.httpd.plist
How can I create global variables ? or export variables like envvars file in other OS's ?
How to define dynamically the subdomain of wildcard address as a variable in apache configuration file ?
How can I call the enviroment variable in configuration file of apache ?
This option here doen't work:
Create an Apache SetEnv variable with the subdomain name in case of wildcard
It seems it doesn't work.
I've tried:
setting the enviroment virable:
SetEnv SUBDOMAIN subdomainx
SetEnvIf Host "^([^.]*).domainx.tldx$" SUBDOMAIN=$1
SetEnvIf Host "^([^.]*).domainx.tldx$" SUBDOMAIN=specificsubdomainx
Define SUBDOMAIN %-3
retrieving the variable in the same config file:
${SUBDOMAIN}
%{SUBDOMAIN}
SUBDOMAIN
Please help, Its freaking me out. Thanks
SetEnvIf Host "^([^.]*).domainx.tldx$" SUBDOMAIN=$1
looks ok (provided the domain you're using it on is *.domainx.tldx)
But you have to reference the variable like this:
%{ENV:SUBDOMAIN}
In my application I am trying to set the env variabel in the httpd-vhost config instead of insde .htacces file. If I put the setEnv variabel inside the .htaccess variable it works fine but not handy to keep .htaccess sync with production. I've tried as can be seen in my screenshot to set it inside the httpd config. I've restarted apache to load the new configuration.
Any advice or tips are welcome and thanks in advance.
When I set the setEnv variabel outside the it seems to work?
I have the following on my htaccess.
SetEnv APPLICATION_ENV development
When I pass this file to prodution, I will change it to:
SetEnv APPLICATION_ENV production
This
development
and
production
are set on Zend Framework application.ini correct ?
How does Zend and Apache communicate here? How does Zend knows about that htaccess instruction?
Thanks.
SetEnv, used in Apache's configuration (be it a .htaccess file, or a VirtualHost), defines an environment variable.
From PHP, you can read environment variables either :
using the getenv() function.
Or in the $_SERVER or $_ENV superglobal variables
Taking a look at the given index.php in Zend Frameworks QuickStart, you'll see it uses that environment variable the define the PHP constant called APPLICATION_ENV :
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV',
(getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV')
: 'production'));
And that constant is later used to initialize the application :
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
The flow of communication, as you call it, is the followoing:
If you use
SetEnv APPLICATION_ENV production
in your .htaccess, the environment you set there, will be used. Why?
The following piece of code from your index.php doesn't define the constant, if it has been defined already, which is the case, if you use SetEnv in your .htaccess.
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV',
(getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV')
: 'production'));
If your .htaccess doesn't define the constant, the value provided in the index.php will be used. If I were you, I would still keep it in sync. Because you may make mistakes like forgetting to set AllowOverride for your vhost which would result in a situation where the environment is set by the index.php even though the .htaccess is present.
I need to set my apache environment to 'foobar'
I know I need to set in in my vhost, but what should I type there and where?
SetEnv sets a particular variable to some value, so you need something like
SetEnv varname varvalue
If this is for a specific virtual host, and you have access to the Apache configuration files, this would go inside the <VirtualHost> directive for that virtual host.
If you don't have control of the config files, you'll need to put it in a .htaccess file. But for this to work, SetEnv must be allowed in .htaccess files, which is specified using the AllowOverride directive.
I came here because I configured a python/django WSGI environment.
Loading modules and SetEnv'ing all day long.
Did not work. The vars would just not show up.
What did work was this: https://gist.github.com/GrahamDumpleton/b380652b768e81a7f60c
Graham describes how to basically clone your wsgi.py file and then use a different one for each environment (production, test, dev) and setting your environment vars in there with os.environ['whatever'] = 'you like!'