Debian/Ubuntu Linux 特定命令
您可以在 Debian Linux 版本 7.x 或 Ubuntu Linux 版本 Ubuntu 14.10 或更早版本上使用 service 或 /etc/init.d/ 命令,如下所示:
重启 Apache 2 网络服务器,输入:
# /etc/init.d/apache2 restart
或
$ sudo /etc/init.d/apache2 restart
或
$ sudo service apache2 restart
要停止 Apache 2 Web 服务器,请输入:
# /etc/init.d/apache2 stop
或
$ sudo /etc/init.d/apache2 stop
或
$ sudo service apache2 stop
要启动 Apache 2 Web 服务器,请输入:
# /etc/init.d/apache2 start
或
$ sudo /etc/init.d/apache2 start
或
$ sudo service apache2 start
关于 Debian/Ubuntu Linux systemd 用户的说明
在 Debian Linux 版本 8.x+ 或 Ubuntu Linux 版本 Ubuntu 15.04+ 或更高版本上使用以下命令:
启动命令
systemctl start apache2.service
停止命令
systemctl stop apache2.service
重启命令
systemctl restart apache2.service
CentOS/RHEL (Red Hat) Linux 版本 4.x/5.x/6.x 或更旧的特定命令
开始
service httpd start
停止
service httpd stop
重启
service httpd restart
CentOS/RHEL (Red Hat) Linux 版本 7.x 或更新的特定命令
大多数现代发行版现在使用 systemd,因此您需要使用以下命令:
启动命令
systemctl start httpd.service
停止命令
systemctl stop httpd.service
重启命令
systemctl restart httpd.service
在 Linux/Unix 上启动/停止/重新启动 Apache 的通用方法
语法如下(必须以root用户运行):
停下来
apachectl -k stop
重启
apachectl -k restart
优雅重启吧
apachectl -k graceful
开始
apachectl -f /path/to/your/httpd.conf
apachectl -f /usr/local/apache2/conf/httpd.conf
如果其他服务占用了80端口(例如:Skype),
试试代码:
sudo /etc/init.d/apache2 stop
后跟代码:
sudo killall apache2
然后确保没有服务在端口 80 上运行代码:
sudo netstat -l|grep www
然后(重新)启动 apache 代码:
sudo /etc/init.d/apache2 restart