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


13

这是我所做的,但是我对终端真的很新:

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

This operation requires root.

Answers:


23

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

sudo apachectl -k restart

键入后,它将作为您的密码。假设您具有管理员权限,只需输入密码,Apache应该重新启动。其他命令包括startstop可以运行这样启动Apache:

sudo apachectl -k start

像这样停止Apache:

sudo apachectl -k stop

同样,如果您只是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
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.