Mac OS X上自带了Apache (安装目录为 /private/etc/apache2/ ),在Terminal里输入以下命令:
- 启动:apachectl start
- 停止:apachectl stop
- 关闭:apachectl restart
启动Apache之后,在浏览器地址栏输入localhost,出现『It Works』,表明Apache顺利启动。
『It Works』源自于 /Library/WebServer/Documents/index.html.en,为什么输入localhost就会显示这个文件呢?因为 apache/httpd.conf 里默认配置了 /Library/WebServer/Documents/ 为根目录。
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/Library/WebServer/Documents"
<Directory "/Library/WebServer/Documents">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options FollowSymLinks Multiviews
MultiviewsMatch Any
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
配置Apache用户目录
目标:浏览器地址栏输入 localhost\~txsing\,出现『hello world』。
注意:txsing是本人的用户名,以下出现的txsing都需要替换为自己的用户名。
在 /Users/txsing/ 目录下新建Sites文件夹
/Users/txsing/Sites/ 便是你的Apache用户根目录。更新 /apache2/httpd.conf
LoadModule authn_core_module libexec/apache2/mod_authn_core.so LoadModule authz_host_module libexec/apache2/mod_authz_host.so LoadModule userdir_module libexec/apache2/mod_userdir.so Include /private/etc/apache2/extra/httpd-userdir.conf
删除以上4行行首的#号,默认情况下,前两句行首应该已经没有#号了。
更新 apache2/extra/httpd-userdir.conf
Include/private/etc/apache2/users/*.conf
新建 apache2/users/txsing.conf 内容如下
<Directory"/Users/linuxidc/Sites/"> AllowOverride All Options IndexesMultiViews FollowSymLinks </Directory>