Accessing files within vagrant using pycharm on host - vagrant

I am reading online docs of jetbrains but unable to understand that how does one access files on the vagrant VM from pycharm running on a host. Do I need to do tool>deployment>configure and than setup a SFTP to 127.0.0.1? If yes, I tried that but its unable to connect (even using default vagrant user which is password-less).
This is a common use-case and I am sure many would have done it. What am I missing?

I got this working by doing the following:
Tools -> Deployment -> Configuration
Add server (SFTP)
host: 127.0.0.1
Port: 2222
Root Path: /home/vagrant
user name: vagrant
password: vagrant
At this point you can test your connection. It should work. If it doesn't maybe your vagrant is not working properly?

Related

How to put files into Vagrant?

I did an internship and they used vagrant so all the developers whould run the same latest version of the web application.
But now i want to create my own vagrant webserver.
I got to the point that i setup vagrant using the hashicorp/precise32 box.
I got nginx running on my own special ip adress that i changed in the hosts file.
So now i can go to mytestsite.com and it will show me welcome to nginx.
But now my question is, how can i get my own file(small test web application) into the vagrant server because i do not know how to transfer my files to vagrant.
And how can i let my friends use my vagrant test web application.
Thank you for your help!
Sincerely Mex
19 years old
web application student in the Netherlands
By default vagrant will have a synced folder between your vm and the host machine. It is in the same folder as the vagrantfile and can accessed through /vagrant on your host machine.
However if you want more customization and mount certain folders on your host machine and sync them to the vagrant VM it can be done in the vagrant file as follows:
Vagrant.configure("2") do |config|
# other config here
config.vm.synced_folder "src/", "/srv/website"
end
Here is a quick guide to get you started using vagrants synced folders and the example i posted

How to access Redis running in Vagrant Virtual Machine

We are trying to use Vagrant to run a Redis server on Mac (using an Ubuntu Guest OS) with this Vagrantfile
Sadly we are unable to access the Redis database inside the Vagrant Box.
We get this error:
Error: Redis connection to 127.0.0.1:6379 failed - read ECONNRESET
This is the Network configuration in the VirtualBox VM:
What else do we need to add to the Vagrantfile to expose Redis to Mac?
(Note: the reason for using Vagrant is both to let people try redis without having to install it on their main OS, but more importantly to ensure that other elements of the app run as expected)
This may be helpful https://serverfault.com/questions/248248/cannot-connect-to-redis-installed-on-virtualbox-running-ubuntu-from-windows-7. I know question is about connecting from Windows, but the solution is mostly modifications to the Redis config within the VM in order to not bind Redis only to a local port in the redis.conf so that it can be accessed on the host machine(Mac in your case).
Also, depending on how you are trying to access Redis you may be able to configure a SSH tunnel on the host machine(Mac) in order to gain access to the Redis server within the Vagrant VM. I ended up going this route for my case to connect to Redis inside of a Vagrant VM for local development of an Ember JS app using ember-cli and ember-cli deploy with ember-cli-deploy-redis
You can give a Private IP to the Vagrant box and then access redis using the private IP.
For example, lets say you want to configure 192.168.33.10 as you Vagrant box IP. Simply add this line in Vagrant file.
Vagrant.configure(2) do |config|
config.vm.network 'private_network', ip: '192.168.33.10'
end
From now u can access your vagrant box using 192.168.33.10
I happen to run Redis within a Docker container in addition to the Vagrant setup. Running into this question again and again, I want to a add my findings.
Indeed making sure binding to net devices is to 0.0.0.0 instead of 127.0.0.1 is essential. Since I am running Docker I just had to make sure the container is properly run:
docker run -d redis -p 0.0.0.0:6379:6379 redis
Then, in addition the known Vagrant configuration:
config.vm.network :forwarded_port, guest: 6379, host: 6379
And voilĂ : running Redis in a Vagrant VM using Docker, able to access it from the Mac OSX host system.
This is without changing the Redis config, since Docker takes care of this.

Configuring Homestead to work with MySQL Workbench

I just started using Homestead today and so far I don't think I know what I am doing, previously I was using the inbuilt PHP server that comes with Laravel and I had MySQL server and workbench installed separately on my computer.
With this setup I was able to connect to my database with ease, however since I got my Homestead running I can't seem to access that database again. This error keeps popping up:
3/3 ErrorException in Connector.php line 47: SQLSTATE[HY000] [1045]
Access denied for user 'myproject_db101'#'localhost' (using password: YES)
(View: /home/vagrant/Projects/myproject/resources/views/layout/index.blade.php)
(View: /home/vagrant/Projects/myproject/resources/views/layout/index.blade.php)
How can I fix this?
I was facing the same issue and I tried below steps to fix it. Please let me know if they work for you.
Note the homestead ip address for your vagrant box. It is available in Homestead.yaml file under ~/.homestead directory. This directory location would be different on different OS. But since you have already installed vagrant with homestead you should know its location. For me the ip address was 192.168.10.10.
Open up the Mysql Connection wizard and provide the below settings
hostname = 192.168.10.10
port = 3306
username = homestead
password = secret
Test Your connection
For me these settings worked. Check if they work for you.
These other answers might have worked for you guys, but in case anyone has a case like mine, I'm just going to provide what worked for me. Hopefully it helps someone out. I'm working on a brand new homestead installation as of today, but on a very old mac in case thats relevant.
What worked for me was using the regular localhost ip of my machine as the host, and then the homested/secret combination for the password, and using the default port but with a 0 at the end.
This adds up to be the following settings:
Connection method: Standard (TCP/IP)
Host: 127.0.0.1
Username: homestead
Password: secret
Port: 33060
Hopefully this helps someone out. Its the only configuration that worked for me.
Try using homestead's default MySQL credentials: User: root Password: secret
If you are accessing the database from your computer via MySQL Workbench (not from within the homestead VM), you can use localhost:33060 (note: non-standard port). This is mapped to port 3306 within your VM.
From your application and any time you're working from within the homestead VM, you can connect to the database normally as localhost on port 3306.
Very likely a configuration issue. Either the user 'myproject_db101'#'localhost' has no password set or is not allowed to connect from localhost. You need another user with proper rights (e.g. the root user) to fix permissions for that user.

Unable to access the database of homestead environment (laravel) through MYSQL workbench

Unable to access the homestead database through MYSQL workbench Please help me out to solve this issue
error messages at time of testing the connection - "Failed to Connect to MySQL at 127.0.0.1:33060 with user homestead Lost connection to MySQL server at 'reading initial communication packet', system error: 0"
please take a note that
Bind address in my.cnf file is 127.0.0.1 (my.cnf file located at /etc/mysql/)
hosts file contains: 127.0.0.1 localhost projectname (which is located at /etc/)
I have tried changing bind address to 0.0.0.0 but it was also not worked.
Actually I was keep trying to setup the database connectivity by just considering the homestead environment ... But on Keep searching I found one link http://www.acnenomor.com/171821p1/laravel-homestead-vagrant-box-database-problems from where I got idea and I tried once again with the data shown in attached image and it worked for me ... so I am sharing this answer in general .. it may help someone...
Please take a note that I have also tried to connect the database of Laravel homestead environment by installing all the stuffs in other system too and it was worked fine as described in the official document.. so in my case it might be the problem of some changes in configuration file of mysql or any other related environment... so please first go through the official document... http://laravel.com/docs/4.2/homestead#daily-usage
The first thing you need to do is
vagrant up
and then use these connections below for a default homestead installation.
Connection Method: Standard (TCP/IP)
Hostname: 127.0.0.1
Port: 33060
Username: homestead
Password: secret
Try the alternate IP of 192.168.10.10
hostname = 192.168.10.10
port = 3306
username = homestead
password = secret
This works for me on Windows 10 Home Version 20H2 OS Build 19042.1165 (To find this information navigate to Start, Type 'About' and click 'About your PC').
ran into a similar problem while trying to use SQLyog on my windows machine to connect to mySQL on a Homestead environment. I was able to resolve this issue by adding
skip-name-resolve
to the VMs /etc/mysql/my.conf file.
Apparently (according the mysql error logs) connections from the local machine were coming from '10.0.2.2', which caused the warning "IP Address '10.0.0.2' could not be resolved".
You will need to re-add this line every time you spin up the environment.

Using gitlab-vagrant-vm from OSX host

I followed the instructions here and was able to succesfully (I think) install the gitlab vagrant virtual machine on OSX 10.8 using virtualbox.
I can do vagrant up to get the VM running, and everything seems to work fine. After that I can do vagrant ssh without a problem. Also, after sshing into the VM I was able to do bundle exec rake gitlab:test, which completed with results being 1584 examples, 0 failures.
I would like to see the gitlab web interface from my OSX host machine. I thought I could just direct my browser to the IP indicated in the VagrantFile (http://192.168.3.14), but that didn't work.
Any ideas?
Also any other usage tips for this setup would be appriciated (things like where the repositories are stored on my host machine so I can back them up, if anyone set the gitlab-vagrant-vm up for external access from either another computer on the network or a remote source, ect.)
You have to connect a second interface for vagrant. To do this you've to edit the VagrantFile.
For example if you want to conenct to the host wifi add the following line after 192.168.3.14
config.vm.network :bridged, bridge: "en0: Wi-Fi (AirPort)"
You also can bridge to the ethernet interface. Use ifconfig on the host machine to determine the right interface. After that the dyndns-server of the host network will assign an IP to the Vagrant-Box. Then you can access GitLab on that IP.
Did you actually start the server? You can do that with
bundle exec foreman start -p 3000
This will start the server on port 3000, you would then access it from the host with
http://192.168.3.14:3000/
Hope this helps,
Chris

Resources