Sogl
Sogl

Reputation: 822

Can't run Laravel vagrant box on Windows 7 machine

I'm trying to run vagrant homestead laravel virtual machine, but can't. I follow official instructions.

My steps:

  1. Vagrant and VirtualBox installed successfully.
  2. vagrant box add laravel/homestead downloaded.
  3. git clone https://github.com/laravel/homestead.git Homestead. I can't see any *.yaml file in root directory as I see in this video.
  4. I open Git bash and go to Homestead folder, than type sh init.sh.

Output:

$sh init.sh
cp: overwrite `/z/.homestead/Homestead.yaml'?`
cp: overwrite `/z/.homestead/after.sh'?`
cp: overwrite `/z/.homestead/aliases.sh'?`
Homestead initialized!

But I can't see Homestead.yaml file. Also my C:\Users\user\ folder not contains any .homestead folder.

  1. vagrant up

Output:

 c:/projects/Homestead/scripts/homestead.rb:91:in `read': No such file or directory - Z:/.ssh/id_rsa.pub (Errno::ENOENT)
    from c:/projects/Homestead/scripts/homestead.rb:91:in `block in configure'
    from C:/Vagrant/embedded/gems/gems/vagrant-1.7.4/plugins/kernel_v2/config/vm_provisioner.rb:72:in `call'
    from C:/Vagrant/embedded/gems/gems/vagrant-1.7.4/plugins/kernel_v2/config/vm_provisioner.rb:72:in `add_config'
    from C:/Vagrant/embedded/gems/gems/vagrant-1.7.4/plugins/kernel_v2/config/vm.rb:317:in `provision'
    from c:/projects/Homestead/scripts/homestead.rb:89:in `configure'
    from c:/projects/Homestead/Vagrantfile:20:in `block in <top (required)>'

    from C:/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/config/v2/loader.rb:37:in `call'
    from C:/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/config/v2/loader.rb:37:in `load'
    from C:/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/config/loader.rb:103:in `block (2 levels) in load'
    from C:/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/config/loader.rb:97:in `each'
    from C:/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/config/loader.rb:97:in `block in load'
    from C:/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/config/loader.rb:94:in `each'
    from C:/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/config/loader.rb:94:in `load'
    from C:/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/vagrantfile.rb:28:in `initialize'
    from C:/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/environment.rb:689:in `new'
    from C:/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/environment.rb:689:in `vagrantfile'
    from C:/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/environment.rb:441:in `host'
    from C:/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/environment.rb:207:in `block in action_runner'
    from C:/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/action/runner.rb:33:in `call'
    from C:/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/action/runner.rb:33:in `run'
    from C:/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/environment.rb:428:in `hook'
    from C:/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/environment.rb:671:in `unload'
    from C:/Vagrant/embedded/gems/gems/vagrant-1.7.4/bin/vagrant:177:in `ensure in <main>'
    from C:/Vagrant/embedded/gems/gems/vagrant-1.7.4/bin/vagrant:177:in `<main>'

What did I miss in my installation?

UPDATE:

I found these files in an already mounted disk Z:\ . Why bash creates files on Z:\ when I start init.sh from C:\?

Cygwin creates files in user profile folder (.homestead directory), but it also not making vagrant up to work.

UPDATE 2:

Now both vagrant up and homestead up commands give this output:

c:\projects\laravel5>homestead up
Bringing machine 'default' up with 'virtualbox' provider...
There are errors in the configuration of this machine. Please fix
the following errors and try again:

vm:
* A box must be specified.

Upvotes: 0

Views: 2156

Answers (2)

Leonardo Puglia
Leonardo Puglia

Reputation: 141

I've followed the instructions on Solg's answer and they work well. Thank you very much! I didn't found this answer anywhere else.

There are some reservations, though. I've found out that if you sudo su before installing laravel with composer global require "laravel/installer=~1.1" it will install laravel for the root user, and that is not what we should want, as it saves laravel on /root/.composer folder and it's only accessible by the root user.

A better aproach would be running sudo composer global require "laravel/installer=~1.1" without sudo su, so laravel gets fully installed with it's requirements, but in the vagrant user directory instead.

Actually, i've come up with an even better option (in my opinion) that is to put some code on the after.sh, located in .homestead folder, to be automatically executed when the VM goes up (by running vagrant up):

if [ ! -d $HOME/.composer/vendor/bin ]; then
    echo "Installing Laravel Installer!!!"

    sudo composer global require "laravel/installer=~1.1"
    echo "\nPATH=$HOME/.composer/vendor/bin:$PATH" >>$HOME/.profile
fi

This way, even if you destroy your VM, when you vagrant upit again, laravel will be installed and laravel command added to bash.

Hope it can help you.

Upvotes: 1

Sogl
Sogl

Reputation: 822

Did it on Windows 7 and Windows 8 machines.

Steps:

  1. Install Git for Windows.
  2. Change HOME path by setting Windows PATH value. Article how to do it. Now if you type cd ~ in Git Bash than you must move to your profile folder. Also Git Bash starts with the same folder.
  3. Install Vagrant and VirtualBox.
  4. Add Vagrant box vagrant box add laravel/homestead.
  5. In your profile folder type git clone https://github.com/laravel/homestead.git Homestead.
  6. Create ssh keys in Git Bash by moving to cd ~/.ssh and type ssh-keygen -t rsa -C "yourmail@you" -f homestead.
  7. Move to ~/Homestead and type sh init.sh. It creates 3 files in ~/.homestead folder.
  8. Edit your Homestead.yaml file. My config (# for comment line):

    ---
    ip: "192.168.10.10"
    memory: 2048
    cpus: 1
    provider: virtualbox
    
    #Paths to your generated SHH keys
    authorize: ~/.ssh/homestead.pub
    
    keys:
        - ~/.ssh/homestead
    
    #Folder sharing
    folders:
        - map: C:\projects\Laravels  <----your Windows mapped folder!
        to: /home/vagrant/Code   <--- VM mapped folder. Do not change it.
    
    #Add your sites here
    sites:
        - map: test.lar
        to: /home/vagrant/Code/test.lar/public
        - map: test2.lar
        to: /home/vagrant/Code/test2.lar/public
    
    #I commented it because do not want to re-create DB on each VM run
    #databases:
    #    - homestead
    
    variables:
        - key: APP_ENV
        value: local
    
  9. Edit hosts file on \Windows\System32\drivers\etc folder and add 2 lines to the end:

    192.168.10.10  test.lar
    192.168.10.10  test2.lar
    
  10. Now move to ~/Homestead and start your machine with vagrant up. In most situations you need to run Git Bash as administrator. After this command you can see in VirtualBox running machine with name Homestead.

  11. Open http://test.lar in browser on your host machine. You can see line No input file specified. All is OK.
  12. SSH to homestead VM by typing vagrant ssh and become root user with sudo su.
  13. If you want to create sites with laravel command, type this: composer global require "laravel/installer=~1.1"
  14. Add composer global folder to PATH with export PATH="$PATH:~/.composer/vendor/bin" and source ~/.bashrc. More info.
  15. Move to laravel code folder cd /home/laravel/Code and create your first project with laravel new test.lar.
  16. Refresh your http://test.lar page and see working page with Laravel 5 on the center of the screen. It works! Files in your mapped folder are automatically synchronized.

That's all. Mostly i used this tutorial and official in parts.

Upvotes: 3

Related Questions