Vagrant Windows-1251 encoding error - vagrant

I got the next error with vagrant when trying to use "vagrant up" command:
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'precise32'...
C:/HashiCorp/Vagrant/embedded/gems/gems/childprocess-0.5.3/lib/childprocess/wind
ows/process_builder.rb:43:in `join': incompatible character encodings: Windows-1
251 and UTF-8 (Encoding::CompatibilityError)
I have Windows 8.1, and I used "chcp 1251" command before, because it was the same error with "ibm866" encoding.
Thanks!

Problem was solved by setting environment variable VAGRANT_HOME

the solution for me was this one .
You have to go to : c:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.6.3\bin\vagrant
And edit the vagrant (file) and put after this : #!/usr/bin/env ruby
this 2 lines
Encoding.default_external = Encoding.find('Windows-1250')
Encoding.default_internal = Encoding.find('Windows-1250')
Good luck!

Set an environtment variable VAGRANT_HOME to the path, for example 'c:\HashiCorp'
Then add to c:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.6.3\bin\vagrant after #!/usr/bin/env ruby these two lines:
Encoding.default_external = Encoding.find('Windows-1251')
Encoding.default_internal = Encoding.find('Windows-1251')
Notice Windows-1251, not Windows-1250.
And I think you might need to reboot to enable the environment variable.

Yes, setting environment variable VAGRANT_HOME can solve the problem.
I think it's mainly because vagrant up command would try to visit %userprofile%\.vagrant.d folder, however, your %userprofile% is named in Windows 1251 encoding. Setting VAGRANT_HOME can point to a path recognizable for vagrant's ruby script.

If you stil having some trouble with it, even after seting env variable, try just to move your "homestead" folder to a path that not contains any cyrilic symbols.
Or you can create another user in you system without cyrilc
Hope it helps!

Related

GrumPHP and php-cs-fixer on WSL using wrong version

I'm trying to get GrumPHP to work with a small Laravel 9 project but php-cs-fixer is being pulled from the wrong location and I can't seem to find how to change this.
Error from GrumPHP:
phpcsfixer
==========
PHP needs to be a minimum version of PHP 7.1.0 and maximum version of PHP 7.4.*.
You can fix errors by running the following command:
'/windir/f/wamp64/vendor/bin//php-cs-fixer' '--config=./home/testuser/php-cs-config.php_cs' '--verbose' 'fix'
Seems like an easy fix, so I updated php-cs-fixer and followed the upgrade guide to get to v3. (currently sitting on 3.10). But I can also see that '/windir/f/wamp64/vendor/bin//php-cs-fixer' is not the correct directory for php-cs-fixer, the actual bin folder is located in WSL not the windows directory so I included a GRUMPHP_BIN_DIR in the grumphp yaml but still no luck.
grumphp.yml
grumphp:
environment:
variables:
GRUMPHP_PROJECT_DIR: "."
GRUMPHP_BIN_DIR: "./home/testuser/tools/vendor/bin/"
paths:
- './home/plustime/tools'
tasks:
phpcsfixer:
config: "./home/testuser/php-cs-config.php_cs"
allow_risky: ~
cache_file: ~
rules: []
using_cache: ~
config_contains_finder: true
verbose: true
diff: false
triggered_by: ['php']
I can't seem to find much about this or anything in the docs, so any help would be appreciated.
This ended up coming down to altering how WSL constructs the environment. To get around WSL building windows paths into the Linux distribution.
The answer was found here:
How to remove the Win10's PATH from WSL
Quick run down:
On the WSL instance open the file /etc/wsl.conf with something like
sudo nano /etc/wsl.conf
Add the following lines to the bottom of the file,
[interop]
appendWindowsPath = false
Mine looked like this when it was finished:
# Enable extra metadata options by default
[automount]
enabled = true
root = /windir/
options = "metadata,umask=22,fmask=11"
mountFsTab = false
# Enable DNS – even though these are turned on by default, we'll specify here just to be explicit.
[network]
generateHosts = true
generateResolvConf = true
[interop]
appendWindowsPath = false
Then restart the WSL instance from your windows terminal and restart it.
wsl --shutdown
GrumPHP now using the correct php-cs-fixer.

Messed up file contents in vagrant smb shared file

I decided to throw up a quick OpenCart installation today using the Homestead vagrant box with Hyper-V on my Windows 10 machine, and I've got my opencart folder mapped like this in Homestead.yml:
- map: D:\web\www\oc\oc-3.0.2.0
to: /home/vagrant/code/opencart
type: "smb"
All's well. The folder is synced in the vagrant VM as expected. But on trying to install OpenCart, I get this parse error:
PHP Parse error: syntax error, unexpected ''] == '' (T_CONSTANT_ENCAPSED_STRING) in /home/vagrant/code/opencart/upload/system/startup.php on line 93
Looking at lines 92-94 of that file on my host machine:
require_once(modification(DIR_SYSTEM . 'engine/event.php'));
require_once(modification(DIR_SYSTEM . 'engine/router.php'));
require_once(modification(DIR_SYSTEM . 'engine/loader.php'));
Looking at the same lines on the synced file in vagrant:
require_once(modification(DIR_SYSTEM . 'engine/event.php'));
requirePROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
$_SERVER['HTTPS'] = true;
This code that's replaced the "require_once" code here appears earlier in this file. It's as if it's recopied over later code, making this file unusable. Here's the full file.
If I delete the lines that are copied or replace them with some other code, things appear find in the vagrant version. But if I only delete a couple of the lines, the rest still overwrite later code.
Does anyone have any idea what's causing this or how to resolve it?
So it turns out this had nothing to do with Homestead nor OpenCart. I pulled up another vagrant project I had and noticed similar problems with synced files.
I had recently installed Docker for Windows to play around with, so I decided to uninstall it and see if that would fix the problem. And it did.
So somewhere, somehow Vagrant and Docker aren't getting along on Windows 10. No idea where the exact problem is, though.

"NameError: undefined local variable or method 'config' for main:Object" when trying to set Vagrant proxy

I'm very new to Vagrant (just installed it yesterday). And I am trying to set my proxy settings as per this answer. I have already installed the proxyconf plugin.
I am running Windows 7 64-bit. I assumed that the Vagrantfile in question was C:\Users\<my username>\.vagrant.d\Vagrantfile. This file did not exist, so I created it with the contents set to just the three lines given in the answer linked above (with yourproxy replaced by my actual proxy of course):
config.proxy.http = "http://yourproxy:8080"
config.proxy.https = "http://yourproxy:8080"
config.proxy.no_proxy = "localhost,127.0.0.1"
Now I am trying to run a Vagrant command (which I got from another online tutorial)
vagrant box add bento/centos-7 --provider=virtualbox
When I run it, I get the following:
There was an error loading a Vagrantfile. The file being loaded
and the error message are shown below. This is usually caused by
a syntax error.
Path: C:/Users/<my username>/.vagrant.d/Vagrantfile
Line number: 0
Message: NameError: undefined local variable or method `config' for main:Object
Sorry as this is probably down to my extremely limited knowledge of Vagrant, but can someone help me as to how to set it up correctly?
Need to put Vagrant.configure("2") do |config| before these lines and end after them. This is missed from the answer which I was quoting from.

How can I set a proxy server for gem?

I am unable to install SASS through command prompt.
I tried below steps
c:\gem install sass
I am getting below error:
ERROR: Could not find a valid gem 'sass' (>= 0), here is why:
Unable to download data from https://rubygems.org/ - Errno::ECONNREFUSED: No connection could be made because the target machine actively refused it. - connect(2) (https://rubygems.org/latest_specs.4.8.gz)
Please help me,
For http/https proxy with or without authentication:
Run one of the following commands in cmd.exe
set http_proxy=http://your_proxy:your_port
set http_proxy=http://username:password#your_proxy:your_port
set https_proxy=https://your_proxy:your_port
set https_proxy=https://username:password#your_proxy:your_port
You need to write this in the command prompt:
set HTTP_PROXY=http://your_proxy:your_port
You need to add http_proxy and https_proxy environment variables as described here.
When setting http_proxy and https_proxy, you are also probably going to need no_proxy for URLs on the same side of the proxy. https://msdn.microsoft.com/en-us/library/hh272656(v=vs.120).aspx
In Addition to #Yifei answer. If you have special character like #, &, $
You have to go with percent-encode | encode the special characters. E.g. instead of this:
http://foo:B#r#http-gateway.domain.org:80
you write this:
http://foo:B%40r#http-gateway.domain.org:80
So # gets replaced with %40.
You can try export http_proxy=http://your_proxy:your_port
None of the answers here actually helped my case (proxy + password), instead I found a solution on a Github issue:
https://github.com/rubygems/rubygems/issues/1068
Basically I had to set three variables:
set http_proxy=proxy_ip:port
set http_proxy_user=user
set http_proxy_pass=password

How can I define PATH for Phusion Passenger under nginx with Bundler?

Please forgive my near total ignorance of Ruby, but I am having an issue with Phusion Passenger in that it attempts to run something that relies on $PATH (and blindly assumes it is defined and a string). However, nginx evidently clears out the variable.
Error message:
private method `split' called for nil:NilClass
...
Backtrace:
# File Line Location
0 /usr/lib64/ruby/gems/1.8/gems/bundler-1.1.0/lib/bundler.rb 254 in `which'
That line reads:
path = ENV['PATH'].split(File::PATH_SEPARATOR).find do |p|
If there is a workaround for this, I would greatly appreciate it, as I would like to avoid using Apache if at all possible.
have you tried setting the path within your nginx config? Something to the effect:
env PATH=/some/path/expected:/another/path;
See: http://wiki.nginx.org/CoreModule#env

Resources