如何在 Mac OS X 中使用终端重新启动 Apache?

jao*_*488 14 terminal.app macos

这就是我所做的,但我对终端真的很陌生:

Jeremys-MacBook-Pro-2:~ jeremyoconnor$ apachectl restart

This operation requires root.
Run Code Online (Sandbox Code Playgroud)

Gia*_*968 24

由于 Apache 在80被视为敏感系统级端口的保留端口 ( )上运行,因此您必须apachectl restart通过sudo如下方式运行:

sudo apachectl -k restart
Run Code Online (Sandbox Code Playgroud)

输入后,它将作为您的密码。假设您有管理员权限,只需输入密码,Apache 就会重新启动。其他命令包括start并且stop可以像这样运行以启动 Apache:

sudo apachectl -k start
Run Code Online (Sandbox Code Playgroud)

像这样停止Apache:

sudo apachectl -k stop
Run Code Online (Sandbox Code Playgroud)

此外,如果您只输入apachectl而不输入任何内容,您将收到可以与apachectl命令一起使用的选项和指令列表;这是我从 Mac OS X 10.9.5 的输出:

Usage: /usr/sbin/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]
Options:
  -D name            : define a name for use in <IfDefine name> 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 settings (currently only vhost settings)
  -S                 : a synonym for -t -D DUMP_VHOSTS
  -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
Run Code Online (Sandbox Code Playgroud)