Muneer
Muneer

Reputation: 7564

Provision script in Laravel/Homestead

I wonder how I can include a provision script in Laravel/Homestead that should execute each time the Homestead VM is up.

As a hint, I used to work with Vagrant in following way,

config.vm.provision :shell, path: "bootstrap.sh"

where the bootstrap.sh file is my provision script.

Upvotes: 3

Views: 1024

Answers (2)

Jonathan
Jonathan

Reputation: 1564

I know this is an old post, but its still the #1 result in google for the search "laravel vagrant provisioning script"

In addition to the link provided in the previous answer in the Vagrant Docs, There is also a built-in call to a script in the Vagrant file:

customizationScriptPath = "user-customizations.sh"

...

if File.exist? customizationScriptPath then
    config.vm.provision "shell", path: customizationScriptPath, privileged: false, keep_color: true
end

To use this, simply create a file in the root of your codebase:

user-customizations.sh

This file will be executed on boot up of your Homestead system.

Upvotes: 0

ydaetskcoR
ydaetskcoR

Reputation: 56839

You can always manually force a provision with either vagrant provision or vagrant reload --provision.

To make a every vagrant up automatically call the provisioner then simply define it in your Vagrantfile like so:

Vagrant.configure("2") do |config|
  config.vm.provision :shell, path: "bootstrap.sh",
    run: "always"
end

You can then choose to not run the provisioner by using the vagrant up --no-provision.

The Vagrant docs on this go into a little more detail about what else you can do with provisioners.

Upvotes: 1

Related Questions