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 搞定

相關文章
相關標籤/搜索