我正在尝试重新启动 Apache,当我使用命令时sudo systemctl restart apache2.service
,什么都没有发生。终端没有任何错误消息或其他响应,在我按下回车键后,它只是转到一个新行。我不知道会发生什么,当我尝试重新启动 mysql 时也会发生同样的事情。非常感谢您的帮助。
答案1
通常,如果您启动/重新启动 apache,则不会确认它是否已启动,但如果遇到错误则会告知。
如前面的答案所示,根据您所使用的 Ubuntu 版本,有多种方法可以启动 apache。
Ubuntu 16.10,则适用以下方法:
sudo service apache2 restart
sudo systemctl restart apache2
如果担心它是否正确启动,请使用上述任一命令,将 替换restart
为status
。
如果运行,它应该提供与此类似的结果:
● apache2.service - LSB: Apache2 web server
Loaded: loaded (/etc/init.d/apache2; generated; vendor preset: enabled)
Drop-In: /lib/systemd/system/apache2.service.d
└─apache2-systemd.conf
Active: active (running) since Wed 2017-03-22 00:38:10 UTC; 9min ago
Docs: man:systemd-sysv-generator(8)
CGroup: /system.slice/apache2.service
├─1627 /usr/sbin/apache2 -k start
├─1630 /usr/sbin/apache2 -k start
└─1631 /usr/sbin/apache2 -k start
Mar 22 00:38:09 potato systemd[1]: Starting LSB: Apache2 web server...
Mar 22 00:38:09 potato apache2[1605]: * Starting Apache httpd web server apache2
Mar 22 00:38:09 potato apache2[1605]: AH00558: apache2: Could not reliably determine the server's ful
Mar 22 00:38:10 potato apache2[1605]: *
Mar 22 00:38:10 potato systemd[1]: Started LSB: Apache2 web server.
当 Apache 失败时,我们希望看到类似的内容:
Job for apache2.service failed because the control process exited with error code.
See "systemctl status apache2.service" and "journalctl -xe" for details.
然后发出其中一个提供的命令,将提供有关无法启动 apache 的原因的详细信息:
● apache2.service - LSB: Apache2 web server
Loaded: loaded (/etc/init.d/apache2; generated; vendor preset: enabled)
Drop-In: /lib/systemd/system/apache2.service.d
└─apache2-systemd.conf
Active: failed (Result: exit-code) since Wed 2017-03-22 00:49:46 UTC; 2min 10s ago
Docs: man:systemd-sysv-generator(8)
Process: 1810 ExecStop=/etc/init.d/apache2 stop (code=exited, status=0/SUCCESS)
Process: 1863 ExecStart=/etc/init.d/apache2 start (code=exited, status=1/FAILURE)
Mar 22 00:49:46 potato apache2[1863]: *
Mar 22 00:49:46 potato apache2[1863]: * The apache2 configtest failed.
Mar 22 00:49:46 potato apache2[1863]: Output of config test was:
Mar 22 00:49:46 potato apache2[1863]: apache2: Syntax error on line 219 of /etc/apache2/apache2.conf:
Mar 22 00:49:46 potato apache2[1863]: Action 'configtest' failed.
Mar 22 00:49:46 potato apache2[1863]: The Apache error log may have more information.
Mar 22 00:49:46 potato systemd[1]: apache2.service: Control process exited, code=exited status=1
Mar 22 00:49:46 potato systemd[1]: Failed to start LSB: Apache2 web server.
Mar 22 00:49:46 potato systemd[1]: apache2.service: Unit entered failed state.
Mar 22 00:49:46 potato systemd[1]: apache2.service: Failed with result 'exit-code'.
在这个例子中,我将 /etc/apache2/sites-enabled 移动到 /etc/apache2/sites-disabled 并尝试启动 apache。
希望这可以帮助。
答案2
尝试这个命令。
sudo /etc/init.d/apache2 restart
这也适用于许多其他事物,例如网络。
sudo /etc/init.d/networking restart
答案3
根据你使用的 Ubuntu 版本,Upstart 的本机命令应通过 initctl 处理,因此要使该命令有输出,你应该使用sudo restart apache2