http://www.javashuo.com/article/p-cspxknku-dz.html mac 系統升級以後,常常會發生一些變化,可是,之前的操做老是能夠參考的!php
http://httpd.apache.org/docs/2.4/vhosts/html
*** 本次 mac PS 版本:mac OS Mojave 10.14.5web
直接瀏覽器上輸入 127.0.0.1 It works! 說明缺省虛擬主機配置是正確的! 輸入 127.0.0.1/info.php ,結果一片空白!apache
經過 Finder ,設置個人虛擬目錄權限,所有可讀寫 ** 缺省虛擬主機目錄 DocumentRoot "/Library/WebServer/Documents" ** 使用次數很少,本次再也不單獨創建本身的虛擬主機目錄了vim
打開 Terminal 終端,查看php 和 apache2 信息 $ php -v瀏覽器
PHP 7.1.23 (cli) (built: Feb 22 2019 22:19:32) ( NTS )
Copyright (c) 1997-2018 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies安全
$ httpd -v服務器
Server version: Apache/2.4.34 (Unix)
Server built: Feb 22 2019 20:20:11php7
$ which httpddom
/usr/sbin/httpd
$ httpd -S
在這裏能夠看到 DocumentRoot 、ErrorLog 等信息 AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using dhbm-on-mac20180816.local. Set the 'ServerName' directive globally to suppress this message VirtualHost configuration: ServerRoot: "/usr" Main DocumentRoot: "/Library/WebServer/Documents" Main ErrorLog: "/private/var/log/apache2/error_log" Mutex default: dir="/private/var/run/" mechanism=default Mutex mpm-accept: using_defaults PidFile: "/private/var/run/httpd.pid" Define: DUMP_VHOSTS Define: DUMP_RUN_CFG User: name="_www" id=70 not_used Group: name="_www" id=70 not_used
打開 php 支持 sudo vim /etc/apache2/httpd.conf 找到如下 libphp7.so 模塊地方,去掉前面的註釋 #
# by wzh 20190613 enable php7 LoadModule php7_module libexec/apache2/libphp7.so
放開虛擬目錄權限 sudo vim /etc/apache2/httpd.conf 找到 < Directory /> 的地方,放開 AllowOverride 和 Require 限制
<Directory /> # by wzh 20190613 # AllowOverride none # Require all denied allow from all AllowOverride All Require all granted
</Directory>
一樣找到 DocumentRoot "/Library/WebServer/Documents" <Directory "/Library/WebServer/Documents"> 放開限制
# by wzh 20190613 AllowOverride None # # Controls who can get stuff from this server. # Require all granted # add by wzh 20190613 none ->all Options All AllowOverride All Allow from all
4. 測試虛擬目錄 http://localhost/ http://127.0.0.1/
*** mac OS 升級常常會形成 apache2 配置的一些變化,可是,感受每次都會變的愈來愈簡單!比起之前折騰過的兩次,本次是最省事的一次! *** 主要就是:一、加載 php 模塊 二、放開目錄權限 三、放開虛擬目錄權限 *** 也許有些變化在上一次折騰的時候已經作過了!
增長一個虛擬目錄 sudo vim /etc/apache2/httpd.conf
** 本次爲了簡化,直接在缺省虛擬目錄下新建子目錄test123,做爲測試網站站點的目錄 ** 每增長一個站點,就要先增長一個目錄(我這裏創建了 2 個)
# add by wzh 20190613 new dir for other website:test123.wzh # for vhost test DocumentRoot "/Library/WebServer/Documents/test123" <Directory "/Library/WebServer/Documents/test123"> Require all granted # by wzh 20190613 none ->all Options All AllowOverride All Allow from all </Directory> # add by wzh 20190613 new dir for other website : tp123.wzh # for ThinkPHP test on 8080 port DocumentRoot "/Library/WebServer/Documents/tp123" <Directory "/Library/WebServer/Documents/tp123"> Require all granted # by wzh 20190613 none ->all Options All AllowOverride All Allow from all </Directory>
增長一個虛擬站點 $ sudo vim /etc/apache2/extra/httpd-vhosts.conf *** 在文件最後增長如下 2 個測試站點
# add by wzh 20190613 <VirtualHost *:80> ServerAdmin 13501062476@139.com DocumentRoot "/Library/WebServer/Documents/test123/" ServerName test123.wzh ErrorLog "/private/var/log/apache2/test123-error_log" CustomLog "/private/var/log/apache2/test123-access_log" common </VirtualHost> # add by wzh 20190613 <VirtualHost *:80> ServerAdmin 13501062476@139.com DocumentRoot "/Library/WebServer/Documents/test123/" ServerName test123.wzh ErrorLog "/private/var/log/apache2/test123-error_log" CustomLog "/private/var/log/apache2/test123-access_log" common </VirtualHost> # add by wzh 20190613 <VirtualHost *:8080> ServerAdmin 13501062476@139.com DocumentRoot "/Library/WebServer/Documents/tp123/" ServerName tp123.wzh ErrorLog "/private/var/log/apache2/tp123-error_log" CustomLog "/private/var/log/apache2/tp123-access_log" common </VirtualHost>
3.增長一條本地映射 ** 僅供本地測試用,外網是找不到這 2 個域名的 $ sudo vim /etc/hosts 在最後增長 2 條記錄
# add by wzh 20190623 127.0.0.1 test123.wzh 127.0.0.1 tp123.wzh
增長一個本地 8080 端口 listen $ sudo vim /etc/apache2/extra/httpd-vhosts.conf
** 若是不用80 端口以外的其餘端口,能夠忽略這一步 ** 找到如下位置,增長 2 條本身的 listen
#Listen 12.34.56.78:80 <IfDefine SERVER_APP_HAS_DEFAULT_PORTS> Listen 8080 </IfDefine> <IfDefine !SERVER_APP_HAS_DEFAULT_PORTS> Listen 80 </IfDefine> # add by wzh 20190613 Listen 127.0.0.1:80 Listen 127.0.0.1:8080
重啓生效 $ sudo apachectl restart
** 爲了簡化,先去關閉mac OS 防火牆 ** mac OS 防火牆 從之前的 ipfw 改到如今的 pf ** 目前爲止我也不知道怎麼開放指定端口
ping tp123.wzh ping test123.wzh
$ curl test123.wzh $ curl test123.wzh/index.php
$ curl test123.wzh:8080 $ curl test123.wzh:8080/index.php ** 若是發現錯誤 curl: (7) Failed to connect to tp123.wzh port 8080: Connection refused ** 請參照上 一步:增長一個本地 8080 端口 listen
$ curl tp123.wzh $ curl tp123.wzh/index.php
$ curl tp123.wzh:8080 $ curl tp123.wzh:8080/index.php
瀏覽器測試 http://test123.wzh/ http://test123.wzh/index.php
http://tp123.wzh/ http://tp123.wzh/index.php http://test123.wzh:8080/ http://test123.wzh:8080/index.php
以上結果僅貼圖一個爲例
參考 https://www.cnblogs.com/maowenqiang/p/5120767.html 寫得很是清楚,這裏再抄寫一次
cd /etc/apache2 sudo vim httpd.conf
# by wzh 20190628 啓用apache的虛擬主機功能 # LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so
我這裏沒有打開這個!直接全部域名網站都放在 httpd-vhosts.conf 裏面
# Virtual hosts # by wzh 20190628 多域名支持 Include /private/etc/apache2/extra/httpd-vhosts.conf
cd /etc/apache2/extra sudo vim httpd-vhosts.conf 加上新建立的虛擬目錄對應的域名
# add by wzh 20190628 tp6.wzh <VirtualHost *:80> ServerAdmin 13501062476@139.com DocumentRoot "/Users/dhbm/php20190628" ServerName tp6.wzh ErrorLog "/private/var/log/apache2/tp6--error_log" CustomLog "/private/var/log/apache2/tp6-access_log" common </VirtualHost>
cd /etc sudo vim hosts 加上剛剛建立的域名和虛擬主機
# add by wzh 20190628 127.0.0.1 tp6.wzh
重啓 apache2 生效 sudo apachectl restart
測試一下 http://tp6.wzh/tp/public/
配置了多個虛擬目錄以後,老是所有指向最後一個 按照以上 五、配置多虛擬目錄、域名支持 cd /etc/apache2 sudo vim httpd.conf 放開如下 2 處 的 # 註釋
# by wzh 20190628 啓用apache的虛擬主機功能 # LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so # Virtual hosts # by wzh 20190628 多域名支持 Include /private/etc/apache2/extra/httpd-vhosts.conf
這樣的話,全部的網站都會到 /etc/apache2/extra/httpd-vhosts.conf 裏面去查找,按照 ServerName 對應響應的虛擬目錄
配置了vhost 支持以後,localhost 和 127.0.0.1 反而打不開了 ping 127.0.0. 和 ping localhost 都不通,由於 mac 開着防火牆? 測試一下 apache 語法 httpd -t 顯示如下的錯誤
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using dhbm-on-mac20180816.local. Set the 'ServerName' directive globally to suppress this message
百度如下,找到這個博客 https://blog.csdn.net/weixin_43245095/article/details/89556756
按照他的建議修改 sudo vim /etc/apache2/httpd.conf 找到 ServerName 修改以下
# add by wzh 20190629 # 解決 httpd -t 錯誤 ServerName 127.0.0.1:80
restart 以後,再次 測試 httpd -t
Syntax OK
查看 apache 狀態 sudo apachectl status 顯示以下提示
Go to http://localhost:80/server-status in the web browser of your choice.
Note that mod_status must be enabled for this to work.
參考 https://blog.csdn.net/wangkepermit/article/details/72954995 須要開啓status功能
個人理解:
找到如下 mod_status.so LoadModule status_module libexec/apache2/mod_status.so
另外 httpd-info 的地方,缺省是註釋的 # Real-time info on requests and configuration #Include /private/etc/apache2/extra/httpd-info.conf
可能涉及到安全性問題,目前暫時不須要,因此,這裏保持不動!
啓動、中止 apache sudo apachectl start sudo apachectl stop sudo apachectl restart sudo apachectl status
檢查 httpd 語法 httpd -t
查看apache 加載了那些模塊 sudo apachectl -M 或 sudo apachectl -t -D DUMP_MODULES