Mac OS X 配置Apache

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都需要替换为自己的用户名。

  1. /Users/txsing/ 目录下新建Sites文件夹
    /Users/txsing/Sites/ 便是你的Apache用户根目录。

  2. 更新 /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行行首的#号,默认情况下,前两句行首应该已经没有#号了。

  3. 更新 apache2/extra/httpd-userdir.conf

    Include/private/etc/apache2/users/*.conf
    
  4. 新建 apache2/users/txsing.conf 内容如下

      <Directory"/Users/linuxidc/Sites/"> 
       AllowOverride All 
       Options IndexesMultiViews FollowSymLinks 
      </Directory> 
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值