apachectl 添加域名、虛擬主機(jī)走過(guò)的坑(mac)

1.設(shè)置域名
打開(kāi)Finder,command + shift + G ,搜索框內(nèi)輸入/etc ,也就是查找系統(tǒng)的根目錄,找到一個(gè)叫hosts的文件,用文本編輯器打開(kāi)。


111.png

默認(rèn)情況下,他們的根目錄都是你在/etc/apache2/httpd.conf文件中設(shè)置的根目錄

DocumentRoot "/Users/edz/Sites(你自己設(shè)置的根目錄)"
<Directory "/Users/edz/Sites">

如果不知道httpd.conf中怎么設(shè)置,請(qǐng)查看,http://blog.csdn.net/qq_31989521/article/details/50773492
或者我的第一篇 php開(kāi)發(fā)環(huán)境搭建(匯總)
2.虛擬主機(jī)
(1).看你的php版本(終端里輸入 php -version ),如果你是最新的,在httpd.conf文件中查找:php7_module(版本號(hào)對(duì)應(yīng)),將此行代碼#刪除

LoadModule php7_module /usr/local/php5-7.1.0-20161202-092124/libphp7.so

(如果想用最新的配置環(huán)境,見(jiàn)更新PHP版本+appache的相應(yīng)修改,里面也說(shuō)了一下更新版本會(huì)遇到的坑)
(2)最重要的一步到來(lái)了,在/etc/apache2/extra/httpd-vhosts.conf,設(shè)置虛擬主機(jī)

<VirtualHost *:80> 
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/Users/edz/Sites"
    ServerName localhost
    ServerAlias 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
    #DirectoryIndex info.php
     <Directory />
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order deny,allow
                Allow from all
      </Directory>
</VirtualHost>
222.png

一個(gè)域名可以對(duì)應(yīng)一個(gè)虛擬主機(jī),多個(gè)域名也可以對(duì)應(yīng)一個(gè)主機(jī)。

注意:每次從新設(shè)置了,httpd-vhost.conf文件之后,最好,重啟一下appach。(方法:打開(kāi)終端,輸入 sudo apachectl -k restart),加上-k,可以監(jiān)聽(tīng)到,在配置文件中是否有錯(cuò)誤。

下面是我創(chuàng)建的上面三個(gè)域名對(duì)應(yīng)的虛擬主機(jī)

<VirtualHost *:80> 
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/Users/edz/Sites"
    ServerName localhost
    ServerAlias 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
    #DirectoryIndex info.php
     <Directory />
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order deny,allow
                Allow from all
      </Directory>
</VirtualHost>

<VirtualHost *:80> 
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/Users/edz/web1"
    ServerName dev.php.com
    ErrorLog "/private/var/log/apache2/dummy-host2.example.com-error_log"
    CustomLog "/private/var/log/apache2/dummy-host2.example.com-access_log" common
    DirectoryIndex info.php
     <Directory  />
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order deny,allow
                Allow from all
      </Directory>
</VirtualHost>


<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/Users/edz/web2"
    ServerName www.2017.com
    #ErrorLog "/private/var/log/apache2/dummy-host2.example.com-error_log"
    #CustomLog "/private/var/log/apache2/dummy-host2.example.com-access_log" common
    DirectoryIndex formlist.html
    <Directory  />
                Options Indexes 
                AllowOverride None
                Order deny,allow
                Allow from all
      </Directory>
</VirtualHost>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容