MacOS Apache配置

时间:2023-03-08 21:54:43
仅适用于apache 2.2版本
查看版本
sudo apachectl -v
启动服务器
sudo apachectl start
打开localhost,可以看到内容为“It works!”的页面。
位于/Library/WebServer/Documents/  这就是Apache的默认根目录
重启的话则是   sudo apachectl restart
httpd.conf 配置文件
sudo vi /etc/apache2/httpd.conf

http.conf改成

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

# This should be changed to whatever you set DocumentRoot to.

#
<Directory "/Users/lumixraku/Sites">
....

  Order allow,deny
  Allow from all

</Directory>

将目录改为自己的目录   那么访问http://localhost/~xxx/ 直接进入指定的目录就Ok了  xxx是你mac 的机器名
还可以更干脆一点 (L170左右)

#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this direc
# symbolic links and aliases may be used to point to other loca
#
DocumentRoot "/Library/WebServer/Documents"

改成
DocumentRoot "/Users/lumixraku/Sites"  
那么直接localhost就可以访问Sites目录啦

==============================

下面是10.11的配置

El Capitan Apache配置

sudo vim /etc/apache2/httpd.conf

找到DocumentRoot


DocumentRoot "/Users/yourname/Sites"
<Directory "/Users/yourname/Sites">
AllowOverride All
Options Indexes MultiViews FollowSymLinks
Require all granted
</Directory>

并且下面这些取消注释 
LoadModule authz_core_module libexec/apache2/mod_authz_core.so 
LoadModule authz_host_module libexec/apache2/mod_authz_host.so 
LoadModule userdir_module libexec/apache2/mod_userdir.so 
LoadModule include_module libexec/apache2/mod_include.so 
LoadModule rewrite_module libexec/apache2/mod_rewrite.so 
LoadModule userdir_module libexec/apache2/mod_userdir.so

如果有一些用户配置 
到/etc/apache2/users中 
创建一个 yourname.conf的文件

<Directory "/Users/yourname/Sites/">
AllowOverride All
Options Indexes MultiViews FollowSymLinks
Require all granted
</Directory>

sudo apachectl restart

之后使用这个访问 
http://localhost/~username/