2

Ubuntu 16.04 running on a vagrant virtual machine on a Windows 8.1 host.

My xdebug.ini file is symlinked to a directory that's shared with the host machine. (This is so I can create new machines and have xdebug.ini set up how I want, and and edits I make to it are always available on the Windows host - I don't have to worry about backing up configurations from the VM)

It seems like the directory is mounted after apache has been started during boot. So I always have to restart apache to load xdebug.

Can I make it so that apache starts after the shared directory is mounted? Or automatically restart apache after startup, so I don't have to do it manually?

1 Answer 1

2

Ok, so I figured out an answer. I'm not super familiar with manipulating the linux boot sequence and even though this is a vagrant machine, I didn't want to break it.

So I found a vagrant solution for my problem.

I just added this bash script, startup.sh, to the virtual machine in a directory shared with the host:

#!/usr/bin/env bash

systemctl restart apache2

Then I modified my Vagrantfile to add the following line:

config.vm.provision :shell, path: "startup.sh", run: "always"

Or, you could skip the separate bash script and run it inline in the Vagrantfile as Karl suggested in the comments:

config.vm.provision :shell, inline: 'systemctl restart apache2', run: 'always'

So, now my VM restarts Apache after boot, and everything works as I wanted it to.

5
  • 2
    I was going to make that exact recommendation based on reading your question. Good solution! I would have recommended an inline script rather than a separate file, since it is a one-liner: config.vm.provision :shell, inline: 'apache2ctl restart', run: 'always' Jul 22, 2019 at 18:27
  • @KarlWilbur good point about ‘inline’. Thanks! Jul 22, 2019 at 18:42
  • 1
    Great idea to run it inline. To get it to work, I had to add this: config.vm.provision :shell, inline: 'sudo systemctl restart apache2', run: 'always'
    – Zeth
    Apr 4, 2022 at 7:32
  • @Zeth yes, ‘systemctl’ is the new way to do that in Ubuntu. Updated my answer. I think ‘sudo’ is unnecessary because all the setup is run as root but let me know if I’m mistaken. Apr 4, 2022 at 7:41
  • 1
    You're right! sudo is not necessary (I just tested it). --- In case someone else 'suffers' from the same issue as me, then I got here, when trying to fix this issue for a Vagrant-box. Read more details and solution attempts here: askubuntu.com/questions/1400332/…
    – Zeth
    Apr 4, 2022 at 8:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .