Related
I've been having a problem with Vagrant (1.8.1, using VirtualBox 5.0.20) on Windows 10.
When I follow the getting started tutorial https://www.vagrantup.com/docs/getting-started/ after I have typed vagrant up, my console is stuck on:
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2200
default: SSH username: vagrant
default: SSH auth method: private key
It does not continue, i can see the VM boot inside of VirtualBox, and i can use the VirtualBox GUI to log in with the default credentials, so the VM itself is working.
According to https://www.vagrantup.com/docs/virtualbox/common-issues.html
I should run VirtualBox as admin and do vagrant up from a cmd.exe with admin rights, but when i do that i get the message:
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.
Command: ["modifyvm", "1b9d4f9b-04d8-48bf-8d16-d3aed99d341b", "--natpf1", "delete", "ssh"]
Stderr: VBoxManage.exe: error: Code E_FAIL (0x80004005) - Unspecified error (extended info not available)
VBoxManage.exe: error: Context: "LockMachine(a->session, LockType_Write)" at line 493 of file VBoxManageModifyVM.cpp
This seems different from the 100's of posts all around the net like these:
https://github.com/Varying-Vagrant-Vagrants/VVV/issues/375
since I am not getting antying after the output listed above, it just sits there and after alike 10 minutes it comes up with the message:
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.
If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.
If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.
If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.
I've also read Vagrant stuck in "Waiting for VM to Boot" but it did not help me.
Is there anything else I am missing here?
In my case, vagrant up was hanging on 'Syncing VM folder' , on Windows 7 with Vagrant 1.9.3 and VBox 5.1.18 . It turned out that it requires Powershell >= 3.0.
I downloaded it from https://www.google.ca/search?q=powershell+3.0+download&ie=utf-8&oe=utf-8&client=firefox-b&gfe_rd=cr&ei=x0fdWLfsBubQXu2OorAD, and worked fine afterwards.
try to turn off the VM from VirtualBox or from command line
C:\Progra~1\Oracle\VirtualBox\VBoxManage.exe controlvm default poweroff
then restart the VM from vagrant.
In case you get an error when powering off the VM, force the shutdown
C:\Progra~1\Oracle\VirtualBox\VBoxManage.exe startvm default --type emergencystop
Then vagrant up will should work nicely
I actually already found my problem. It was a .dll from some addware scanner that was preventing the virtualbox VM from starting. I lost the link to the forum topic which helped me solve this unfortunately.
What i did was open the logs from the VM in VirtualBox and had a read trough. At some point, a line indicating an error appeared with a .dll name which was the culprit. I deleted the offending .dll files from my pc and it was fixed.
If i find the link again to the topic explaining exactly what dll it was i will post it here. Im not at the machine that i fixed the problem on now so i can't access my search history.
Hope it will work for you as it worked for me
I'm still investigating why, but as a solution it works.
our case - when typed in cmd (inside vagrand image directory) "vagrant up"
it open virtual box vm and stuck on "default: SSH auth method:
private key" as mentioned in question
so fix by this steps:
open manually virtual box (besides what already opened by vagrant up)
run the vm that had added to the list (by vagrant up)
open CMD
type "Vagrant ssh"
and it will work
hope it helped,
best regards
I am setting up my previously working vagrant environment in Windows 10. I've updated to the newest version of both VirtualBox (https://www.virtualbox.org/ticket/14040) and Vagrant.
When I vagrant up I get an error: Cannot rename this connection. A connection with the name you specified already exists. Specify a different name.
I've since tried deleting all of my boxes, deleting the .vagrant and .virtualbox directories, reinstalling both virtualbox and vagrant. Yet, I always get the same error. Here is the error message from my console:
The guest machine entered an invalid state while waiting for it
to boot. Valid states are 'starting, running'. The machine is in the
'poweroff' state. Please verify everything is configured
properly and try again.
If the provider you're using has a GUI that comes with it,
it is often helpful to open that and watch the machine, since the
GUI often has more helpful error messages than Vagrant can retrieve.
For example, if you're using VirtualBox, run vagrant up while the
VirtualBox GUI is open.
The primary issue for this error is that the provider you're using
is not properly configured. This is very rarely a Vagrant issue.
I had the same issue with Scotchbox, and even after installing the test build the issue was still there.
This is how I fixed the issue.
Step 1: Download and install https://www.virtualbox.org/attachment/ticket/14040/VBox-Win10-fix-14040.exe and leave it running in the background
Step 2: Head to the Virtual box program files ( C:\Program Files\Oracle\VirtualBox ).
Step 3: Go to compatibility for these three .exe ( Virtualbox.exe, VBoxHeadless.exe, and VBoxManage.exe ) and choose windows 7.
Then just run vagrant up again and it should work.
Right, I've spent a lot of time trying to resolve this. And I finally came across a post on the laracasts forum:
I've been able to get Homestead up and running after a day of troubleshooting with the following steps:
Installed the VirtualBox 5.0.1 test build
https://www.virtualbox.org/download/testcase/VirtualBox-5.0.1-101902-Win.exe
Information at: https://www.virtualbox.org/ticket/14040
I also reinstalled Vagrant 1.7.4
This solved the initial issue with VirtualBox, but presented another
issue. When I attempted to "vagrant up" I would get a pop-up error
message from VirtualBox about not being able to rename the connection,
the VM wouldn't boot, and I would get the error message that
#antonybudianto posted in terminal.
I applied a suggestion made by Venimus in this thread:
https://github.com/mitchellh/vagrant/issues/6059
I edited line 17 in /Homestead/scripts/homestead.rb as follows:
config.vm.network "private_network", ip: "192.168.10.10", name: "VirtualBox Host-Only Ethernet Adapter #3"
Apparently the trick is to include the name of the host-only adapter
that you've already set up in VirtualBox. By doing this, you prevent
Vagrant from attempting to rename the connection. You just need to
make sure that the name matches the name of your adapter in Windows.
Also, go into the VirtualBox GUI and make sure that the host-only
adapter is on the same network, but not the same ip. My homestead is
192.168.10.10, my VirtualBox host-only adapter is set to 192.168.10.9.
This seems to be working well for me, and has the advantage of not
changing your Vagrant install at all. It's a Homestead-only
modification.
https://laracasts.com/discuss/channels/general-discussion/windows-10-vagrant-virtualbox-homestead/replies/87037
It has worked for me. Do note this part:
You just need to make sure that the name matches the name of your
adapter in Windows. Also, go into the VirtualBox GUI and make sure
that the host-only adapter is on the same network, but not the same
ip. My homestead is 192.168.10.10, my VirtualBox host-only adapter is
set to 192.168.10.9.
Hope it helps.
You have to uncheck the actual Ethernet network adapter by click rightclick >> Properties>> uncheckbox for virtualBox NDIS6 Brdige Networking Drive
so you have to check that checkbox on Virtual adapter only
This problem appears on my Windows 7, using vagrant 1.9.6 and VirtualBox 5.1.22.
The problem was that I previously removed some of the Host-Only adapters.
A workaround for this problem was to change the IPv4 address of existing Host-Only adapter to match the VagrantFile configuration:
look for IP in Vagrantfile for config.vm.network:
config.vm.network "private_network", ip: "192.168.42.10"
modify the IPv4 address of existing Host-only adapter to match the IP. Got to VirtualBox -> File -> Preferences -> Network -> Host-only Networks - > right click on VirtualBox Host-Only Ethernet Adapter (Edit Host-only Network). Change IPv4 address to:
192.168.42.1
Uninstall VirtualBox using CCLeaner then remove virtual adapter if it still exist from network and sharing center. For remove try using Device Manager and find networks and find the virtualbox adapters and remove them.
Then finally install it and don't launch it. Go to installation folder and right click on it and run it as Administrator.
:)
Njoy... Happy coding. :)
Since homestead 2.0 homestead laravel has not been working
I don't know why 'homestead init' creates a Homestead.yaml file in mydirectory/.homestead
and not in the project directory. Homestead up OR Vagrant up create the following message
A VirtualBox machine with the name 'homestead' already exists.
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'laravel/homestead'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'laravel/homestead' is up to date...
A VirtualBox machine with the name 'homestead' already exists.
Please use another name or delete the machine with the existing
name, and try again.
I solved by using vboxmanage to get the ID of the VM.
$ vboxmanage list vms
"my-vm" {c700b8b6-b766-4638-871b-736b44b7db18}
Copy the ID of the desired VM (the c700…db18 string) into the contents of ~/.vagrant/machines/default/virtualbox/id. Save the file then run vagrant up to get the vm working without having to destroy it.
For me, the machine was not showing up as an active VM in the VirtualBox application. To fix I had to do this:
vagrant global-status
This gave me the ID of the machine that I needed to destroy. With the ID, run:
vagrant destroy {VM ID}
I had to run that in sudo to actually destroy the machine. At that point, I was able to run
vagrant up
From the following message :
A VirtualBox machine with the name 'vm_name' already exists.
Please use another name or delete the machine with the existing
name, and try again.
I listed current running virtual machines from the command line :
VBoxManage list vms
Result :
"vm_name" {8ba467b7-da96-4f68-9bf8-671dd6f0d007}
Then proceeded with the removal of the offending virtual machine :
VBoxManage unregistervm 8ba467b7-da96-4f68-9bf8-671dd6f0d007 --delete
You probably have a virtualbox running! Open the programme virtualbox and shut down the other virtualbox ;)
http://smallbusiness.chron.com/shut-down-virtualbox-43657.html
If this isn't working then you might want to delete the old homestead folder and place all your projects in the new folder ;)
I'm a bit late to the party on this, but for anyone else having this issue SergioPeluzzi came closest, but didn't get the cigar with this:
Seek for vb.name = settings["name"] = "homestead" line and changed "homestead" to "HOMESTEAD" and "vói lá"
The line is actually:
vb.name = settings["name"] ||= "homestead"
As you can see from the bit that says settings["name"], you just need to add a name field to your Homestead YAML file, e.g.
memory: 2048
cpus: 1
provider: virtualbox
name: my-sexy-homestead-box
I edited Homestead.yaml and add new name for it
ip: "192.168.10.10"
memory: 2048
cpus: 4
provider: virtualbox
name: my-new-homestead-box-name
I solved this editing /Homestead_folder/scripts/homestead.rb
Seek for vb.name = settings["name"] = "homestead" line and changed homestead to HOMESTEAD and "vói lá" that worked for me.
I had an old .vagrant directory in my project which was causing the error :)
If this doesn't fix it for you i would suggest opening VirtualBox and removing all VirtualBoxes and trying again.
You just have to add the key name to your homestead.yaml file right after the provider like this:
name: name_of_you_machine
That works for me.
I had same issue today. Spend few hours to find the solution.
If by any reason you can't find the list of exiting virtual machines then type in terminal
sudo virtualbox
This will run Virtual Box in GUI. You should see the the full list of VMs and from there you'd be able to manage them.
Typing "virtualbox" only won't show anything. You need to be root (administrator).
Thanks to mightyspaj for the tip.
Commands to execute:
vagrant box list
vagrant box remove laravel/homestead
vagrant global-status
vagrant destroy nameOfYourBox
Open your VirtualBox and delete all itens of your homestead
vagrant up
I opened the virtualBox and then deleted homestead vm that was created earlier. It helped.
I was receiving the same error message, even after running "homestead destory", and "vagrant destroy". Same as you, I was using the VirtualBox provider, vagrant, and homestead. Here's what I did:
Opened VirtualBox GUI. I see "homestead" as a VM, but I cannot remove it, button is greyed out.
I logged out of my OS, logged back in and re-opened VirtualBox. Status is now "aborted" and i'm able to remove.
There were some residual files in ~/VirtualBox\ VMs/homestead, so i ran rm -r /Users/gabriel/VirtualBox\ VMs/homestead
I am now able to run "homestead up"
Open VirtualBox GUI. See for your VM and remove it.
It solved my problem.
Sometimes you might not want to delete old box. Yesterday may old Vagrant has broken, I've updated Vagrant and Virtualbox but folders mapping didn't work. I wanted to run new box and had this error.
I didn't want to remove old box (because I wanted to run some backups) but I wanted to run new box. The solution was running VirtualBox, right click on Homestead machine and choose Settings and then changing name from homestead to homestead_old.
After that I was able to install homestead but had this old machine and could also run this to make any backups I needed.
If you are a Windows User, make sure you delete C:\Users\<Username>\VirtualBox VMs\homesteadfolder. Because if there is still a folder named homestead, the action of vagrant up will not be completed
If you want to keep keep your machine, without destroying and recreating following steps should solve your problem.
(I work on OS X El Captain, Vagrant 1.8.1)
Run homestead in debug mode
homestead --debug up
Look for something like in the output:
INFO machine: Initializing machine: default INFO machine: -
Provider: VagrantPlugins::ProviderVirtualBox::Provider INFO machine:
- Box: # INFO machine: - Data dir: /Users/YOUR_HOME_DIR/Workspace/Homestead/.vagrant/machines/default/virtualbox
Data dir, is the path which is interesting for you.
Then vboxmanage list vms
"homestead" {0e8438b9-4a67-4fb1-80cb-2c62cf04ab5c}
"settler_default_1447385930122_73498_1474294682778_13108"
{93ecb93f-f159-4406-a384-5312b4d3ab34}
Edit id file, in the path which you found out in the previous command
vi /Users/YOUR_HOME_DIR/Workspace/Homestead/.vagrant/machines/default/virtualbox/id
Replace content of that file, with the id of the VM you want to fix, in this scenario it is
0e8438b9-4a67-4fb1-80cb-2c62cf04ab5c
Now try
homestead up
VM should start booting. It might work, or you might have issues with ssh authentication
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Authentication failure. Retrying... default: Warning: Authentication failure. Retrying...
To fix that do following
Check Homestead SSH config
homestead ssh-config
You should get something like
Host default HostName 127.0.0.1 User vagrant Port 2222
UserKnownHostsFile /dev/null StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile
"/Users/pryznar/.vagrant.d/insecure_private_key"
IdentitiesOnly yes
LogLevel FATAL
Edit IdentityFile file
/Users/YOUR_HOME_DIR/.vagrant.d/insecure_private_key
Check Homestead.yml
cat /Users/YOUR_HOME_DIR/.homestead/Homestead.yaml
Then copy path to the file under the key keys, and copy private key from that file
cat ~/.homestead/ssh/id_rsa
Last step is to replace private key in /Users/YOUR_HOME_DIR/.vagrant.d/insecure_private_key with the one you just copied
Now try rung homestead again, should work.
homestead up
I got some warnings, but so far it works without issues
==> default: Warning: Using a password on the command line interface can be insecure.
==> default: ERROR 1045 (28000): Access denied for user 'homestead'#'localhost' (using password: YES) The SSH command
responded with a non-zero exit status. Vagrant assumes that this means
the command failed. The output for this command should be in the log
above. Please read the output to determine what went wrong.
You can open the VirtualBox GUI and remove the conflicting virtual machine.
None of this worked for me. I was using an old dev machine
I attempted:
vagrant global-status > destroy any by id which you don't need or match what is conflicting
open virtualbox and remove + delete files for any which you don't need or are conflicting
What worked:
locate your ~/.vagrant/machines/ or ~/.vagrant.d/boxes folder. In my case, it contained the conflicting vm and also a bunch of old left over vm machines which steps 1 & 2 did not remove for some reason.
after clearing these, everything worked fine again, finally!
Windows10
Edit Homestead.yaml file and give a new name for the box:
ip: "192.168.10.10"
memory: 2048
cpus: 2
provider: virtualbox
name: my-new-vbox #new name for the box
and run vagrant up or vagrant up --provision
Or
Open Virtualbx application in GUI and delete all the virtualbox that was causing problem and run the above command
Or
Delete the "Vagrant" file inside homestead folder and run the above command.
I had the following error:
Error:
A VirtualBox machine with the name 'homestead-7' already exists.
Please use another name or delete the machine with the existing
name, and try again.
Solution:
Find the VirtualBox VMS folder, in my case it was in ~/VirtualBox VMs
List the elements in the folder with ls command, and review if the virtual machine is there
Delete the folder with the name of the machine, in my case homestead-7
Re-execute the vagrant up command in the homestead folder
That's all, I hope it's helpful, that was my solution.
Regards!
In my case the following article provide the solution. There was a folder named homestead inside the path /var/root/VirtualBox VMs/ that was causing the issue. Once this folder was removed, rm -r homestead, the issue was resolved. If you can not see or have access to this path execute the following commands in your terminal windows:
$ sudo -s
$ cd /var/root/VirtualBox\ VMs
And proceed to delete the homestead folder.
Add --force after box, and before your given name.
Renaming an already existing default VM
Disclaimer
The following procedure will destroy your VM and may be only suiteable in a desting-environment like mine! For production environments, consider to repair the association like described here
I had this problem after overriding the default name of an already existing VM by using
Vagrant.configure("2") do |config|
config.vm.define :ubuntu_test
where the VirtualBox name was also set (as a newbie I assumed that Vagrand will use this name too)
config.vm.provider "virtualbox" do |vb|
vb.name = "Ubuntu-Test"
end
By adding config.vm.define it seems that Vagrant doesn't associate the VirtualBox VM any more with the Vagrant file since even vagrant destroy -f say VM not created but vagrant up throw this error
A VirtualBox machine with the name 'Ubuntu-Test' already exists.
To delete those zombie VM
If the VM is running, stop it first: vboxmanage shutdown <VMName> (Here the name is Ubuntu-Test)
Get the Id by running vboxmanage list vms
Delete it: vboxmanage unregistervm <Id> --delete
Now your VM can be re-created using vagrant up
Using vagrant global-status --prune, your new name is present
For me id file was present in the below-mentioned location.
D:\drupalvm.vagrant\machines\drupalvm\virtualbox
After a few hours of troubleshooting, nothing else worked for me, as no one mentioned this little detail.
Depending on your privileges at the time of installation, you may need to run virtualbox as an administrator. It was only when I did this that I saw my vagrant boxes in the list of virtual machines.
I then proceeded to remove my virtual machine named homestead from virtualbox, and the problem was solved.
If you're using homestead in Windows, just open up your Oracle VM VirtualBox and delete the homestead VM.
The Vagrant relies on VirtualBox (if that's the default provider) so it checks for existing environment first before provisioning your VM.
It is executing the following command:
VBoxManage list vms
and when it finds the VM with the same hostname, so it'll fail.
You can debug it by:
vagrant --debug up
to find out the exact reason.
Solution
If you're planning to use multiple VMs in different folders, then you need to change your config.vm.hostname (possibly config.vm.provider(name) as well) in your Vagrantfile to make it unique. Or simply remove it, so Vagrant will assign a different name for each VM.
If that's not the case, simply shutdown and unregister previous VM which conflicts by running:
VBoxManage controlvm NAMEOFVM poweroff
VBoxManage unregistervm NAMEOFVM --delete
and re-run your vagrant up.
If it fails on directory rename (because you missed --delete), then rename or remove the destination folder, for example:
rm -fr ~/"VirtualBox VMs/NAMEOFVM"
and re-try again.
This problem may be related to: GitHub issue #2969 - vagrant up not detecting a previously run VM
In my case, nothing was indicating that the VM "already exists" besides that error message. Nothing on VirtualBox UI, nothing returned by “vboxmanage list vms”, nothing through “vagrant global-status”, it didn’t exist in “.vagrant.d\boxes” and so on. I resolved it by manually creating a new same-name VM in the VM VirtualBox Manager (using the “new” button + accepting all the defaults), and then removing it (right-click > remove). After that, the “vagrant up” worked as expected.
I had the same issue today. Windows 10. I recently had updated Homestead, so the error was probably because of that. I tried it all, destroy, up, delete folders, whatever. Whenever I tried to run vagrant up, it was showing this kind of errors. The solution? After updating, I noticed that Homestead is now naming the boxes by the project folder name, and Homestead.yaml has all that infos. I just run that Homestead Windows configuration vendor\\bin\\homestead make and later them a vagrant up (before making sure it was all clean) and voilá, looks like the machine is booting now. =) Try that if you need it.
Vagrant's chef-client provisioning fails until after I use RDP into the VM and login as 'vagrant' user for the first time.
The debug output says:
INFO interface: Machine: error-exit ["Berkshelf::VagrantWrapperError", "VagrantPlugins::CommunicatorWinRM::Errors::WinRMBadExitStatus: The following WinRM command responded with a non-zero exit status.\nVagrant assumes that this means thecommand failed!\n\ncmd.exe /c install.bat 11.16.4\n\nStdout from the command:\n\nDownloading Chef 11.16.4 for Windows...\r\nInstalling Chef 11.16.4\r\n\n\nStderr from the command:\n\n"]
Ideally, I could "vagrant destroy" and "vagrant up" back to back without any other steps necessary.
How can I work around this?
I am using:
Vagrant 1.6.5
Chef 11.16.4
Windows 8 (kensykora/windows_81)
Windows 2012 (kensykora/windows_2012_r2_standard)
You could set up the vagrant user to auto-login:
https://technet.microsoft.com/en-us/magazine/ee872306.aspx
Then you can package the modified box instance and use the new box from there on:
http://docs.vagrantup.com/v2/cli/package.html
I have a Vagrant VM standard issue lucid32.box running. What would the complete instructions be to set up LAMP on this?
I have looked at knife (part of chef) and attempted:
vagrant#lucid32:~$ knife cookbook site install apache2
but got
WARNING: No knife configuration file found
How do I set up a knife configuration file and what should I have in it?
I've been doing a lot of searching online for answers but am overwhelmed by partial solutions that don't explain their starting point/pre-requisites.
Update
I will aim to answer this myself as no-one else seems to want to. Here is my current understanding - I aim to address my unknowns/questions in red later.
OK, I've decided to answer this fully for myself as the original question poster. (Thanks to everyone who contributed prior.)
End-to-end setup of LAMP VM on a Windows 64-bit host using Vagrant and Oracle VirtualBox
I asked this question originally because although there are plenty of instructions and guides on the web, what they don’t seem to do is:
Clearly define a starting point and what the prerequisites are
Give instructions for those, like me, in corporate environments that have a capable Windows machine to host the VM. Instead they assume a Linux-based host machine.
Be clear on where the files being set up are: On the host? On the guest OS? (This is especially difficult to determine if both the host and guest OS are both Linux or Unix-based - the command line snippets shown don’t give clues obviously as they all look the same.)
State which version of Vagrant is used. There are two (2) main versions: API version 1 which is all releases before (but NOT including) v1.1.0. The other is API version 2 - which is releases from v1.1.0 onwards. So the versioning convention is similar to Java. This API version is important as, for example, v1 API scripts simply won't work on API v2 of the Vagrant software unless a clause is put at the beginning of the script to state which version to use.
Personally I think the Vagrant versioning convention could be simpler. NOTE: This guide here is for Vagrant 1. I am told that version 1 has a wide established installed base, while Vagrant 2 was still in draft mid 2013. I therefore like to call version 1 - V1 LTS - Long Term Support - like Ubuntu to show that this is going to be around for a long time yet.
Here is a picture to clarify which API is on which version of the Vagrant software:
For my example setup of using Vagrant here, I would suggest using pre-V1.1.0 (i.e. Vagrant API 1 from the downloads on vagrantup.com) however you ought to be able to use Vagrant 2 API version of the Vagrant software as mentioned above but you'll need to add a 'directive' at the beginning of your scripts to tell Vagrant that they are for Vagrant 1 otherwise the scripts will fail with an error message. TODO: I'll try to get that directive and put it here to help.
(Mitchell Hashimoto, Vagrant creator - please take note of the above for any future editions of your O'Reilly book: Vagrant: Up and Running: http://shop.oreilly.com/product/0636920026358.do)
What these instructions in this answer should do:
Get you a 32-bit Ubuntu Linux OS with a LAMP (Linux OS, Apache web server, MySQL database, PHP) stack running as a Virtual Machine using Oracle VirtualBox on your Windows 7 64-bit machine (or a Mac or Linux machine, but primarily tested on Windows but should work fine on Mac and this solution is meant to be platform-independent). I have tested PHP OK (via standard phpinfo.php file and see that MySQL is running but haven't tested this yet).
Other ways to set up a LAMP stack running on a Vagrant VM
Note: An alternative pretty much out-of-the-box solution for those (like me) who want a LAMP stack with the Drupal open-source content management framework is here: http://drupal.org/project/vagrant
You should be able to follow just my prerequisites below and then download the .zip from the above URL and follow the instructions on there and run vagrant up from the command line to start the VM and wait as it builds and starts (some of this is one-off the first time as once you have the image set up subsequent boots should be faster). You get a lot of other developer stuff 'for free' (i.e. to save you the effort installing them) - like git, drush (I think), and performance profiling tools. Afterwards go to [server address]/install.php to install Drupal. This seems to work well without issue - I've tried it out but not tested it extensively. You might need to disable the install of xhprof if you get an error message - see http://drupal.org/node/1940668 for details.
Another option is to use this configuration tool: https://puphpet.com/
- It's a visual point-and-click method for configuring your Vagrant setup. This works on Vagrant 2 (I think, Update yes, it does, on Vagrant 1.2.2 at least). Update: In fact, I've got this working successfully and based a setup for running Drupal on it locally - see my guide here: https://drupal.org/node/2055947
Update
Here are some other out-of-the-box Vagrant setups that I've found to work well - on Mac and Windows:
https://github.com/mikebell/drupaldev-apache
https://github.com/mikebell/drupaldev-nginx
If you want the Solr search engine locally in your VM as part of your LAMP stack, you may want to look at:
https://github.com/computerminds/parrot
Even though these alternatives are great, my instructions are still of value to help you understand the workings of such setups or if you want a simpler more basic LAMP stack.
Small extras that you need to find out how to do (will try to include them here)
Logging into the machine once set up - this is done via the standard SSH-based login. You will need the free tools putty.exe and puttygen.exe.
At the moment I have not provided how to log in with SSH here but will try to do so in future. You will find references at the end of this answer.
Note that the login will be with the user vagrant.
(After you have followed the setup instructions below) to use the root user you need to 'unlock' the account to be able to reset the password:
Unlock the root account:
vagrant#lucid32:~$ sudo passwd -u root
passwd: password expiry information changed.
Then change the root password:
vagrant#lucid32:~$ sudo passwd root
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
(The password is not shown as you type.)
Test the new password by logging into root with it:
vagrant#lucid32:~$ su root
Password:
root#lucid32:/home/vagrant#
Credit: https://scottlinux.com/2011/07/22/reset-or-change-user-password-in-linux/
(Article: "Reset or Change User Password in Linux" - This helped me work out how to do it.)
Any errors?
Give it a try - add comments to the answer if you have problems and I will try to fix. See also the troubleshooting at the end.
Future tasks
Currently using Puppet. Do it with Chef instead of Puppet, just to widen the ways of working. Both of these are contenders but have different approaches so I believe: With Puppet I am told that you say what you want and Puppet may make some arbitrary decisions to get you there. Whereas with Chef I believe you define the precise sequence of steps. Again - comment here and correct me if necessary,
Prerequisites for these instructions:
Windows 7 64-bit
Installed VirtualBox
Installed Vagrant
Separate installs of Ruby and Puppet are not required as these appear to come with Vagrant. To be honest, I did install these to fix some problems but found out those problems were something else. So I uninstalled Ruby and Puppet and re-ran (vagrant up etc) and it still works so I assume these extra, separate installs of Ruby and Puppet are not required.
Suggested Vagrant and VirtualBox version combination to use: VirtualBox version 4.2.12 and pre-Vagrant 1.2 (as previously discussed). Certain other combinations could work but I haven't tested those, so am sticking with this combination unless I can see clear benefit of using later versions. One top clear benefit would be speed of provisioning. The combination I state here works for the puphpet.com route to setting up a VM at least which is quite complex, and I would therefore assume should work on my simple setup documented here.
(Credit: These instructions are based on:
http://ox86.tumblr.com/post/23734821654/painless-development-environments-with-virtualbox
...but not an exact copy as they did not work for me.)
The instructions
(Ensure you have the prerequisites above.)
The host setup work is done on your host machine in your Windows user folder, for example for me this is C:\Users\rdavis
mkdir lamp-project
cd lamp-project
mkdir configs
cd ..
cd lamp-project
mkdir manifests
(following from: http://docs.vagrantup.com/v1/docs/getting-started/index.html)
Download the distro install image, in this case Ubuntu Lucid (10.04). This image is effectively equivalent to the install disk (CD or DVD) that you would traditionally use to install an OS on a machine.
C:\Users\rdavis\lamp-project>vagrant box add lucid32 http://files.vagrantup.com/lucid32.box
(By the way, there are several other popular distros on vagrantup.com, but if you want to generate the .box file from a distro .ISO then there is a tool called VeeWee to do that: https://github.com/jedi4ever/veewee)
Initialise it:
C:\Users\rdavis\lamp-project>vagrant init lucid32
(Note, I just used vagrant init when writing up these instructions because I had already initialised lucid32, but for the first time, you will have to do the above command.)
C:\Users\rdavis\lamp-project>vagrant init
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
C:\Users\rdavis\lamp-project>
Edit C:\Users\rdavis\lamp-project\Vagrantfile
- insert the following directly after Vagrant::Config.run do |config|
config.vm.box = "lucid32"
config.vm.provision :puppet do |puppet|
puppet.manifests_path = File.expand_path("../manifests", __FILE__)
end
config.vm.forward_port 80, 8080
config.vm.share_folder "configs", "/configs", File.expand_path("../configs", __FILE__)
So your Vagrantfile should look like:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant::Config.run do |config|
config.vm.box = "lucid32"
config.vm.provision :puppet do |puppet|
puppet.manifests_path = File.expand_path("../manifests", __FILE__)
end
config.vm.forward_port 80, 8080
config.vm.share_folder "configs", "/configs", File.expand_path("../configs", __FILE__)
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
# Every Vagrant virtual environment requires a box to build off of.
# config.vm.box = "lucid32"
# (this is already done above, but if you have a box called 'base' which is an Ubuntu lucid32 then you can use: config.vm.box = "base". This info may be helpful if you get error: "The box 'base' could not be found.")
# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
# config.vm.box_url = "http://example.com/path/to/above.box"
# Boot with a GUI so you can see the screen. (Default is headless)
# config.vm.boot_mode = :gui
# Assign this VM to a host-only network IP, allowing you to access it
# via the IP. Host-only networks can talk to the host machine as well as
# any other machines on the same network, but cannot be accessed (through this
# network interface) by any external networks.
# config.vm.network :hostonly, "192.168.33.10"
# Assign this VM to a bridged network, allowing you to connect directly to a
# network using the host's network device. This makes the VM appear as another
# physical device on your network.
# config.vm.network :bridged
# Forward a port from the guest to the host, which allows for outside
# computers to access the VM, whereas host only networking does not.
# config.vm.forward_port 80, 8080
# Share an additional folder to the guest VM. The first argument is
# an identifier, the second is the path on the guest to mount the
# folder, and the third is the path on the host to the actual folder.
# config.vm.share_folder "v-data", "/vagrant_data", "../data"
# Enable provisioning with Puppet stand alone. Puppet manifests
# are contained in a directory path relative to this Vagrantfile.
# You will need to create the manifests directory and a manifest in
# the file base.pp in the manifests_path directory.
#
# An example Puppet manifest to provision the message of the day:
#
# # group { "puppet":
# # ensure => "present",
# # }
# #
# # File { owner => 0, group => 0, mode => 0644 }
# #
# # file { '/etc/motd':
# # content => "Welcome to your Vagrant-built virtual machine!
# # Managed by Puppet.\n"
# # }
#
# config.vm.provision :puppet do |puppet|
# puppet.manifests_path = "manifests"
# puppet.manifest_file = "base.pp"
# end
# Enable provisioning with chef solo, specifying a cookbooks path, roles
# path, and data_bags path (all relative to this Vagrantfile), and adding
# some recipes and/or roles.
#
# config.vm.provision :chef_solo do |chef|
# chef.cookbooks_path = "../my-recipes/cookbooks"
# chef.roles_path = "../my-recipes/roles"
# chef.data_bags_path = "../my-recipes/data_bags"
# chef.add_recipe "mysql"
# chef.add_role "web"
#
# # You may also specify custom JSON attributes:
# chef.json = { :mysql_password => "foo" }
# end
# Enable provisioning with chef server, specifying the chef server URL,
# and the path to the validation key (relative to this Vagrantfile).
#
# The Opscode Platform uses HTTPS. Substitute your organization for
# ORGNAME in the URL and validation key.
#
# If you have your own Chef Server, use the appropriate URL, which may be
# HTTP instead of HTTPS depending on your configuration. Also change the
# validation key to validation.pem.
#
# config.vm.provision :chef_client do |chef|
# chef.chef_server_url = "https://api.opscode.com/organizations/ORGNAME"
# chef.validation_key_path = "ORGNAME-validator.pem"
# end
#
# If you're using the Opscode platform, your validator client is
# ORGNAME-validator, replacing ORGNAME with your organization name.
#
# IF you have your own Chef Server, the default validation client name is
# chef-validator, unless you changed the configuration.
#
# chef.validation_client_name = "ORGNAME-validator"
end
Then, in C:\Users\rdavis\lamp-project\manifests create file default.pp and put in it:
$config_path = "/configs"
$vagrant_base_path = "/vagrant"
Exec { path => "/bin:/usr/bin:/usr/local/bin" }
group { "puppet": ensure => present }
exec { "apt-get update": command => "apt-get update" }
class apache {
exec { "enable-mod_rewrite":
require => Package["apache2"],
before => Service["apache2"],
command => "/usr/sbin/a2enmod rewrite"
}
package { "apache2":
ensure => present
}
service { "apache2":
ensure => running,
require => Package["apache2"]
}
}
class php {
package { "libapache2-mod-php5": ensure => present }
package { "php5": ensure => present }
package { "php5-cli": ensure => present }
package { "php5-dev": ensure => present }
package { "php5-mysql": ensure => present }
package { "php-pear": ensure => present }
exec { "pear upgrade":
command => "/usr/bin/pear upgrade",
require => Package["php-pear"],
}
}
class mysql {
package { "mysql-server":
require => Exec["apt-get update"],
ensure => present,
}
service { "mysql":
enable => true,
ensure => running,
require => Package["mysql-server"],
}
exec { "Set MySQL server root password":
require => Package["mysql-server"],
unless => "/usr/bin/mysqladmin -uroot -proot status",
command => "/usr/bin/mysqladmin -uroot password root",
}
}
include apache
include php
include mysql
(Helpful note (optional), my above versions of Vagrantfile and default.pp (and other Vagrant ancilliary files and folder structure) are available from my GitHub repository, VagrantVMSetups, at: https://github.com/therobyouknow/VagrantVMSetups
- See the justlamp folder - this is the same as the contents of lamp-project used in this answer.)
Then run Vagrant:
C:\Users\rdavis\lamp-project>vagrant up
Note that this can take a while (5-15 minutes) - but bear with it. It should now successfully run a LAMP VM. Then you have finished with the VM in your current work task. If you then keep the VM for use at a later time but shut it down using vagrant halt (rather than vagrant destroy to delete the VM image) then I would expect this delay to be a one-off initial setup time. Subsequent startups of the VM (using vagrant up) should be faster I would think.
Troubleshooting:
Troubleshooting Problem 1: Bad/illegal quotes used - error message seen on host machine after running vagrant up
Background: this happened to me because I pasted in the code snippets from the web page where the instructions came from. The code snippet had open-and-close quotes - which aren’t interpreted as proper quotes by the interpreter/parser that Vagrant uses (or indeed by most script interpreters and compilers I would think.)
Symptom:
output like this:
There is a syntax error in the following Vagrantfile. The syntax error
message is reproduced below for convenience:
C:/Users/rdavis/lamp-project/Vagrantfile:6: invalid multibyte char (US-ASCII)
C:/Users/rdavis/lamp-project/Vagrantfile:6: syntax error, unexpected $end
Or this:
Could not parse for environment production: Could not match ?/configs? at /tmp/vagrant-puppet/manifests/default.pp:1 on node lucid32.hsd1.ca.comcast.net.
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
Or this:
There was an error executing the following command with VBoxManage:
["list", "hostonlyifs"]
Remedy: use proper double quotes “. Don’t use open-and-closing quotes.
Troubleshooting Problem 2: Following error message on host machine after running vagrant up
←[1;35merr: /Stage[main]/Apache/File[/etc/apache2/sites-enabled/000-default]: Could not evaluate: Could not retrieve information from environment production source(s) file:/configs/000-default at /tmp
/vagrant-puppet/manifests/default.pp:11←[0m
Remedy: you shouldn’t see this - the original script used contained references to a path containing 000-default. I just removed all lines and constructs referring to it.
Troubleshooting Problem 3: PHP files are treated as downloads (download of file occurs in browser) rather than being executed and displayed.
PHP needs enabling on the guest VM machine.
Remedy: you may or may not need to do this.
This tip worked: (to enable PHP and stop the file being seen as a download):
https://serverfault.com/questions/243435/getting-php-to-work-with-apache-to-run-php-files-through-browser
vagrant#lucid32:/etc/php5/cli$ a2enmod php5
Module php5 already enabled
vagrant#lucid32:/etc/php5/cli$ sudo apache2ctl restart
Another tip:
PHP needs enabling, suggestion in:
http://galleryproject.org/node/55011
is:
edit php.ini
These are shared extensions (.so files). You need to enable them in php.ini and then restart PHP.
Myself, I didn’t need to edit php.ini after all. By the way, this is at: /etc/php5/cli/php.ini for this lucid32 VM.
Troubleshooting Problem 4: Addressing the VirtualBox additions warning message about version mismatch
[default] The guest additions on this VM do not match the install version of
VirtualBox! This may cause things such as forwarded ports, shared
folders, and more to not work properly. If any of those things fail on
this machine, please update the guest additions and repackage the
box.
Guest Additions Version: 4.2.0
VirtualBox Version: 4.2.4
Not a problem it seems (it doesn’t stop the VM from running successfully), but if you wish to address it:
http://automation.binarysage.net/?p=1198
https://unix.stackexchange.com/questions/58216/automate-installation-of-virtualbox-guest-additio
ns-via-command-line
https://serverfault.com/questions/243435/getting-php-to-work-with-apache-to-run-php-files-through-browser
(for Linux-like users: http://www.pauloamgomes.net/blog/installing-vagrant)
Troubleshooting problem 5: The box 'base' could not be found." error message seen after running vagrant up.
Remedy? Check the line containing the statement config.vm.box = etc. in your Vagrantfile (see my example Vagrantfile above) to ensure that it is referring to a Vagrant box (the OS install image) that actually exists on your system - issue command vagrant box list to see what boxes you have.
If you have followed my instructions then you should have the lucid32 box. Make sure that there are no extraneous config.vm.box = etc. statements in your Vagrantfile. Confession: there was an extraneous config.vm.box = "base" in my Vagrantfile when actually a few lines above, config.vm.box = "lucid32" was already done. I have now corrected this.
FAQ
Q: What is a Vagrant box? A: Can be considered equivalent to an OS install disk in that it is the basis, the starting point for a VM - it’s the OS. It’s a binary file.
Q: What is a Vagrant package? A: A snapshot of the VM plus the configuration that Vagrant has performed from the VagrantFile provides a self-contained means to distribute the setup to other people.
References:
General Vagrant resources:
What exactly do the Vagrant commands do?
- nice description
http://community.opscode.com/questions/81
http://deanstrezovski.com/setting-up-a-cagrant-lamp-stack/
http://www.jasongrimes.org/2012/06/managing-lamp-environments-with-chef-vagrant-and-ec2-1-of-3/
How do I associate a Vagrant project directory with an existing VirtualBox VM?
http://docs.vagrantup.com/v1/docs/getting-started/index.html
More on Vagrant Boxes:
http://docs.vagrantup.com/v1/docs/boxes.html
Where is Vagrant saving changes to the VM?
SSH key-based logins (logging into the VM box externally - i.e. from the host machine or from another machine):
http://www.howtoforge.com/ssh_key_based_logins_putty_p2
http://docs.vagrantup.com/v1/docs/getting-started/ssh.html
http://en.wikipedia.org/wiki/Ssh-agent
For Windows SSH-based login to the VM:
PuTTY: a free telnet/ssh client
www.chiark.greenend.org.uk/~sgtatham/putty/
puttygen:
www.chiark.greenend.org.uk/~sgtatham/putty/download.html
Version history/updates of this answer
Signposting and headings clean-up
Added running vagrant up and that it can take a while
Added how to set the root password in the VM
Added missing step to download and init the lucid32 box (equivalent to the install disk)
Added link to my https://github.com/therobyouknow/VagrantVMSetups GitHub repo that contains the Vagrant config setup for this answer - for convenience.
Altered Vagrantfile to remove the extraneous config.vm.box = "base" when actually a few lines above, config.vm.box = "lucid32" was already done. This will help if you encounter the error The box 'base' could not be found." Also added a new troubleshooting item explaining the same.
Added alternative out-of-the-box solution for those wanting a Drupal-based LAMP VM: http://drupal.org/project/vagrant see more notes above on this.
2013-07-10: slight grammar adjustment to reasons for writing this guide. Updated that the Vagrant book from O'Reilly is now published. Added link to https://puphpet.com/ - online Vagrant configurator script generator (very nice!). Added link to VeeWee tool which is used to generate a Vagrant .box file from any .ISO Linux distribution (standard install disc)
2013-10-14 Updated "what they don't seem to do" bullets with points on which Version of Vagrant - this guide uses Vagrant 1 (and why). Stated Vagrant 2 used with puphpet.com also link to my documentation using puphpet.com to set up a Vagrant VM for Drupal.
2013-10-21 Updated to state combination of VirtualBox version and Vagrant to use: VirtualBox version 4.2.12 and Vagrant 1.2.2. Certain other combinations could work but I haven't test those, so am sticking with this combination unless I can see clear benefit of using later versions. One top clear benefit would be speed of provisioning. Put heading on other approaches to Vagrant VM section. Updated to say this and other solutions are platform independent and should work on PC, Mac or Linux.
2013-10-23 updates on what Vagrant version to use for this guide (i.e. pre v1.2 (that's pre Vagrant 2)) and for another approach, puphpet.com (v1.2.2 - which by contrast is a Vagrant 2 release.)
2013-12-03 corrected notes of Vagrant API versioning and what API version is in which Vagrant software version. Added some more alternative, comprehensive Vagrant setups.
In your VM, you need to run:
$knife configure
Accept all the defaults.
After you have run this, there will be a configuration file in your ~/.chef/knife.rb.
As for your diagram:
The vagrant folder contains the Vagrantfile for that project. The actual .ovf and .vmdk files, along with another Vagranfile, exists in /%USERPROFILE%/.vagrant.d/
The Vagranfile is the configuration file for Vagrant and exists in multiple places with a set order of precedence. The Vagranfile in your project folder takes precedence: Vagrantfile documentation.
Everything can be from localhost, including setting up a more complex Vagrant project with multiple VMs, as such.
EDIT: to make it clear that the 'knife configure' cmd should be run in the VM and to remove a spurrious Windows path reference.