Apache fails to start on Vagrant

apache, apache2, ubuntu, vagrant, virtualbox

Solution

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.

Problem

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 Vagrantfile. So on the guest Ubuntu I can access the files in the mounted `/vagrant` dir like this ``` /vagrant /mysite /index.php /Vagrantfile ``` Now in my Apache config I add a line ``` Alias /mysite /vagrant/mysite ``` After reloading config and restarting apache I can go to `localhost:8558/mysite/index.php` and it works. The problem is that when I reload Virtualbox with `vagrant reload` it starts Apache service before mounting the `/vagrant` folder. So Apache can't find the aliased dir and fails to start. i have to start it manually then My question is - is there a way to delay Apache start so that it starts after the mounting? Update: As a workaround I added script to the crontab that starts apache 30 seconds after the boot as described here. But I wonder if there is a better solution.

Original source