Mac OS X内置Apache作为web server,之前是是通过系统偏好设置>共享面板中的web sharing控制,从10.8 ML以后移除了这一选项,需要从命令行打开,如下,
$ sudo apachectl start
$ httpd -v
Server version: Apache/2.2.22 (Unix)
Server built: Aug 24 2012 17:16:58
Mac OS X分为2个System Level和User Level,System Level对应到/Library/WebServer/Documents,而User Level则对应到~/Sites。
启用User Level还是需要配置以下apache,在/etc/apache2/users下新建一个username.conf,内容如下,
<directory "/Users/nonocast/Sites/"> Options Indexes MultiViews AllowOverride All Order allow,deny Allow from all </directory>
username.conf的权限应该像下面这样,
-rw-r–r– 1 root wheel 127 10 10 01:26 username.conf
如果不一致可以通过sudo chmod 644 username.conf设置,最后重启apache,sudo apachectl restart,再次打开http://localhost/~username,