阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

在Linux中管理Apache Web服务器的有用命令

129次阅读
没有评论

共计 4600 个字符,预计需要花费 12 分钟才能阅读完成。

在本教程中,我们将介绍一些您应该了解的开发人员或系统管理员最常用的 Apache(HTTPD)服务管理命令,并且应该让这些命令保持在您的指尖。我们将显示 Systemd 和 SysVinit 的命令。

确保以下命令必须以 root 或 sudo 用户身份执行,并且应该适用于任何 Linux 发行版,如 CentOS,RHEL,Fedora Debian 和 Ubuntu。

在 Linux 中管理 Apache Web 服务器的有用命令

安装 Apache 服务器

要安装 Apache Web 服务器,请使用默认的分发包管理器,如下所示。

$ sudo apt install apache2    [On Debian/Ubuntu]
$ sudo yum install httpd    [On RHEL/CentOS]
$ sudo dnf install httpd    [On Fedora 22+]
$ sudo zypper install apache2    [On openSUSE]

检查 Apache 版本

要在 Linux 系统上检查已安装的 Apache Web 服务器版本,请运行以下命令。

$ sudo httpd -v

$ sudo apache2 -v

输出示例

Server version: Apache/2.4.6 (CentOS)
Server built:  Nov  5 2018 01:47:09

如果要显示 Apache 版本号和编译设置,请使用 - V 标志,如图所示。

$ sudo httpd -V
或者
$ sudo apache2 -V

输出示例

Server version: Apache/2.4.6 (CentOS)
Server built:  Nov  5 2018 01:47:09
Server’s Module Magic Number: 20120211:24
Server loaded:  APR 1.4.8, APR-UTIL 1.5.2
Compiled using: APR 1.4.8, APR-UTIL 1.5.2
Architecture:  64-bit
Server MPM:    prefork
  threaded:    no
    forked:    yes (variable process count)
Server compiled with….
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=256
 -D HTTPD_ROOT=”/etc/httpd”
 -D SUEXEC_BIN=”/usr/sbin/suexec”
 -D DEFAULT_PIDLOG=”/run/httpd/httpd.pid”
 -D DEFAULT_SCOREBOARD=”logs/apache_runtime_status”
 -D DEFAULT_ERRORLOG=”logs/error_log”
 -D AP_TYPES_CONFIG_FILE=”conf/mime.types”
 -D SERVER_CONFIG_FILE=”conf/httpd.conf”

检查 Apache 配置语法错误

要检查 Apache 配置文件是否存在任何语法错误,请运行以下命令,该命令将在重新启动服务之前检查配置文件的有效性。

$ sudo httpd -t
或者
$ sudo apache2ctl -t

输出示例

AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using linuxidc.com.
Set the ‘ServerName’ directive globally to suppress this message
Syntax OK

启动 Apache 服务

要启动 Apache 服务,请运行以下命令。

———— On CentOS/RHEL ————
$ sudo systemctl start httpd    [On Systemd]
$ sudo service httpd start   [On SysVInit]

———— On Ubunt/Debian  ————
$ sudo systemctl start apache2  [On Systemd]
$ sudo service apache2 start    [On SysVInit]

启用 Apache 服务

上一个命令仅在此期间启动 Apache 服务,要使其在系统引导时自动启动,请运行以下命令。

———— On CentOS/RHEL ————
$ sudo systemctl enable httpd    [On Systemd]
$ sudo chkconfig httpd on   [On SysVInit]

———— On Ubunt/Debian  ————
$ sudo systemctl enable apache2  [On Systemd]
$ sudo chkconfig apache2 on      [On SysVInit]

重启 Apache 服务

要重新启动 Apache(停止然后启动该服务),请运行以下命令。

———— On CentOS/RHEL ————
$ sudo systemctl restart httpd    [On Systemd]
$ sudo service httpd restart     [On SysVInit]

———— On Ubunt/Debian  ————
$ sudo systemctl restart apache2  [On Systemd]
$ sudo service apache2 restart    [On SysVInit]

查看 Apache 服务状态

要检查 Apache 服务运行时状态信息,请运行以下命令。

———— On CentOS/RHEL ————
$ sudo systemctl status httpd    [On Systemd]
$ sudo service httpd status   [On SysVInit]

———— On Ubunt/Debian  ————
$ sudo systemctl status apache2  [On Systemd]
$ sudo service apache2 status    [On SysVInit]

重新加载 Apache 服务

如果您对 Apache 服务器配置进行了任何更改,则可以通过运行以下命令指示服务重新加载其配置。

———— On CentOS/RHEL ————
$ sudo systemctl reload httpd    [On Systemd]
$ sudo service httpd reload   [On SysVInit]

———— On Ubunt/Debian  ————
$ sudo systemctl reload apache2  [On Systemd]
$ sudo service apache2 reload    [On SysVInit]

停止 Apache 服务

要停止 Apache 服务,请使用以下命令。

———— On CentOS/RHEL ————
$ sudo systemctl stop httpd      [On Systemd]
$ sudo service httpd stop   [On SysVInit]

———— On Ubunt/Debian  ————
$ sudo systemctl stop apache2    [On Systemd]
$ sudo service apache2 stop    [On SysVInit]

显示 Apache 命令帮助

最后但并非最不重要的是,您可以通过运行以下命令获得有关 systemd 下的 Apache 服务命令的帮助。

$ sudo httpd -h
或者
$ sudo apache2 -h 
或者
$ systemctl -h apache2 

输出示例

Usage: httpd [-D name] [-d directory] [-f file]
            [-C “directive”] [-c “directive”]
            [-k start|restart|graceful|graceful-stop|stop]
            [-v] [-V] [-h] [-l] [-L] [-t] [-T] [-S] [-X]
Options:
  -D name            : define a name for use in  directives
  -d directory      : specify an alternate initial ServerRoot
  -f file            : specify an alternate ServerConfigFile
  -C “directive”    : process directive before reading config files
  -c “directive”    : process directive after reading config files
  -e level          : show startup errors of level (see LogLevel)
  -E file            : log startup errors to file
  -v                : show version number
  -V                : show compile settings
  -h                : list available command line options (this page)
  -l                : list compiled in modules
  -L                : list available configuration directives
  -t -D DUMP_VHOSTS  : show parsed vhost settings
  -t -D DUMP_RUN_CFG : show parsed run settings
  -S                : a synonym for -t -D DUMP_VHOSTS -D DUMP_RUN_CFG
  -t -D DUMP_MODULES : show all loaded modules
  -M                : a synonym for -t -D DUMP_MODULES
  -t                : run syntax check for config files
  -T                : start without DocumentRoot(s) check
  -X                : debug mode (only one worker, do not detach)

就这样了!在本文中,我们已经解释了您应该了解的最常用的 Apache/HTTPD 服务管理命令,包括启动,启用,重新启动和停止 Apache。如有任何问题或意见,您可以随时通过下面的反馈表联系我们。

如何在 Ubuntu 18.04 上安装和配置 Apache 2 Web 服务器  https://www.linuxidc.com/Linux/2018-11/155507.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计4600字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中