Apache fails to start on Vagrant

后端 未结 3 814
走了就别回头了
走了就别回头了 2021-02-19 16:32

In my Vagrant environment I have a guest Ubuntu Virtualbox with a LAMP with default settings.

I have my source code on the host machine in the same folder as my Vagrantf

相关标签:
3条回答
  • 2021-02-19 16:44

    while upstart probably is a valid option, I had several issues using it with vagrant. I had to run several tasks that needed to be run as a privileged user, which I did not manage to get working with upstart.

    Starting from version 1.6.0 (May 6, 2014), vagrant provides the option to run a specific provisioner every time, so also after booting a halted VM with vagrant up.

    In your Vagrantfile, add:

    # a file, eg after-boot.sh
    config.vm.provision "shell", path: "after-boot.sh", run: "always"
    # or just inline
    config.vm.provision "shell", inline: "service apache2 restart", run: "always"
    

    note the run: "always", this will force vagrant to run the provisioner always, obviously it works just as well with any other provisioning system like chef or puppet.

    0 讨论(0)
  • 2021-02-19 16:48

    If upstart is installed (as in Ubuntu), Vagrant emits "vagrant-mounted" event. See https://serverfault.com/a/568033/179583 to get the idea. In your script you can (re)start the Apache server.

    Btw, I have a feeling that newer Apache versions just warn, but still start even if the doc root doesn't exist. The same with nginx.

    0 讨论(0)
  • 2021-02-19 16:54

    I would like to add a little to Zauberfisch's answer (Apache fails to start on Vagrant)

    What needed to happen was this command needed to be run as a superuser AKA 'Sudo' so this was the command that was needed:

    `config.vm.provision "shell", inline: "sudo service apache2 restart", run: "always"`
    

    The reason why this didn't work for you without the sudo appears to be that Vagrant tries to run the command without /usr/sbin in PATH. For me, this worked just as well:

    `config.vm.provision "shell", inline: "/usr/sbin/service apache2 restart", run: "always"`
    
    0 讨论(0)
提交回复
热议问题