Mac OS X中配置Apache

1.启动Apachehtml

打开 “iTerm”-我安装的这个也能够用自带的 "终端(terminal)",apache

输入 sudo apachectl -v 查看Apache版本号浏览器

启动 sudo apachectl start编辑器

这样Apache就启动了。打开Safari浏览器地址栏输入 “http://localhost”,能够看到内容为“It works!”的页面ide

默认的根目录 “/Library(资源库)/WebServer/Documents/”spa

apache的目录是在 “/etc/apache2/” 若是找不到该目录那就自行百度吧rest


2.设置虚拟主机code

本人小菜鸟Vim编辑器不太会用,容我使用Notepadhtm

在 /etc/apache2/httpd.conf 中找到“#Include /private/etc/apache2/extra/httpd-vhosts.conf”,去掉前面的“#”资源

重启apache  sudo apachectl restart

重启Apache后就开启了虚拟主机配置功能

在 /etc/apache2/extra/httpd-vhosts.conf 中添加如下配置:(注意DocumentRoot请自行修改)

<VirtualHost *:80>
    DocumentRoot "/Library/WebServer/Documents"
    ServerName localhost
    ErrorLog "/private/var/log/apache2/localhost-error_log"
    CustomLog "/private/var/log/apache2/localhost-access_log" common
</VirtualHost> 

<VirtualHost *:80>
    DocumentRoot "/Users/Onego/WebServer"
    ServerName mysites
    ErrorLog "/private/var/log/apache2/sites-error_log"
    CustomLog "/private/var/log/apache2/sites-access_log" common
    <Directory />
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order deny,allow
                Allow from all
      </Directory>
</VirtualHost>

在 /etc/hosts 中加入"127.0.0.1 mysites"

重启apache  sudo apachectl restart

这样就能够配置完成sites虚拟主机了,能够访问“http://mysites”

2.权限设置

这样就能够配置完成sites虚拟主机了,能够访问“http://mysites”

8.权限问题

在apache2目录下的httpd.conf

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

这里改为

<Directory />
    Options Indexes FollowSymLinks
    AllowOverride None
</Directory>

重启apache  sudo apachectl restart

OK 搞定

相关文章
相关标签/搜索