15

I have successfully installed Vagrant along with some boxes on my Windows PC. I got to say it works awesome, creating and destroying VM's with different configurations on the fly.

The only problem I'm facing now is that I want to install composer. But composer requires you to point to the php.exe to do so. I don't want to install PHP on my computer, otherwhise there is no point using Vagrant, right. How do I tackle this problem?

I've seen some articles about using Puppet, but I couldn't make much sense out of them.

Thanks in advance.

Wouter J
  • 39,482
  • 15
  • 97
  • 108
JasonK
  • 4,654
  • 9
  • 29
  • 58

3 Answers3

24

You just need to install PHP (and curl) in your vagrant box. For instance, execute vagrant ssh to get SSH access to your box and execute the following commands:

$ sudo apt-get install -y php5-cli curl
$ curl -Ss https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/bin/composer

Now you're ready to use the composer command in your vagrant box.

You can improve this by making this part of provisioning, the step where a box is set up when running vagrant up. To do this, put the above commands in a shell file (for instance project/vagrant/provision.sh):

sudo apt-get install -y php5-cli curl > /dev/null
curl -Ss https://getcomposer.org/installer | php > /dev/null
sudo mv composer.phar /usr/bin/composer

Now, configure this shell file as a provision step in your VagrantFile:

Vagrant.configure("2") do |config|

  config.vm.box = "ubuntu/trusty64"

  # configure the shell file as a provision step:
  config.vm.provision :shell, path: "vagrant/provision.sh"

end

Now, when running vagrant init, the shell file is executed and php & composer are installed.

You can also choose to use a box with php and composer pre-installed, like laravel/homestead.

Wouter J
  • 39,482
  • 15
  • 97
  • 108
  • Thanks I got it now. I'm using the homestead box, works perfect. – JasonK Jul 04 '15 at 15:08
  • Thanks. So when we run composer commands in our vagrant box it will reflect the changes on files on my host windows machine as well ? Also how about git? Do we neet to install git on windows host or in the vagrant box ? Thanks again – Raheel Nov 23 '15 at 17:15
0

There is also a vagrant box with composer pre-installed. Here is the Github for this box: https://github.com/Swader/homestead_improved. With Git Bash for windows, navigate to the folder where /homestead_improved was installed.

Run vagrant up;, vagrant ssh to get inside the VM machine.

Once inside the virtual machine cd inside the /Code dir. You can now use composer, for example composer global require "laravel/installer=~1.1" to install the Laravel installer.

  • that's the point my vagrant doesnt have compser pre-installed. what's the use if it doenst have it. why has laravel point us to wrong homestead if this is what they should provide?? PS i havent installed this one yet – Saugat Thapa Apr 05 '17 at 07:09
0

Commands to be followed when you are in vagrant homestead in order to update the composer:

  1. vagrant ssh
  2. cd code (where my laravel projects are)
  3. composer selfUpdate --2 [which means composer selfUpdate --versionnumber]
ganicvp7
  • 19
  • 4