Apache 无法在 Vagrant 上启动 [英] Apache fails to start on Vagrant

查看:28
本文介绍了Apache 无法在 Vagrant 上启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Vagrant 环境中,我有一个带有默认设置的 LAMP 的来宾 Ubuntu Virtualbox.

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

我在主机上的源代码与我的 Vagrantfile 位于同一文件夹中.因此,在来宾 Ubuntu 上,我可以像这样访问已安装的 /vagrant 目录中的文件

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

现在在我的 Apache 配置中添加一行

Now in my Apache config I add a line

Alias /mysite /vagrant/mysite

重新加载配置并重新启动 apache 后,我可以转到 localhost:8558/mysite/index.php 并且它可以工作.

After reloading config and restarting apache I can go to localhost:8558/mysite/index.php and it works.

问题是,当我使用 vagrant reload 重新加载 Virtualbox 时,它会在安装 /vagrant 文件夹之前 启动 Apache 服务.所以 Apache 找不到别名目录并且无法启动.我必须手动启动它然后

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

我的问题是 - 有没有办法延迟 Apache 启动,使其在安装后启动?

My question is - is there a way to delay Apache start so that it starts after the mounting?

更新: 作为一种解决方法,我向 crontab 添加了脚本,该脚本在启动后 30 秒启动 apache,如此处.但我想知道是否有更好的解决方案.

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.

推荐答案

如果安装了 upstart(如在 Ubuntu 中),Vagrant 会发出vagrant-mounted"事件.请参阅 https://serverfault.com/a/568033/179583 了解这个想法.在您的脚本中,您可以(重新)启动 Apache 服务器.

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.

顺便说一句,我有一种感觉,较新的 Apache 版本只是发出警告,但即使文档根目录不存在,它仍然会启动.与nginx相同.

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.

这篇关于Apache 无法在 Vagrant 上启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆