Apache,问题无法启动LSB:Apache2 Web服务器

我使用Ubuntu 16.02。 当我尝试sudo service apache2 restart ,它说:

 Job for apache2.service failed because the control process exited with error code. See "systemctl status apache2.service" and "journalctl -xe" for details. 

然后我输入: journalctl -xe ,并请求:

 -  
 - 单位apache2.service已经开始启动。
 1月11日02:30:46 aleksandr-VirtualBox apache2 [8177]:/etc/init.d/apache2:1:/ etc / apache2 / envvars:envvars:not found
 1月11日02:30:46 aleksandr-VirtualBox apache2 [8177]:/etc/init.d/apache2:49:/ etc / apache2 / envvars:envvars:not found
 1月11日02:30:46 aleksandr-VirtualBox apache2 [8177]:/etc/init.d/apache2:1:/ etc / apache2 / envvars:envvars:not found
 1月11日02:30:46 aleksandr-VirtualBox apache2 [8177]:/etc/init.d/apache2:49:/ etc / apache2 / envvars:envvars:not found
 1月11日02:30:46 aleksandr-VirtualBox apache2 [8177]:*启动Apache httpd web服务器apache2
 1月11日02:30:46 aleksandr-VirtualBox apache2 [8177]:*
 1月11日02:30:46 aleksandr-VirtualBox apache2 [8177]:* apache2 configtest失败。
 1月11日02:30:46 aleksandr-VirtualBox apache2 [8177]:配置测试的输出是:
 1月11日02:30:46 aleksandr-VirtualBox apache2 [8177]:/ usr / sbin / apache2ctl:1:/ etc / apache2 / envvars:envvars:not found
 1月11日02:30:46 aleksandr-VirtualBox apache2 [8177]:/ usr / sbin / apache2ctl:49:/ etc / apache2 / envvars:envvars:not found
 1月11日02:30:46 aleksandr-VirtualBox apache2 [8177] :( 2)没有这样的文件或目录:AH02291:无法访问目录'/ etc / apache2 / logs /'主错误日志
 1月11日02:30:46 aleksandr-VirtualBox apache2 [8177]:AH00014:配置检查失败
 1月11日02:30:46 aleksandr-VirtualBox apache2 [8177]:操作'configtest'失败。
 1月11日02:30:46 aleksandr-VirtualBox apache2 [8177]:Apache错误日志可能包含更多信息。
 1月11日02:30:46 aleksandr-VirtualBox systemd [1]:apache2.service:控制进程退出,代码=退出状态= 1
 1月11日02:30:46 aleksandr-VirtualBox sudo [8171]:pam_unix(sudo:session):用户root会话已关闭
 1月11日02:30:46 aleksandr-VirtualBox systemd [1]:无法启动LSB:Apache2 Web服务器。
 - 主题:单位apache2.service失败
 - 定义者:systemd
 - 支持:http://lists.freedesktop.org/mailman/listinfo/systemd-devel
 -  
 - 单位apache2.service失败了。
 -  
 - 结果失败了。
 1月11日02:30:46 aleksandr-VirtualBox systemd [1]:apache2.service:单位进入失败状态。
 1月11日02:30:46 aleksandr-VirtualBox systemd [1]:apache2.service:结果'exit-code'失败。
 1月11日02:33:09 aleksandr-VirtualBox dhclient [792]:enp0s8到192.168.56.100端口67的DHCPREQUEST为192.168.56.101(xid = 0x204f076f)
 1月11日02:33:09 aleksandr-VirtualBox dhclient [792]:192.168.56.100的DHCPACK为192.168.56.100
 1月11日02:33:09 aleksandr-VirtualBox NetworkManager [619]:[1484073189.4253]地址192.168.56.101
 1月11日02:33:09 aleksandr-VirtualBox NetworkManager [619]:[1484073189.4260] plen 24(255.255.255.0)
 1月11日02:33:09 aleksandr-VirtualBox NetworkManager [619]:[1484073189.4266]服务器标识符192.168.56.100
 1月11日02:33:09 aleksandr-VirtualBox NetworkManager [619]:[1484073189.4273]租期1200
 1月11日02:33:09 aleksandr-VirtualBox NetworkManager [619]:[1484073189.4279] dhcp4(enp0s8):状态更改绑定 - >绑定
 1月11日02:33:09 aleksandr-VirtualBox dbus [590]:[system]通过systemd激活:service name ='org.freedesktop.nm_dispatcher'init ='dbus-org.freedesktop.nm-dispatcher.service'
 1月11日02:33:09 aleksandr-VirtualBox systemd [1]:启动网络管理器脚本调度程序服务...
 - 主题:单位NetworkManager-dispatcher.service已开始启动
 - 定义者:systemd
 - 支持: 
 -  
 -  Unit NetworkManager-dispatcher.service已经开始启动。
 1月11日02:33:09 aleksandr-VirtualBox dhclient [792]:绑定到192.168.56.101  - 在559秒内更新。
 1月11日02:33:09 aleksandr-VirtualBox dbus [590]:[system]成功激活了服务'org.freedesktop.nm_dispatcher'
 1月11日02:33:09 aleksandr-VirtualBox systemd [1]:启动网络管理器脚本调度程序服务。
 - 主题:单位NetworkManager-dispatcher.service已完成启动
 - 定义者:systemd
 - 支持: 
 -  
 - 单元NetworkManager-dispatcher.service已完成启动。
 -  
 - 启动结果完成。
 1月11日02:33:09 aleksandr-VirtualBox nm-dispatcher [8205]:req:1'dhcp4-change'[enp0s8]:新请求(1个脚本)
 1月11日02:33:09 aleksandr-VirtualBox nm-dispatcher [8205]:req:1'dhcp4-change'[enp0s8]:开始运行有序脚本...

并且当systemctl status apache2.service它是真实的:

 * apache2.service  -  LSB:Apache2 Web服务器
   已加载:已加载(/etc/init.d/apache2;错误;供应商预设:已启用)
   Drop-In:/lib/systemd/system/apache2.service.d
            `-apache2-systemd.conf
   活动:自2017-01-11 02:30:46 +08之后失败(结果:退出代码);  33分钟前
     文档:man:systemd-sysv-generator(8)
  进程:8023 ExecStop = /etc/init.d/apache2 stop(code = exited,status = 0 / SUCCESS)
  进程:2236 ExecReload = /etc/init.d/apache2 reload(code = exited,status = 0 / SUCCESS)
  进程:8177 ExecStart = / etc / init.d / apache2 start(code = exited,status = 1 / FAILURE)

 1月11日02:30:46 aleksandr-VirtualBox apache2 [8177]:/ usr / sbin / apache2ctl:1:/ etc / apache2 / envvars:envvars:not found
 1月11日02:30:46 aleksandr-VirtualBox apache2 [8177]:/ usr / sbin / apache2ctl:49:/ etc / apache2 / envvars:envvars:not found
 1月11日02:30:46 aleksandr-VirtualBox apache2 [8177] :( 2)没有这样的文件或目录:AH02291:无法访问目录'/ etc / apache2 / logs /'主错误日志
 1月11日02:30:46 aleksandr-VirtualBox apache2 [8177]:AH00014:配置检查失败
 1月11日02:30:46 aleksandr-VirtualBox apache2 [8177]:操作'configtest'失败。
 1月11日02:30:46 aleksandr-VirtualBox apache2 [8177]:Apache错误日志可能包含更多信息。
 1月11日02:30:46 aleksandr-VirtualBox systemd [1]:apache2.service:控制进程退出,代码=退出状态= 1
 1月11日02:30:46 aleksandr-VirtualBox systemd [1]:无法启动LSB:Apache2 Web服务器。
 1月11日02:30:46 aleksandr-VirtualBox systemd [1]:apache2.service:单位进入失败状态。
 1月11日02:30:46 aleksandr-VirtualBox systemd [1]:apache2.service:结果'exit-code'失败。

怎么了? 中断在哪里? 请帮忙!

有两个错误:


1.由于某种原因,您的/etc/apache2/envvars缺失:

  • 来自journalctl -xe

     Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: /etc/init.d/apache2: 1: /etc/apache2/envvars: envvars: not found Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: /etc/init.d/apache2: 49: /etc/apache2/envvars: envvars: not found Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: /etc/init.d/apache2: 1: /etc/apache2/envvars: envvars: not found Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: /etc/init.d/apache2: 49: /etc/apache2/envvars: envvars: not found ... Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: /usr/sbin/apache2ctl: 1: /etc/apache2/envvars: envvars: not found Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: /usr/sbin/apache2ctl: 49: /etc/apache2/envvars: envvars: not found 
  • 来自systemctl status apache2.service

     Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: /usr/sbin/apache2ctl: 1: /etc/apache2/envvars: envvars: not found Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: /usr/sbin/apache2ctl: 49: /etc/apache2/envvars: envvars: not found 

在我的系统中,此文件具有下一个权限:

 $ ls -l /etc/apache2/envvars -rw-r--r-- 1 root root 1782 мар 19 2016 envvars 

它的内容( $ cat /etc/apache2/envvars )是:

 # envvars - default environment variables for apache2ctl # this won't be correct after changing uid unset HOME # for supporting multiple apache2 instances if [ "${APACHE_CONFDIR##/etc/apache2-}" != "${APACHE_CONFDIR}" ] ; then SUFFIX="-${APACHE_CONFDIR##/etc/apache2-}" else SUFFIX= fi # Since there is no sane way to get the parsed apache2 config in scripts, some # settings are defined via environment variables and then used in apache2ctl, # /etc/init.d/apache2, /etc/logrotate.d/apache2, etc. export APACHE_RUN_USER=www-data export APACHE_RUN_GROUP=www-data # temporary state file location. This might be changed to /run in Wheezy+1 export APACHE_PID_FILE=/var/run/apache2/apache2$SUFFIX.pid export APACHE_RUN_DIR=/var/run/apache2$SUFFIX export APACHE_LOCK_DIR=/var/lock/apache2$SUFFIX # Only /var/log/apache2 is handled by /etc/logrotate.d/apache2. export APACHE_LOG_DIR=/var/log/apache2$SUFFIX ## The locale used by some modules like mod_dav export LANG=C ## Uncomment the following line to use the system default locale instead: #. /etc/default/locale export LANG ## The command to get the status for 'apache2ctl status'. ## Some packages providing 'www-browser' need '--dump' instead of '-dump'. #export APACHE_LYNX='www-browser -dump' ## If you need a higher file descriptor limit, uncomment and adjust the ## following line (default is 8192): #APACHE_ULIMIT_MAX_FILES='ulimit -n 65536' ## If you would like to pass arguments to the web server, add them below ## to the APACHE_ARGUMENTS environment. #export APACHE_ARGUMENTS='' ## Enable the debug mode for maintainer scripts. ## This will produce a verbose output on package installations of web server mod ules and web application ## installations which interact with Apache #export APACHE2_MAINTSCRIPT_DEBUG=1 

你可以手动创建它: sudo nano /etc/apache2/envvars ,粘贴上面的内容,保存ctrl + o并退出ctrl + x


2.在您的系统中,文件夹/etc/apache2/logs也缺失:

  • 来自journalctl -xe

     Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: (2)No such file or directory: AH02291: Cannot access directory '/etc/apache2/logs/' for main error log 
  • 来自systemctl status apache2.service

     Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: (2)No such file or directory: AH02291: Cannot access directory '/etc/apache2/logs/' for main error log 

这不是默认日志文件夹,它是在自定义配置中定义的,必须创建:

 $ sudo mkdir /etc/apache2/logs 

我删除了站点中的.conf文件,但没有删除启用站点的链接文件。

现在我删除了已启用网站的所有文件

重启apache2服务器(sudo service apache2 restart)

为我工作

希望这可能有助于某人:)

试试这些命令:

 sudo a2dismod mpm_event sudo a2enmod mpm_prefork 

然后重启apache2服务。

我有同样的问题。 我在sudo service apache2 restart遇到了同样的错误并运行了sudo systemctl status apache2.service并且红线Failed to start LSB: Apache2 web server.

运行波纹管命令:

 sudo apache2ctl configtest 

它会检查错误(我认为是语法错误)然后你可以调试错误。