在Windows子系统中安装Apache

31

刚刚升级到最新的Windows 10版本(构建版本14316),我立即开始尝试WSL——Windows子系统Linux,它可以在Windows上运行Ubuntu安装程序。

也许我正在尝试不可能的事情,比如在WSL上安装Apache服务器,但是请有人解释一下为什么这不可能。

无论如何,在安装过程中(sudo apt-get install apache2),我在依赖项下载和正确安装后收到了以下错误消息:

initctl: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: No such file or directory
runlevel:/var/run/utmp: No such file or directory
 * Starting web server apache2                                                 *
 * The apache2 configtest failed.
Output of config test was:
mktemp: failed to create directory via template '/var/lock/apache2.XXXXXXXXXX': No such file or directory
chmod: missing operand after '755'
Try 'chmod --help' for more information.
invoke-rc.d: initscript apache2, action "start" failed.
Setting up ssl-cert (1.0.33) ...
Processing triggers for libc-bin (2.19-0ubuntu6.7) ...
Processing triggers for ureadahead (0.100.0-16) ...
Processing triggers for ufw (0.34~rc-0ubuntu2) ...
WARN: / is group writable!
现在,我理解似乎缺少一些文件夹和文件,使得Apache2无法正常工作。在我开始更改任何可能影响我的Windows安装的内容之前,我想问是否有其他方法?另外,我应该担心/是否具有组可写权限,还是这只是标准的Windows行为?

mkdir /var/run/httpd - Fernando Rossato
4个回答

63

为了消除这个警告

Invalid argument: AH00076: Failed to enable APR_TCP_DEFER_ACCEP
将以下内容添加到/etc/apache2/apache2.conf的末尾
AcceptFilter http none

5
这个到底是做什么的? - megamaiku
这正是我在我的情况下所需要的。谢谢! - apaderno
@megamaiku 这是一个警告,详见:https://github.com/microsoft/WSL/issues/1953 - gavenkoa

18

请在您的输出中注意以下内容

failed to create directory via template '/var/lock/apache2.XXXXXXXXXX': No such file 
我尝试列出 /var/lock 目录,它指向 /run/lock,但那个目录不存在。
使用以下命令创建该目录:
mkdir -p /run/lock
安装现在应该可以正常工作(您可能需要先清理安装)。

apache running on Windows Ubuntu


谢谢。我尝试了这个,但仍然出现错误,最明显的是:initctl: 无法连接到Upstart:无法连接到套接字/com/ubuntu/upstart:没有那个文件或目录 [Mon Apr 11 01:30:25.532677 2016] [core:crit] [pid 3046:tid 140694537176960] (22)Invalid argument: AH00069: make_sock: for address [::]:80, apr_socket_opt_set: (IPV6_V6ONLY) (22)Invalid argument: AH00072: make_sock: could not bind to address 0.0.0.0:80 no listening sockets available, shutting down AH00015: 无法打开日志 - bluppfisk
你有没有可能在80端口上有另一个服务器正在监听?我知道这很微不足道,但这种情况发生在最好的人身上。尝试在配置文件中更改监听套接字? - Erez A. Korn
1
你的方案对我有效。但是,我仍然遇到了这两个错误,不过Apache已经启动并运行!:[Tue Apr 12 12:31:22.726611 2016] [core:crit] [pid 979:tid 140694537176960] (22)Invalid argument: AH00069: make_sock: for address [::]:80, apr_socket_opt_set: (IPV6_V6ONLY)和[Tue Apr 12 12:31:22.726611 2016] [core:warn] [pid 979:tid 140694537176960] (22)Invalid argument: AH00076: Failed to enable APR_TCP_DEFER_ACCEPT - Laurens
2
你是对的,Skype正在监听80端口。非常感谢。 - bluppfisk
当本地主机打开IIS本地主机时,您如何在浏览器上查看此Apache上的文件? - indago
显示剩余2条评论

16

为避免与网络相关的很多问题,您必须以管理员模式启动bash.exe。

我已经安装了Lamp(Apache/MySQL/Php),没有任何问题:

  • 以管理员模式启动bash.exe

  • 键入: sudo apt-get install lamp-server^

  • /etc/apache2/apache2.conf中添加以下两行:

Servername localhost

AcceptFilter http none

然后您就可以启动apache了:/etc/init.d/apache2 start


2
谢谢提供的信息。这对我来说甚至不需要管理员模式也可以运行。唯一的区别是,我在安装后立即重新启动了Apache - Maris B.
@MarisB. 完全正确。您需要在安装后立即重新启动服务才能使其正常工作。 - NullPointerException
我尝试使用sudo apt-get install lamp-server,但它无法获取php软件包,似乎没有apache2目录,所以我认为整个过程在无法获取剩余30%的软件包后失败了。404 Not Found [IP:91.189.88.149 80] Err:7 http://security.ubuntu.com/ubuntu bionic-updates/main amd64 php7.2-mysql amd64 7.2.17-0ubuntu0.18.04.1 404 Not Found [IP:91.189.88.149 80] E:无法获取http://security.ubuntu.com/ubuntu/pool/main/p/php7.2/php7.2-common_7.2.17-0ubuntu0.18.04.1_amd64.deb 404 Not Found [IP:91.189.88.149 80] - RiCHiE
E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/p/php7.2/libapache2-mod-php7.2_7.2.17-0ubuntu0.18.04.1_amd64.deb 404 Not Found [IP: 91.189.88.149 80] E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/p/php7.2/php7.2-mysql_7.2.17-0ubuntu0.18.04.1_amd64.deb 404 Not Found [IP: 91.189.88.149 80] E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing? - RiCHiE

4

根据这里提供的大量建议,我编辑了apache2.conf,在所有上述各种错误之后,在文件结尾处插入了以下内容,然后debian wsl软件包上的apache2运行得非常好:

Servername localhost
AcceptFilter http none
AcceptFilter https none

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接