mac配置apache

http://www.cnblogs.com/snandy/archive/2012/11/13/2765381.htmlphp

用自帶的html

 sudo apachectl -vweb

 sudo apachectl startapache

 sudo apachectl stopide

 sudo apachectl restartthis

web默認目錄在/Library/WebServer/Documents/spa

設置虛擬主機

  1. 在終端運行「sudo vi /etc/apache2/httpd.conf」,打開Apche的配置文件
  2. 在httpd.conf中找到「#Include /private/etc/apache2/extra/httpd-vhosts.conf」,去掉前面的「」,保存並退出。
  3. 運行「sudo apachectl restart」,重啓Apache後就開啓了虛擬主機配置功能。
  4. 運行「sudo vi /etc/apache2/extra/httpd-vhosts.conf」,就打開了配置虛擬主機文件httpd-vhost.conf,配置虛擬主機了。須要注意的是該文件默認開啓了兩個做爲例子的虛擬主機:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    < VirtualHost  *:80>
         ServerAdmin webmaster@dummy-host.example.com
         DocumentRoot "/usr/docs/dummy-host.example.com"
         ServerName dummy-host.example.com
         ErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log"
         CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log" common
    </ VirtualHost >
     
    < VirtualHost  *:80>
         ServerAdmin webmaster@dummy-host2.example.com
         DocumentRoot "/usr/docs/dummy-host2.example.com"
         ServerName dummy-host2.example.com
         ErrorLog "/private/var/log/apache2/dummy-host2.example.com-error_log"
         CustomLog "/private/var/log/apache2/dummy-host2.example.com-access_log" common
    </ VirtualHost >

    而實際上,這兩個虛擬主機是不存在的,在沒有配置任何其餘虛擬主機時,可能會致使訪問localhost時出現以下提示:rest

    Forbidden
    You don't have permission to access /index.php on this server

    最簡單的辦法就是在它們每行前面加上#,註釋掉就行了,這樣既能參考又不致使其餘問題。code

  5. 增長以下配置
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    < 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/snandy/work"
         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 >

    保存退出,並重啓Apache。server

相關文章
相關標籤/搜索