简体   繁体   中英

Vagrant + Apache + PHP running extremely slowly on Windows

I have a Vagrant VM running Apache and PHP. All requests are routed initially by mod_rewrite.

When a request comes in with anything other than .php, Apache just serves that file directly. This works almost instantaneously both from inside and outside the vagrant VM.

When a request comes in with .php, a couple rewrite conditions are checked and ultimately Apache sends the request to PHP, which loads our Symfony kernel environment and whatnot. I've tried adding exit('test'); to the very first line of that kernel bootstrapping file, so response should be as fast as possible. Literally all that's happening is Apache is sending the request to PHP which is exiting immediately. From inside the VM, this executes almost instantaneously. From the host machine this results in 10+ minute load times.

Also, everything works perfectly on OS X, and the exact same setup works fine on a different Windows machine. I've tried reinstalling/rebuilding pretty much every part of the technology that's driving this to no avail.

So what the heck? There's something different between requesting PHP vs. non-PHP content from the VM, but that difference only exists when the request comes from outside the VM.. and only on a specific Windows machine.

I'm absolutely stumped. Any ideas?

I've had a very slow site in vagrant become perfectly usable by switching from the virtualbox provider to the vmware one.

This is a somewhat expensive solution though, as you should definitely NOT install the trial version of vmware because it doesn't play nicely with the vagrant vmware plugin (follow the official instructions to uninstall vmware then reinstall the full version after purchasing).

Also the vagrant vmware plugin is a separate purchase from hashicorp. In my experience they're definitely worth it though. Would you pay a total of 100 bucks or so for an easy life?

Alternative things to try before splashing out.

Explicitly specify the resources for the vm in your Vagrantfile and use private_network instead of port forwarding. Allow 1/4 of your system ram for the virtual machine. Don't use an ip address that's already being used on your system. It should work fine as shown below.

Vagrant.configure(2) do |config|
  config.vm.box = "lattice/ubuntu-trusty-64"
  config.vm.network "private_network", ip:"192.168.50.4"

  config.vm.provider "virtualbox" do |v|
    v.memory = 2048
    v.cpus = 2
  end
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM