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