apache MacPorts Apache2 在启动时停止启动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2042992/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MacPorts Apache2 Stopped Launching on Boot
提问by Rob Wilkerson
Something that I've noticed recently on two different machines is that Apache2 installed via MacPorts seems to have stopped launching when I boot up. The honest truth is that I can't swear it did so before, but it's something I think I'd notice because installing the LaunchDaemon is part of my install process. In fact, if I try to reload the LaunchDaemon, it fails:
我最近在两台不同的机器上注意到的一点是,当我启动时,通过 MacPorts 安装的 Apache2 似乎已停止启动。诚实的事实是,我以前不能发誓它这样做了,但我想我会注意到这一点,因为安装 LaunchDaemon 是我安装过程的一部分。事实上,如果我尝试重新加载 LaunchDaemon,它会失败:
$ sudo launchctl load -w /Library/LaunchDaemons/org.macports.apache2.plist
org.macports.apache2: Already loaded
Unless I start Apache manually (using sudo apachectl restart), grep'ing for either "apache2" or "httpd" in my process list only produces this:
除非我手动启动 Apache(使用sudo apachectl restart),否则在我的进程列表中对“apache2”或“httpd”进行 grep'ing 只会产生以下结果:
$ sudo ps -ef | egrep "apache2|httpd"
0 52 1 0 0:00.06 ?? 0:00.08 /opt/local/bin/daemondo --label=apache2 --start-cmd /opt/local/etc/LaunchDaemons/org.macports.apache2/apache2.wrapper start ; --stop-cmd /opt/local/etc/LaunchDaemons/org.macports.apache2/apache2.wrapper stop ; --restart-cmd /opt/local/etc/LaunchDaemons/org.macports.apache2/apache2.wrapper restart ; --pid=none
1410639199 6960 6792 0 0:00.00 ttys001 0:00.00 egrep apache2|httpd
1410639199 6960 6792 0 0:00.00 ttys001 0:00.00 egrep apache2|httpd
Looks like the daemon itself is in place, but no executable. As far as I know/can tell, the relevant executables (httpd and apachectl) are executable by everyone.
看起来守护进程本身就位,但没有可执行文件。据我所知/可以告诉,相关的可执行文件(httpd 和 apachectl)是每个人都可以执行的。
Has anyone else noticed this? Any ideas?
有没有其他人注意到这一点?有任何想法吗?
UPDATE
更新
As requested below, I did execute launchctl list. The list is long and I'm not sure how to snip it, but suffice to say that no org.macports.*items are listed. That in itself is interesting because my MySQL daemon is loaded the same way. It works, but also doesn't appear in the list. Let me know if the entire output is really needed.
按照下面的要求,我确实执行了launchctl list. 列表很长,我不知道如何剪断它,但可以说没有org.macports.*列出任何项目。这本身很有趣,因为我的 MySQL 守护程序以相同的方式加载。它有效,但也没有出现在列表中。让我知道是否真的需要整个输出。
UPDATE
更新
I assumed that I had executed launchctl listunder sudo, but prompted by mipadi's comment below, I tried again ensuringthat I did so and I assumed incorrectly. When executed under sudo, the MacPorts items appear:
我假设我是launchctl list在 sudo 下执行的,但是在下面 mipadi 的评论提示下,我再次尝试确保我这样做了,但我假设错误。在 sudo 下执行时,MacPorts 项出现:
51 - org.macports.mysql5
52 - org.macports.apache2
I'm not sure whether that will help, but it's a little more info nonetheless.
我不确定这是否会有所帮助,但还是提供了更多信息。
UPDATE
更新
I've asked a different, but related, question at LaunchDaemons and Environment Variables. I'll update both questions as I learn more.
我在LaunchDaemons 和 Environment Variables 上问了一个不同但相关的问题。随着我了解更多,我会更新这两个问题。
UPDATE
更新
Today, based on mailing list input, I tried using a wildcard home directory. Academically, it's a little more inclusive than I'd like, but the practical reality is that I'm the only one using this computer; certainly the only one who'd have Apache config files laying around.
今天,根据邮件列表输入,我尝试使用通配符主目录。在学术上,它比我想要的更具包容性,但实际情况是我是唯一一个使用这台计算机的人;当然是唯一一个拥有 Apache 配置文件的人。
Include "/Users/*/Dropbox/Application Support/apache/conf.d.osx/*.conf"
Include "/Users/*/Library/Application Support/MacPorts/apache/conf.d/*.conf"
Unfortunately...
很遗憾...
httpd: Syntax error on line 512 of /opt/local/apache2/conf/httpd.conf: Wildcard patterns not allowed in Include /Users/*/Dropbox/Application Support/apache/conf.d.osx/*.conf
采纳答案by Rob Wilkerson
Since I now know whyApache has stopped loading on startup, I'm going to articulate that answer and mark this question as answered. The reason Apache has stopped launching on boot is that I'm trying to share an httpd.conffile across systems. The config file needs to Includefiles from directories that exist within my home directory. Since the home directory is different on each machine, I was trying to reference the ${HOME}environment variable.
既然我现在知道为什么Apache 在启动时停止加载,我将阐明该答案并将此问题标记为已回答。Apache 在启动时停止启动的原因是我正在尝试httpd.conf跨系统共享文件。配置文件需要Include来自我的主目录中存在的目录的文件。由于每台机器上的主目录不同,我试图引用${HOME}环境变量。
This works fine when manually starting after the machine is booted, but fails on startup because the environment variable isn't yet set. As mentioned above, see this questionfor more information.
这在机器启动后手动启动时工作正常,但在启动时失败,因为尚未设置环境变量。如上所述,请参阅此问题以获取更多信息。
回答by voidstin
I found my answer to this problem here:
我在这里找到了这个问题的答案:
https://trac.macports.org/ticket/36101
https://trac.macports.org/ticket/36101
"I apparently fixed this when changing my local dnsmasq config. In /etc/hosts I added my servername (gala) to the loopback entry:
“我显然在更改我的本地 dnsmasq 配置时修复了这个问题。在 /etc/hosts 中,我将我的服务器名(gala)添加到环回条目中:
127.0.0.1 localhost gala
127.0.0.1 本地主机晚会
and then I changed ServerName in /opt/local/apache2/conf/httpd.conf to match:
然后我更改了 /opt/local/apache2/conf/httpd.conf 中的 ServerName 以匹配:
ServerName gala
服务器名称晚会
Apache now starts at boot for me."
Apache 现在对我来说在启动时启动。”
回答by Klaus
Rob:
抢:
Had the same problem: "sudo launchctl load -w ..." started Apache2 while I was logged in, but did not work during startup (the "-w" should have taken care of that). Also, as you noticed, the daemon seems to be registered with launchctl. It will show up with "sudo launchctl list" and another "sudo launchctl load ..." will result in the error message.
I played with "sudo port load apache2" and "sudo port unload apache2", but could not get httpd running on reboot.
In the end, I got rid of the MacPorts startup item: "sudo port unload apache2", checked with "sudo launchctl list" that org.macports.apache2 is no longer registered for startup.
Afterwards, I followed the steps on http://diymacserver.com> Docs > Tiger > Starting Apache. I only had to adapt the path from /usr/local/... to /opt/local/...
有同样的问题:“sudo launchctl load -w ...”在我登录时启动了Apache2,但在启动期间没有工作(“-w”应该已经解决了这个问题)。此外,正如您所注意到的,守护进程似乎已使用 launchctl 注册。它将显示“sudo launchctl list”,另一个“sudo launchctl load ...”将导致错误消息。
我玩过“sudo port load apache2”和“sudo port unload apache2”,但无法在重新启动时运行httpd。
最后去掉了MacPorts的启动项:“sudo port unload apache2”,用“sudo launchctl list”检查,org.macports.apache2不再注册启动。
之后,我按照http://diymacserver.com> Docs > Tiger > 启动 Apache上的步骤操作。我只需要调整从 /usr/local/... 到 /opt/local/... 的路径
Now the MacPorts Apache2 is starting fine with every reboot.
现在 MacPorts Apache2 每次重新启动时都可以正常启动。
Good luck, Klaus
祝你好运,克劳斯
回答by JCobb
I found that my MacPorts apache2 was not starting on boot because of an “error” in my httpd.conf.
我发现我的 MacPorts apache2 没有在启动时启动,因为我的httpd.conf.
I was using
我正在使用
Listen 127.0.0.1:80
Listen 192.168.2.1:80
Listen 123.123.123.123:80 # Example IP, not the one I was really using
And in Console.app I was seeing
在 Console.app 我看到
4/8/12 4:59:06.208 PM org.macports.apache2: (49)Can't assign requested address: make_sock: could not bind to address 192.168.2.1:80
4/8/12 4:59:06.208 PM org.macports.apache2: no listening sockets available, shutting down
4/8/12 4:59:06.208 PM org.macports.apache2: Unable to open logs
I tried adjusting permissions on all the log folders (despite the fact that logs were being written just fine when I manually started apache2) and that didn't help.
我尝试调整所有日志文件夹的权限(尽管当我手动启动 apache2 时日志写得很好),但没有帮助。
Even though the Apache Documentation for Listenclearly states
即使Apache 的 Listen 文档明确指出
Multiple Listen directives may be used to specify a number of addresses and ports to listen to. The server will respond to requests from any of the listed addresses and ports.
可以使用多个监听指令来指定要监听的地址和端口的数量。服务器将响应来自任何列出的地址和端口的请求。
I decided to try switching back to just using
我决定尝试切换回只使用
Listen 80
And after doing so apache2 is starting on boot with no errors or warnings.
这样做之后 apache2 启动时没有错误或警告。
回答by russes
If you're using Subversion with Apache, you may find that Apache is not starting because the mod_dav_svn.so file has moved to /opt/local/libexec. You'll need to adjust your Apache startup files to account for the new location of this file.
如果您将 Subversion 与 Apache 一起使用,您可能会发现 Apache 没有启动,因为 mod_dav_svn.so 文件已移至 /opt/local/libexec。您需要调整 Apache 启动文件以适应此文件的新位置。
回答by Matt S
In newer versions of MacPorts you can run sudo port load apache2to instruct MacPorts to take care of the launchctl setup and automatically start the process. To stop the process run port unload.
在较新版本的 MacPorts 中,您可以运行sudo port load apache2以指示 MacPorts 处理 launchctl 设置并自动启动该过程。停止进程运行port unload。
After loading check /opt/local/apache2/logs/error_logfor errors, including configuration issues.
加载后检查/opt/local/apache2/logs/error_log错误,包括配置问题。
回答by JCobb
In addition to my previous answerI have also found that sometimes Apache fails to start because something else with the system is not yet ready.
除了我之前的回答之外,我还发现有时 Apache 无法启动是因为系统的其他东西尚未准备好。
On one OS X Server machine I also use the DNS to create a “internal only” DNS name for the machine and that name is used in my Apache configuration. Sometimes when Apache tries to start the DNS server is not yet ready and Apache fails to load because the hostname isn't valid.
在一台 OS X Server 机器上,我还使用 DNS 为机器创建“仅限内部”的 DNS 名称,该名称用于我的 Apache 配置。有时,当 Apache 尝试启动 DNS 服务器时,DNS 服务器还没有准备好并且 Apache 无法加载,因为主机名无效。
I have also seen this on other non-Server systems without local DNS as well where something else required by Apache must not be ready yet.
我也在其他没有本地 DNS 的非服务器系统上看到过这种情况,而且 Apache 需要的其他东西还没有准备好。
One thing that has worked is to edit the apache2.wrapperlocated at /opt/local/etc/LaunchDaemons/org.macports.apache2/apache2.wrapperthat MacPorts' daemondouses to start up Apache.
有效的一件事是编辑apache2.wrapper位于/opt/local/etc/LaunchDaemons/org.macports.apache2/apache2.wrapperMacPortsdaemondo用于启动 Apache 的位置。
Edit the Start()function to add a sleepcommand to wait a bit before launching Apache.
编辑该Start()函数以添加sleep命令以在启动 Apache 之前稍等片刻。
Original (Lines 14-17 on my machine)
原始(我机器上的第 14-17 行)
Start()
{
[ -x /opt/local/apache2/bin/apachectl ] && /opt/local/apache2/bin/apachectl start > /dev/null
}
With wait time added
添加等待时间
Start()
{
[ -x /opt/local/apache2/bin/apachectl ] && sleep 10 && /opt/local/apache2/bin/apachectl start > /dev/null
}

