Apache -> Ruby locale - ruby

I've got the following code checking the default encoding for read files (I'm on Linux, Ubuntu 16 x64), just for testing:
File.read("/bin/ls").encoding
If Apache calls my code through FastCGI then the output is US_ASCII (C locale), but if I run my code manually from anywhere in the system, I get en_US.UTF-8 encoding.
Changing the LANG env variable in /etc/apache2/envvars does not have any effect. Changing the ENV config in /etc/init.d/apache2 doesn't either (after service restart of course). /etc/default/locale is set to en_US.UTF-8. Playing with the virtualhost in my conf file and adding default char sets doesn't help either.
Checking the ENV array when called from Apache is almost empty (only the PATH variable is set), while checking it when run manually is full of variables like LANG etc. So it is obviously an environmental setting problem.
There is an external GEM that I use for my project and it's got a bug when run in a non-unicode environment. I could patch it manually but it's not a good solution because an update will overwrite it.
How could I get Apache to run my code called in a unicode environment?

The solution is: https://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html#fcgidinitialenv
edit /etc/apache2/mods-available/fcgid.conf
FcgidInitialEnv LC_ALL en_US.UTF-8
service apache2 restart

Related

how to change config server uri dynamically using OS environment

I have a spring config server and spring config client. In client I have set spring.cloud.config.uri to http://localhost:8888 but I want to change it to some other uri say http://example.com:8888 in windows using OS environment with setx. so I ran
setx spring.cloud.config.uri "http://example.com:8888"
but when I run my spring config client it's still trying to read from localhost . As per this link my spring.cloud.config.uri in bootstrap.yml should get override by what i set with OS environment but it didn't. Please let me know what I am doing wrong here.
setx
setx adds the variable but doesn't make it available in the current shell (as explained here):
setx modifies the value permenantly, which affects all future shells,
but does not modify the environment of the shells already running. You
have to exit the shell and reopen it before the change will be
available, but the value will remain modified until you change it
again.
Just make sure you are runnning from a newly opened shell window.
I suggest you use set spring.cloud.config.uri=http://example.com:8888 just for the sake of testing.
Check if the environment variable is present
You may add the following as the very first line your main method:
System.out.println(System.getenv("spring.cloud.config.uri"));
System.out.println(System.getenv("SPRING_CLOUD_CONFIG_URI"));
Variable name with underscore
Windows supports environment variables with dots, so it should be ok for you. This isnt the case for pretty much all the other OS. Just so you know, spring supports variable name with underscores (as explained in the link you provided):
If you use environment variables rather than system properties, most
operating systems disallow period-separated key names, but you can use
underscores instead (e.g. SPRING_CONFIG_NAME instead of
spring.config.name).

www-data can't find the ruby gems on vagrant configured virtualbox

I'm trying to get a virtual server running using Vagrant and VirtualBox. For the VirtualBox I'm using scotch/box which got all the basic stuff for running a ubuntu server with some components (apache, mysql, php etc.) more on scotchbox can be found here.
Now I got the server up and running (running a Yii2 application) but as soon as the application starts I get an Yii error message sh: 1: sass: not found and because of that a SASS file couldn't be converted to CSS. So I went back to my server to check if sass was installed, it wasn't so I ran the command gem install sass and after that sass was installed. gem list sass -i returned true.
But still the problem stayed, sass couldn't be found. I went back to my console and of course apache is ran by user www-data and I logged in to ssh with the vagrant user. And this is were it gets a bit vague for me. In the environments variables of the apache service I added the paths to both ruby and the gems. But still the www-data user cannot find the sass command or the gem command or even the ruby command.
I also tried to change the owner of the apache service from www-data to the vagrant user that did kinda help but thats not the solution I want to accept. I want a solution that the apache service stays owned by the www-data user and not a root user like vagrant.
If more data needs to be added please let me know.
Envvars file
envvars - default environment variables for apache2ctl
# this won't be correct after changing uid
unset HOME
# for supporting multiple apache2 instances
if [ "${APACHE_CONFDIR##/etc/apache2-}" != "${APACHE_CONFDIR}" ] ; then
SUFFIX="-${APACHE_CONFDIR##/etc/apache2-}"
else
SUFFIX=
fi
# Since there is no sane way to get the parsed apache2 config in scripts, some
# settings are defined via environment variables and then used in apache2ctl,
# /etc/init.d/apache2, /etc/logrotate.d/apache2, etc.
export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data
# temporary state file location. This might be changed to /run in Wheezy+1
export APACHE_PID_FILE=/var/run/apache2/apache2$SUFFIX.pid
export APACHE_RUN_DIR=/var/run/apache2$SUFFIX
export APACHE_LOCK_DIR=/var/lock/apache2$SUFFIX
# Only /var/log/apache2 is handled by /etc/logrotate.d/apache2.
export APACHE_LOG_DIR=/var/log/apache2$SUFFIX
## The locale used by some modules like mod_dav
export LANG=C
## Uncomment the following line to use the system default locale instead:
#. /etc/default/locale
export LANG
## The command to get the status for 'apache2ctl status'.
## Some packages providing 'www-browser' need '--dump' instead of '-dump'.
#export APACHE_LYNX='www-browser -dump'
## If you need a higher file descriptor limit, uncomment and adjust the
## following line (default is 8192):
#APACHE_ULIMIT_MAX_FILES='ulimit -n 65536'
## If you would like to pass arguments to the web server, add them below
## to the APACHE_ARGUMENTS environment.
#export APACHE_ARGUMENTS=''
## Enable the debug mode for maintainer scripts.
## This will produce a verbose output on package installations of web server modules and web application
## installations which interact with Apache
#export APACHE2_MAINTSCRIPT_DEBUG=1
export GEM_HOME=/home/vagrant/.rvm/gems/ruby-2.1.3
export GEM_PATH=/home/vagrant/.rvm/gems/ruby-2.1.3:/home/vagrant/.rvm/gems/ruby-2.1.3#global
export MY_RUBY_HOME=/home/vagrant/.rvm/rubies/ruby-2.1.3
export IRBRC=/home/vagrant/.rvm/rubies/ruby-2.1.3/.irbrc
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Try to find out whether the PATH that apache uses is indeed modified by your adjustments of the envvars file. You could do this by simply putting running this php code:
var_dump(getenv("PATH"));
die;
I've had the exact same problem. After a long time trying it turned out that service apache2 stop and start in vagrant is not working as expected. After setting the PATH variable in /etc/apache2/envvars try reloading apache by reloading vagrant instead: vagrant reload

Not able to connect to atom.io for themes and packages

I believe my work proxy is preventing me from being able to add themes and packages to Atom. From the preferences menu, I get:
Fetching featured packages and themes failed. Hide output…
tunneling socket could not be established, cause=140499728967552:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:../deps/openssl/openssl/ssl/s23_clnt.c:766:
Is it possible to make it use my $https_proxy variable? Is there some way to configure it to not use https?
You can configure your proxy settings in ~/.atom/.apmrc (or Atom\resources\app\apm\node_modules\atom-package-manager\.apmrc in Windows). Per the apm README:
If you are using a proxy you can configure apm to use it by setting the https-proxy config in your ~/.atom/.apmrc file like so:
https-proxy = https://9.0.2.1:0
It seems that as of Atom 1.0, there are some components that respect the http-proxy and https-proxy variables, and others that don't. For example, the initial check for the version of Atom works, but the check for packages doesn't seem to respect the http-proxy or https-proxy settings.
I was able to get Atom working with Fiddler as my proxy (on 127.0.0.1:8888) by running the following commands (on Windows):
apm config set proxy http://127.0.0.1:8888
apm config set strict-ssl false
I did not need to set http-proxy or https-proxy. I don't know if these settings have been deprecated or not, but they don't seem to work reliably in 1.0. The setting proxy works (and upgrades itself to TLS 1.2 automatically).
The entirety of my %USERPROFILE%\.atom\.apmrc file is:
strict-ssl=false
proxy=http://127.0.0.1:8888/
I was getting this error on Windows 7 fro Atom 1.0, when trying to look up packages.
In my case the issue was resolved by setting https-proxy variable to use http protocole instead of https. so both of the following parameters have exact same value.
here are the values from ~.atom.apmrc file
proxy=http://[host]:[port]/
https-proxy=http://[host]:[port]/
the answer by #NYCdotNet below that suggested to use
strict-ssl=false
didn't work as i was able to lookup some packages but installation failed with timeout error from GIT.
Atom will use your shell's proxy variables (like $https_proxy) if you start Atom from a shell that has these variables set. You need to have the Atom command line tools installed for that to work.
From a shell, you can simply type atom to open the editor for the current directory. It will use all environment variables from this shell, including the proxy variables.
I find this a lot easier than setting the variables in the config file.
I edited the ~/.atom/.apmrc file to set my proxy as mentioned by #AlexMooney, but still got errors.
The solution was to write
proxy = http://host:port
strict-ssl = false
in that ~/.atom/.apmrc file.
For Windows you can easily configure the https-proxy via command line:
amd config set https-proxy https://9.0.2.1:0
It should be stored under C:\Users\...\.apm in file .apmrc
See userconfig with command
amd config list
To config Proxy for Atom to install new pakage, just open CMD and run these commands:
apm config set strict-ssl false
apm config set proxy your_proxy
apm config set your_proxy
I am working behind a proxy server and spent about half a day on this issue, setting https_proxy as well as http_proxy didn't make a difference.
What did it for me was setting the proxy from the cmd line like so:
apm config set proxy http://myproxyaddress:port
I still can't install packages through Atom's gui, but doing it through the cmd line works fine. That I'll take.
I later realised I could've switched to the wifi and got it to work immediately...

Capistrano set configuration environment variables

I'm shocked I haven't been able to find this with googling but I was wondering how to setup a capistrano deploy where the environment variables store the important config variables (api keys, etc). I know how to access them in the code, I just can't get the environment variables setup.
I'm running Ubuntu 12.10 X64 Server and capistrano doesn't seem to be loading my .bashrc file.
Where can I put the environment variables so that they're loaded when any commands are run.
You can set environment variables by creating the ~/.ssh/environment file as follows:
PATH=/opt/bin:/usr/local/bin:/usr/bin:/bin
LANG=C
Note that you should set PermitUserEnvironment to yes in the /etc/ssh/sshd_config and restart the sshd daemon.

how to set env variable for apache on Mac OS X

I am using Snow Leopard and Apache 2.2. I want to set APACHE_ERROR_LOG used in virtual host log settings.
Somehow my Errorlog setting is getting prefixed with usr/$. I am guessing it must be in some setting which right now I can't figure out.
I get error in apache log as:
[error] (2)No such file or directory: could not open transfer log file /usr/$PATH_SPECIFIED_FOR_VIRTUAL_HOST_LOGS
Here is what was wrong. In one of the virtual host i has typo and it started with #. The http.conf has server-root configuration which says
# Do not add a slash at the end of the directory path. If you point
# ServerRoot at a non-local disk, be sure to point the LockFile directive
# at a local disk. If you wish to share the same ServerRoot for multiple
# httpd daemons, you will need to change at least LockFile and PidFile.
#
ServerRoot "/usr"
It was terrible typo mstake.
The easiest way to set an environment variable permanently in mac OS:
Open terminal application:
open -a /Applications/TextEdit.app ~/.bash_profile
In the recently open textedit window add at the bottom of the file the given environment variable, for example:
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_66.jdk/Contents/Home/"
NOTE: Make sure you use: (") instead of (“)

Resources