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 ?
Related
The structure of my project is
/var/www/mysite
------pages
------scripts
------other
In it's corresponding virtual host the configuration is:
ServerName mysitename.com
DocumentRoot /var/www/mysite/pages/
Because of that, when serving the index.php from the pages folder, the resources(scripts/images etc ) are not found, as expected, because the page is trying to load them like so. http://mysitename.com/scripts/storage.js.
This of course makes sense.
How would you approach solving this? I am aware that by setting some mod_rewrite rules you can conditionally rewrite urls, is that a way to go about it? Im mainly interested in seeing what my options are here rather than getting one solution like, move your .html file up one layer.
There are 2 possible solutions:
Using alias in your Apache server config (of course you need to have control over Apache config). An example of alias command:
Alias /scripts /var/www/mysite/scripts
<Directory /var/www/mysite/scripts>
Options Indexes
Allow from all
</Directory>
Create a symbolic link inside pages/ directory. For example on *nix systems use this command to create symlinks:
cd pages
ln -s ../scripts .
ln -s ../other .
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.
We have a application that makes use of an Apache environment parameter to determine what config it should use. Around 5 instances of the application are is hosted on one cPanel / WHM development server.
We could use the .htaccess to set the right environment, but that results in uncommitted changes. cPanel should handle this variable via the vhost file, basically each vhost should have a different value:
SetEnv APP_ENV dev
SetEnv APP_ENV test
SetEnv APP_ENV trans
So, how can we let cPanel handle environment variables? It doesn't seem that this is possible, given the SetEnv can't be found in the vhost template.
https://blog.rac.me.uk/2013/05/29/new-relic-cpanel-apache-and-fastcgi-php/
We can do this with custom php.ini file (most of the hosting provider give option to create custom php.ini file, create custome php.ini file for each domain )
Add configuration in custom php.ini file
APP_ENV="dev"
form php code we can use get_cfg_var() function to retrieve
<?php
echo "current env is : ".get_cfg_var('APP_ENV');
?>
Output
I wanted to change the default document root for some local development on my new machine.
I edited httpd.conf and changed the DocumentRoot declaration to "Documents/Sandbox" and made sure the Sandbox directory has the correct permissions (777).
Further down in httpd.conf I edited another line to read .
So basically I replaced all original DocumentRoot declarations and replaced them with "Documents/Sandbox".
Now whenever I try to run Apache I get the infamous "Documentroot must be a directory" error.
I tried different variations of the DocumentRoot such as with and without a trailing slash, with a home directory declaration (~), adding "Users/me/", ... anyway it doesn't work.
Is what I am trying to do possible (ie having my DocumentRoot in a folder under "Documents" on my machine" and if so how do I go about correct this error?
I had the same problem. I was missing the first "/"
IE: /Users/me/Documents/Sandbox
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!'