繁体   English   中英

Apache2 不工作

[英]Apache2 is not working

我使用 Linux Mint。 当我尝试重新启动 apache 时显示下一条消息。 apache2.service 的作业失败,因为控制进程退出并显示错误代码。 有关详细信息,请参阅“systemctl status apache2.service”和“journalctl -xe”。 这是显示 systemctl 状态 `apache2.service 的下一个错误 tex

apache2.service - LSB: Apache2 web server
   Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf
   Active: failed (Result: exit-code) since Thu 2018-05-31 14:15:00 EEST; 7min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 20286 ExecStart=/etc/init.d/apache2 start (code=exited, status=2)

May 31 14:15:00 alpha-To-be-filled-by-O-E-M systemd[1]: Starting LSB: Apache2 web server...
May 31 14:15:00 alpha-To-be-filled-by-O-E-M apache2[20286]: ERROR: APACHE_PID_FILE needs to be defined in /etc/apache2/envvars
May 31 14:15:00 alpha-To-be-filled-by-O-E-M systemd[1]: apache2.service: Control process exited, code=exited status=2
May 31 14:15:00 alpha-To-be-filled-by-O-E-M systemd[1]: Failed to start LSB: Apache2 web server.
May 31 14:15:00 alpha-To-be-filled-by-O-E-M systemd[1]: apache2.service: Unit entered failed state.
May 31 14:15:00 alpha-To-be-filled-by-O-E-M systemd[1]: apache2.service: Failed with result 'exit-code'.

这里显示的是journalctl -xe

   `enter code here`-- 
-- Unit flatpak-system-helper.service has begun starting up.
May 31 14:11:23 alpha-To-be-filled-by-O-E-M dbus[923]: [system] Successfully activated service 'org.freedesktop.Flatpak.SystemHelper'
May 31 14:11:23 alpha-To-be-filled-by-O-E-M systemd[1]: Started flatpak system helper.
-- Subject: Unit flatpak-system-helper.service has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit flatpak-system-helper.service has finished starting up.
-- 
-- The start-up result is done.
May 31 14:11:25 alpha-To-be-filled-by-O-E-M ll[18688]: libostree pull from 'flathub' for appstream/x86_64 complete
                                                       security: GPG: summary+commit http: TLS
                                                       non-delta: meta: 1 content: 0
                                                       transfer: secs: 1 size: 569 bytes
May 31 14:11:26 alpha-To-be-filled-by-O-E-M flatpak-system-helper[18716]: libostree pull from 'flathub' for appstream/x86_64 complete
                                                                          security: GPG: summary+commit 
                                                                          non-delta: meta: 1 content: 0
                                                                          transfer: secs: 0 size: 569 bytes
May 31 14:11:34 alpha-To-be-filled-by-O-E-M kernel: [UFW BLOCK] IN=enp2s0 OUT= MAC=01:00:5e:00:00:fb:74:1b:b2:78:93:ac:08:00 SRC=192.168.88.25 DST=224.0.0.251 LEN=32 TOS=0x00 PREC=0x00 TTL=1 ID=62651 PROTO=2 
May 31 14:13:40 alpha-To-be-filled-by-O-E-M sudo[18962]:    alpha : TTY=pts/0 ; PWD=/home/alpha ; USER=root ; COMMAND=/usr/bin/apt-get install lamp-server^ -y
May 31 14:13:40 alpha-To-be-filled-by-O-E-M sudo[18962]: pam_unix(sudo:session): session opened for user root by (uid=0)
May 31 14:13:42 alpha-To-be-filled-by-O-E-M sudo[18962]: pam_unix(sudo:session): session closed for user root
May 31 14:14:35 alpha-To-be-filled-by-O-E-M sudo[20275]:    alpha : TTY=pts/0 ; PWD=/home/alpha ; USER=root ; COMMAND=/bin/nano /var/www/testing.php
May 31 14:14:35 alpha-To-be-filled-by-O-E-M sudo[20275]: pam_unix(sudo:session): session opened for user root by (uid=0)
May 31 14:14:39 alpha-To-be-filled-by-O-E-M kernel: [UFW BLOCK] IN=enp2s0 OUT= MAC=01:00:5e:00:00:fb:74:1b:b2:78:93:ac:08:00 SRC=192.168.88.25 DST=224.0.0.251 LEN=32 TOS=0x00 PREC=0x00 TTL=1 ID=36473 PROTO=2 
May 31 14:14:44 alpha-To-be-filled-by-O-E-M kernel: [UFW BLOCK] IN=enp2s0 OUT= MAC=01:00:5e:00:00:fb:48:43:7c:bd:86:85:08:00 SRC=192.168.88.21 DST=224.0.0.251 LEN=32 TOS=0x00 PREC=0x00 TTL=1 ID=54328 PROTO=2 
May 31 14:14:49 alpha-To-be-filled-by-O-E-M sudo[20275]: pam_unix(sudo:session): session closed for user root
May 31 14:15:00 alpha-To-be-filled-by-O-E-M sudo[20280]:    alpha : TTY=pts/0 ; PWD=/home/alpha ; USER=root ; COMMAND=/usr/sbin/service apache2 restart
May 31 14:15:00 alpha-To-be-filled-by-O-E-M sudo[20280]: pam_unix(sudo:session): session opened for user root by (uid=0)
May 31 14:15:00 alpha-To-be-filled-by-O-E-M systemd[1]: Stopped LSB: Apache2 web server.
-- Subject: Unit apache2.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit apache2.service has finished shutting down.
May 31 14:15:00 alpha-To-be-filled-by-O-E-M systemd[1]: Starting LSB: Apache2 web server...
-- Subject: Unit apache2.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit apache2.service has begun starting up.
May 31 14:15:00 alpha-To-be-filled-by-O-E-M apache2[20286]: ERROR: APACHE_PID_FILE needs to be defined in /etc/apache2/envvars
May 31 14:15:00 alpha-To-be-filled-by-O-E-M systemd[1]: apache2.service: Control process exited, code=exited status=2
May 31 14:15:00 alpha-To-be-filled-by-O-E-M systemd[1]: Failed to start LSB: Apache2 web server.
-- Subject: Unit apache2.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit apache2.service has failed.
-- 
-- The result is failed.
May 31 14:15:00 alpha-To-be-filled-by-O-E-M systemd[1]: apache2.service: Unit entered failed state.
May 31 14:15:00 alpha-To-be-filled-by-O-E-M systemd[1]: apache2.service: Failed with result 'exit-code'.
May 31 14:15:00 alpha-To-be-filled-by-O-E-M sudo[20280]: pam_unix(sudo:session): session closed for user root
May 31 14:15:29 alpha-To-be-filled-by-O-E-M kernel: [UFW BLOCK] IN=enp2s0 OUT= MAC=01:00:5e:00:00:fb:74:1b:b2:78:93:ac:08:00 SRC=192.168.88.25 DST=224.0.0.251 LEN=32 TOS=0x00 PREC=0x00 TTL=1 ID=8118 PROTO=2 
May 31 14:15:37 alpha-To-be-filled-by-O-E-M kernel: [UFW BLOCK] IN=enp2s0 OUT= MAC=01:00:5e:00:00:fb:74:1b:b2:78:93:ac:08:00 SRC=192.168.88.25 DST=224.0.0.251 LEN=32 TOS=0x00 PREC=0x00 TTL=1 ID=10819 PROTO=2 
May 31 14:17:01 alpha-To-be-filled-by-O-E-M CRON[20404]: pam_unix(cron:session): session opened for user root by (uid=0)
May 31 14:17:01 alpha-To-be-filled-by-O-E-M CRON[20405]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
May 31 14:17:01 alpha-To-be-filled-by-O-E-M CRON[20404]: pam_unix(cron:session): session closed for user root
May 31 14:17:18 alpha-To-be-filled-by-O-E-M kernel: [UFW BLOCK] IN=enp2s0 OUT= MAC=01:00:5e:00:00:fb:48:43:7c:bd:86:85:08:00 SRC=192.168.88.21 DST=224.0.0.251 LEN=32 TOS=0x00 PREC=0x00 TTL=1 ID=37441 PROTO=2 
May 31 14:17:33 alpha-To-be-filled-by-O-E-M AptDaemon[18313]: INFO: Quitting due to inactivity
May 31 14:17:33 alpha-To-be-filled-by-O-E-M AptDaemon[18313]: INFO: Quitting was requested
May 31 14:17:33 alpha-To-be-filled-by-O-E-M org.debian.apt[923]: 14:17:33 AptDaemon [INFO]: Quitting due to inactivity
May 31 14:17:33 alpha-To-be-filled-by-O-E-M org.debian.apt[923]: 14:17:33 AptDaemon [INFO]: Quitting was requested

在我删除并重新安装 apache2 后,显示下一条消息:

apache2.service - LSB: Apache2 web server
   Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf
   Active: inactive (dead) since Thu 2018-05-31 14:40:49 EEST; 1min 35s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 24002 ExecStop=/etc/init.d/apache2 stop (code=exited, status=0/SUCCESS)
  Process: 23986 ExecStart=/etc/init.d/apache2 start (code=exited, status=0/SUCCESS)

May 31 14:40:49 alpha-To-be-filled-by-O-E-M apache2[23986]: (98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
May 31 14:40:49 alpha-To-be-filled-by-O-E-M apache2[23986]: (98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
May 31 14:40:49 alpha-To-be-filled-by-O-E-M apache2[23986]: no listening sockets available, shutting down
May 31 14:40:49 alpha-To-be-filled-by-O-E-M apache2[23986]: AH00015: Unable to open logs
May 31 14:40:49 alpha-To-be-filled-by-O-E-M apache2[23986]: Action 'start' failed.
May 31 14:40:49 alpha-To-be-filled-by-O-E-M apache2[23986]: The Apache error log may have more information.
May 31 14:40:49 alpha-To-be-filled-by-O-E-M apache2[23986]:  *
May 31 14:40:49 alpha-To-be-filled-by-O-E-M apache2[24002]:  * Stopping Apache httpd web server apache2
May 31 14:40:49 alpha-To-be-filled-by-O-E-M apache2[24002]:  *
May 31 14:40:49 alpha-To-be-filled-by-O-E-M systemd[1]: Started LSB: Apache2 web server.

在日志中显示端口 80(apache2 被另一个应用程序使用):-

5 月 31 日 14:40:49 alpha-To-be-fill-by-OEM apache2[23986]: (98)Address already in use: AH00072: make_sock: 无法绑定到地址 [::]:80

要解决此问题,请停止现有正在运行的应用程序并尝试启动 apache2。

要检查端口 80 上正在运行的应用程序:-

    sudo lsof -i:80

获取正在运行的应用程序的 pid 并使用以下命令终止应用程序:-

   sudo pkill -9 <pid of running application>

再次运行 apache2 应用程序:-

    sudo service apache2 start
export APACHE_PID_FILE=/var/run/apache2/apache2$SUFFIX.pid

在您的/etc/apache2/envvars文件中添加这一行

如果没有suffix则必须添加

#for supporting multiple apache2 instances
 if [ "${APACHE_CONFDIR##/etc/apache2-}" != "${APACHE_CONFDIR}" ] ; then
    SUFFIX="-${APACHE_CONFDIR##/etc/apache2-}"
 else
    SUFFIX=
 fi

更新

no listening sockets available 您面临这个问题是因为另一个应用程序/服务在您的 Ubuntu 服务器上获取了端口 80。

现在您需要杀死获取端口 80 的进程。您可以使用以下命令轻松找到:-

sudo netstat -ltnp | grep ':80'

这将返回如下内容:-

tcp 0 0 127.0.0.1:80 0.0.0.0:* LISTEN 1588/aolserver4-nsd

对于上述情况,进程号 1588 获得了端口 80 ,您需要终止该进程 1588。

sudo kill -9 1588

现在你可以启动你的 apache

解决方案2

转到/etc/apache2/ports.conf并取消注释Listen 80

**如果您的 Apache2 不工作并且返回如下 **

    ● apache2.service - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf
   Active: failed (Result: exit-code) since Fri 2021-02-12 11:23:47 PST; 2min 57s ago

Feb 12 11:23:47 bitcot-Latitude-7480 apachectl[9660]: AH00558: apache2: Could not reliably determine the server's fully qu
Feb 12 11:23:47 bitcot-Latitude-7480 apachectl[9660]: (98)Address already in use: AH00072: make_sock: could not bind to ad
Feb 12 11:23:47 bitcot-Latitude-7480 apachectl[9660]: (98)Address already in use: AH00072: make_sock: could not bind to ad
Feb 12 11:23:47 bitcot-Latitude-7480 apachectl[9660]: no listening sockets available, shutting down
Feb 12 11:23:47 bitcot-Latitude-7480 apachectl[9660]: AH00015: Unable to open logs
Feb 12 11:23:47 bitcot-Latitude-7480 apachectl[9660]: Action 'start' failed.
Feb 12 11:23:47 bitcot-Latitude-7480 apachectl[9660]: The Apache error log may have more information.
Feb 12 11:23:47 bitcot-Latitude-7480 systemd[1]: apache2.service: Control process exited, code=exited status=1
Feb 12 11:23:47 bitcot-Latitude-7480 systemd[1]: apache2.service: Failed with result 'exit-code'.
Feb 12 11:23:47 bitcot-Latitude-7480 systemd[1]: Failed to start The Apache HTTP Server.

别担心,我有你的解决方案

首先检查你的机器是否有 Nginx 服务在你的系统中运行

sudo systemctl status nginx.service

如果它正在运行停止服务使用

sudo systemctl stop nginx.service

然后检查端口 80 是否有任何进程在该端口上运行

sudo lsof -i tcp:80

输出:

    COMMAND PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
anydesk 950 root   22u  IPv4  39398      0t0  TCP bitcot-Latitude-7480:35993->hosted.by.datacamp.co.uk:http (ESTABLISHED)

使用杀死进程

sudo kill 950

现在您的 apache2 已准备就绪,要启动服务,请打开一个新终端Ctrl + Ail + T并使用启动服务

sudo systemctl  start apache2

干得好

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM