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
.