Mac Apache 配置

来源:互联网 发布:php数组按键名排序 编辑:程序博客网 时间:2024/06/05 14:37

本机默认站点目录:/Library/WebServer/Documents

在Mac OS X中可以很方便的通过开启“Web共享”启用Apache服务:
设置方法如下:

打开“系统设置偏好(System Preferences)” -> “共享(Sharing)” -> “Web共享(Web Sharing)”选中即可


启动Apache

有两种方法:

  1. 打开“系统设置偏好(System Preferences)” -> “共享(Sharing)” -> “Web共享(Web Sharing)”
  2. 打开“终端(terminal)”,然后(注意:sudo需要的密码就是系统的root帐号密码)
    1. 运行“sudo apachectl start”,再输入帐号密码,这样Apache就运行了。

这样在浏览器中输入“http://localhost”,就可以看到出现一个内容为“It works!”的页面,它位于“/Library(资源库)/WebServer/Documents/”下,这是Apache的默认根目录。

注意:开启了Apache就是开启了“Web共享”,这时联网的用户就会通过“http://[本地IP]/”来访问“/Library(资源库)/WebServer/Documents/”目录,通过“http://[本地IP]/~[用户名]”来访问“/Users/[用户名]/Sites/”目录,可以通过设置“系统偏好设置”的“安全(Security)”中的“防火墙(Firewall)”来禁止这种访问。

系统默认给当前用户的访问目录是http://localhost/~username的形式,指向的是用户home目录下的Sites目录。而很多情况下我们希望直接访问根目录(http://localhost/)便可直接访问自己的Sites目录而非系统默认的目录。


做如下更改即可:
1.打开/etc/apache2/httpd.conf文件

<span style="color: rgb(194, 12, 185);"><strong>sudo</strong></span> <span style="color: rgb(194, 12, 185);"><strong>vim</strong></span> <span style="font-weight: bold;">/</span>etc<span style="font-weight: bold;">/</span>apache2<span style="font-weight: bold;">/</span>httpd.conf

2.找到

<span style="font-weight: bold;">/</span>Library<span style="font-weight: bold;">/</span>WebServer<span style="font-weight: bold;">/</span>Documents

替换成

<span style="font-weight: bold;">/</span>Users<span style="font-weight: bold;">/</span><span style="color: rgb(122, 8, 116);"><strong>{</strong></span>username<span style="color: rgb(122, 8, 116);"><strong>}</strong></span><span style="font-weight: bold;">/</span>Sites

其中{username}是你登陆用户名,如:

<span style="font-weight: bold;">/</span>Users<span style="font-weight: bold;">/</span>liangc<span style="font-weight: bold;">/</span>Sites

3.重启“Web共享(Web Sharing)” (去掉勾再重新选中即可)

或者 运行“sudo apachectl restart

重启成功后,无需再加上用户名,便可以使用http://localhost/直接访问自己Sites目录下的内容


原文:http://blog.csdn.net/chenlia/article/details/7695804


注:

You don't have permission to access / on this server. 错误

 打开apache的配置文件httpd.conf,

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>

 由于配置了php后,这里的“Deny from all”已经拒绝了一切连接。把该行改成“allow from all”,修改后的代码如下,问题解决。

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    allow from all
</Directory>
0 0
原创粉丝点击