记忆太多 发表于 2015-8-22 02:29:41

在WAMP下设置本地访问的虚拟主机

  在PHP培训过程中,发现有很多同学设计的PHP网站,在开发测试的时候一切正常,可上传在服务器的时候,发现总有路径错误,如生成HTML页中的路径,CSS中的路径背景图片路径等。
我的建议是,对于初学php的程序员来说,直接在本地虚拟主机,相对模拟服务器运行环境,来开发和测试PHP程序,这样移植到服务器中路径的错误机率就比较低了。对于PHP高手来说,就无所谓了。
以下是最简单的WAMP的本地访问形式虚拟主机的设置步骤:
一、在windows下本地域名解析设置:
使用editPlus打开C:\WINDOWS\system32\drivers\etc\hosts文件进行编辑,如下:
# Copyright (c) 1993-1999 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
127.0.0.1 localhost
127.0.0.1 www.al0574.com
这个只能在本地访问。你直接可以浏览器中输入www.al0574.com就可以访问后面在Apache中设置的虚拟站点下web程序或页面。
二、进行Apache服务器解析设置:
apache的配置文件在X:\php\Apache2\conf文件夹下,使用EditPlus打开httpd.conf文件进行编辑,如下:
#NameVirtualHost 127.0.0.1:80
<VirtualHost *:80>
    ServerAdmin www.al0574.com
    DocumentRoot d:\Network
    ServerName dummy-host.example.com
#    ErrorLog logs/dummy-host.example.com-error_log
#    CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>
保存后,重启apache服务就可以使用。
三、测试如图:


表示成功运行了。
这样设置运行的好处是,我们在PHP开发过程中,采用实际路径设置的,这样在本地测试完成后,上传服务器不会有错误的。
页: [1]
查看完整版本: 在WAMP下设置本地访问的虚拟主机