环境描述:
物理机中没有搭建任何环境,将apache搭建在虚拟机(vmware win7 x64)中,使用wamp,apache+mysql,使用物理机如何访问虚拟机中的php网页。
连通网络
首先我们要使物理机和虚拟机在一个内网中才能成功访问。配置如下:
- 将物理机的vmnet8网卡的ipv4地址改为192.168.75.1
具体步骤:1. 控制面板->网络和共享中心->更改适配器设置->选择vmnet8网卡->属性->Internet协议版本4(TCP/Ipv)
选择“使用下面的ip地址选项”,配置静态ip为192.168.75.1掩码为C类255.255.255.0
- 配置目标虚拟机网络模式为NAT
- 配置虚拟机NAT
具体步骤:在VMware中选择->编辑->虚拟网络编辑器->(右下角)更改设置->选择vmnet8网卡->将下面的子网ip地址和子网掩码改为192.168.75.0 255.255.255.0
配置DHCP地址池
具体步骤:(还是在刚才的虚拟网络编辑器中的vmnet8网卡下)点击DHCP设置->配置起始ip段和终止ip段为192.168.75.128-192.168.75.254启动虚拟机
Apache配置
- 打开Apache中的httpd.conf(在apache\apache2.4.9\conf目录下)。
- 找到 <Directory “c:/wamp/www/” > 将倒数第二行的
Require all local
改为Require all granted
<Directory "c:/wamp/www/">## Possible values for the Options directive are "None", "All",# or any combination of:# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews## Note that "MultiViews" must be named *explicitly* --- "Options All"# doesn't give it to you.## The Options directive is both complicated and important. Please see# http://httpd.apache.org/docs/2.4/mod/core.html#options# for more information.#Options Indexes FollowSymLinks## AllowOverride controls what directives may be placed in .htaccess files.# It can be "All", "None", or any combination of the keywords:# AllowOverride FileInfo AuthConfig Limit#AllowOverride all## Controls who can get stuff from this server.## onlineoffline tag - don't removeRequire all local
</Directory>
之后启动服务器,在cmd下输入ipconfig -all
查看虚拟机ipv4地址,使用物理机直接访问这个地址就可以了