参考前面的文章的步骤。
Include conf/extra/httpd-vhosts.conf
将原来的内容删除,添加本地根目录
<VirtualHost *:80>
ServerAdmin postmaster@dummy-host2.localhost
DocumentRoot "C:/wamp/www"
ServerName 127.0.0.1
ServerAlias www.dummy-host2.localhost
ErrorLog "logs/dummy-host2.localhost-error.log"
CustomLog "logs/dummy-host2.localhost-access.log" combined
</VirtualHost>
这使127.0.0.1访问到www根目录
接下来我们配置127.0.0.2使其能访问到phpmyadmin
继续添加配置
<VirtualHost *:80>
ServerAdmin postmaster@dummy-host2.localhost
DocumentRoot "C:\wamp\apps\phpmyadmin4.1.14"
ServerName 127.0.0.2
ServerAlias www.dummy-host2.localhost
ErrorLog "logs/dummy-host2.localhost-error.log"
CustomLog "logs/dummy-host2.localhost-access.log" combined
</VirtualHost>
最后配置127.0.0.3使其能访问到我们自己的项目根目录
<VirtualHost *:80>
ServerAdmin postmaster@dummy-host2.localhost
DocumentRoot "C:/wamp/www/ihanzi"
ServerName 127.0.0.3
ServerAlias www.dummy-host2.localhost
ErrorLog "logs/dummy-host2.localhost-error.log"
CustomLog "logs/dummy-host2.localhost-access.log" combined
</VirtualHost>
那么为什么要这样配置呢。
很多php开发者使用xampp,wamp等软件本地开发。
有了一个新项目,就在网站根目录下新建一个目录,如test
然后浏览器通过http://localhost/test/访问
看似方便,其实不然,以后把项目移植到网上去,路径上会出现很多问题,初学者应该避免这点。所以就按照本文的方法在本地编写项目即可。
原文地址:http://blog.csdn.net/sbsujjbcy/article/details/44836339