配置PHP虚拟目录
----------
摘要
----------
本文极为简要的介绍了如何在Windows平台下安装Apache2.2.x并配置虚拟目录. 以作为快速安装的参考.
详细的设置最好的文档是官方的说明文档见下方的链接, 在安装配置的时候仔细的查阅文档是很好的解决办法.
1. Apache HTTP Server Version 2.2
英文文档
2. Apache HTTP Server Version 2.2
中文文档
----------
准备条件
----------
到 http://httpd.apache.org/
下载相应版本的Apache. (注意: 2.0与2.2版本的Apache对应的Module版本页不同, 互相不兼容,
因此需要根据应用程序来下载相应版本的Apache). 如果不需要使用ssl, 则要下载 Apache 2.x.x-win32-x86-no_ssl.msi,
如果需要使用, 则需要下载Apache
2.x.x-win32-x86-openssl-x.x.x.msi
----------
安装
----------
双击安装程序,
它将引导你完成整个安装过程。请确保你输入正确的服务器URL(如果你的服务器没有DNS名称,你可以直接输入IP地址)。建议将Apache安装成" for all
Users,on Port 80,as a service"
Apache将自动安装一个系统服务以自动启动。注意:如果你已经有一个IIS或者其它的程序使用80端口,安装可能会失败。如果是这样,你可以到程序目录下的Apache
Group\Apache2\conf目录中找到文件httpd.conf,将其中的Listen 80改成一个不用的端口,比如Listen
81。然后重新运行这个安装程序,这次应该不会再有问题了。
安装结束之后在浏览器中键入 http://loccalhost,如果呈现了一个已经配置好的网站,那么Apache就安装成功了。
如果你将Apache安装成一个服务,它将以本地system帐户来运行。为Apache创建一个单独的用户来运行它将会更安全一些。
打开Apache的安装目录, 找到文件 /conf/httpd.conf,
打开它进行配置的编辑. 配置文件中对于各项都有比较详细的描述, 在配置结束之后可以运行开始菜单中Apache安装文件夹中的Test
Configuration工具来检验配置文件是否正确. 如果配置不正确会给出简要的说明. 如果在配置结束之后通过了Test Configuration工具,
但是仍然不能够顺利运行Apache, 可以到[Apache安装目录]/logs/ 这个目录中查看记录,
以找出问题所在.
----------
配置
httpd.conf文件
----------
# 设置文档主目录, 后面的就是磁盘的目录
DocumentRoot
"D:/Programs/Apache2.2/htdocs"
# 添加虚拟目录, 下面的设置在浏览器中输入 http://localhost/webpath/ 的时候机会访问服务器的"D:/Programs/WebPath"目录
Alias /webpath/
"D:/Programs/WebPath"
# 当/webPath 后面不加"/"的话, 在浏览器中可以输入 http://localhost/webpath Apache会自动的在后面添加"/"
Alias /webpath
"D:/Programs/WebPath"
# URL 重定向
Redirect permanent
/foo/ http://www.example.com/bar/
# 设定虚拟主机: 请参考 http://lamp.linux.gov.cn/Apache/ApacheMenu/vhosts/index.html
?
在WIN下安装APACHE配置虚拟目录和UNIN下基本是一样的
就是修改httpd.conf
1:单个IP对应单个玉米
例如:www.phpunion.com对应192.168.1.1
www.feelone.net对应192.168.1.2
在httpd.conf中加入如下指令
DocumentRoot "c:/web/php" #www.phpunion.com要指向的目录,注意一定要有""
ServerName www.phpunion.com #所要绑的玉米
?
DocumentRoot "c:/web/feel" #www.feelone.net要指向的目录,注意一定要有""
ServerName www.feelone.net #所要绑的玉米
剩下的可以继续绑!
?
2:单个IP对应多个玉米
?
NameVirtualHost 192.168.1.1 #记得一定要有着句啊!
DocumentRoot "c:/web/php" #www.phpunion.com要指向的目录,注意一定要有""
ServerName www.phpunion.com #所要绑的玉米
DocumentRoot "c:/web/feel" #www.feelone.net要指向的目录,注意一定要有""
ServerName www.feelone.net #所要绑的玉米
这样就绑上对应的目录了,如果没有NameVirtualHost 192.168.1.1 这个指令的话,所有的玉米就都指到php目录了.
然后重新启动apache,就可以看到所指的玉米对应相应的虚拟目录!
?
Example:
ServerAdmin webmaster@host.example.com
DocumentRoot
/www/docs/host.example.com
ServerName host.example.com
ErrorLog
logs/host.example.com-error_log
TransferLog
logs/host.example.com-access_log
?
?
?
?
?
今天网站建设技术部的PHP程序员教了我一个在本地实现虚拟一个域名来访问本机电脑的数据的方法,首先说说我本地的环境是:WIN2003+xampp。其实能实现效果就行,直接用xampp的最好方法就是省事,不用一个一个软件安装!然后下面一步一步实现虚拟一个www.123.com来访问本地网站程序。
1.关闭xampp的apache,然后找到C:\xampp\apache\conf\extra\httpd-vhosts.conf文件:
在##NameVirtualHost
*:80 下面加入以下代码,其中的IP为本地电脑的IP,可以进入CMD使用ipconfig查询到本机IP
NameVirtualHost
192.168.1.101:80
然后把以下代码复制一份
##
##ServerAdmin postmaster@dummy-host2.localhost
##DocumentRoot
"C:/xampp/htdocs/dummy-host2.localhost"
##ServerName
dummy-host2.localhost
##ServerAlias www.dummy-host2.localhost
##ErrorLog "logs/dummy-host2.localhost-error.log"
##CustomLog
"logs/dummy-host2.localhost-access.log"
combined
##
修改成以下代码
##ServerAdmin postmaster@dummy-host2.localhost
DocumentRoot
"E:/php/ecshop2.72"
ServerName www.123.com
ServerAlias
www.123.com
##ErrorLog "logs/dummy-host2.localhost-error.log"
##CustomLog "logs/dummy-host2.localhost-access.log"
combined
其中DocumentRoot
是本机网站制作程序的路径,ServerName及ServerAlias
就是要虚拟的域名网址,这个随便你高兴了
2.找到C:\xampp\apache\conf\httpd.conf文件,找到以下代码:
DocumentRoot
"C:/xampp/htdocs"
把上面的两个网站目录的路径修改成上面设置的路径
DocumentRoot
"E:/php"
因为设置了虚拟的域名网址,所以路径不用再加上网站的文件夹名称了
3.然后打开C:\WINDOWS\system32\drivers\etc\hosts
文件,
在127.0.0.1 localhost下添加你要添加的虚拟域名网址
127.0.0.1
localhost
192.168.1.101
www.123.com
呵呵,修改这三个文件之后就OK了,现在可以重新启动xampp的apache了,然后在IE里输入www.123.com就能访问本地的网站程序了,这样测试的好处是能把本机虚拟成服务器,有些东东很方便就能调试!当然,用localhost也是还可以访问了,这个功能用不到的话也没必要这么搞,我是因为有时用到Magento程序,使用域名会更好,不会有一些莫名其妙的问题。当然了,如果你有好几个网站的话,每次都要修改一下C:\xampp
\apache\conf\extra\httpd-vhosts.conf对应的DocumentRoot
"E:/php/ecshop2.72",因为我的网页设计的PHP程序都是放在E盘下的PHP文件夹,然后每个网站就一个文件夹,这样每次只需要修改一个文件就OK了,看个人爱好了,共享出来让大家玩玩,嘿嘿!
?
?
详细配置:http://httpd.apache.org/docs/2.2/vhosts/
中文配置:http://www.zzxj.net/web/manual/ApacheMenu/rewrite/rewrite_guide.html
?
?
?
?
Apache虚拟主机的配置
?
虚拟主机的配置
?
基于IP地址的虚拟主机配置
Listen 80
DocumentRoot
/www/example1
ServerName www.example1.com
DocumentRoot
/www/example2
ServerName www.example2.org
?
?
?
基于IP和多端口的虚拟主机配置
Listen 172.20.30.40:80
Listen
172.20.30.40:8080
Listen 172.20.30.50:80
Listen 172.20.30.50:8080
?
DocumentRoot /www/example1-80
ServerName www.example1.com
DocumentRoot
/www/example1-8080
ServerName www.example1.com
DocumentRoot
/www/example2-80
ServerName www.example1.org
DocumentRoot
/www/example2-8080
ServerName www.example2.org
?
单个IP地址的服务器上基于域名的虚拟主机配置:
# Ensure that Apache listens on
port 80
Listen 80
# Listen for virtual host requests on all IP
addresses
NameVirtualHost *:80
DocumentRoot /www/example1
ServerName
www.example1.com
ServerAlias example1.com. *.example1.com
# Other
directives here
DocumentRoot /www/example2
ServerName
www.example2.org
# Other directives here
?
在多个IP地址的服务器上配置基于域名的虚拟主机:
Listen 80
# This is the
“main” server running on 172.20.30.40
ServerName
server.domain.com
DocumentRoot /www/mainserver
# This is the other
address
NameVirtualHost 172.20.30.50
DocumentRoot
/www/example1
ServerName www.example1.com
# Other directives here
…
DocumentRoot /www/example2
ServerName www.example2.org
# Other
directives here …
?
在不同的端口上运行不同的站点:
基于多端口的服务器上配置基于域名的虚拟主机。
Listen
80
Listen 8080
NameVirtualHost 172.20.30.40:80
NameVirtualHost
172.20.30.40:8080
ServerName www.example1.com
DocumentRoot
/www/domain-80
ServerName www.example1.com
DocumentRoot
/www/domain-8080
ServerName www.example2.org
DocumentRoot
/www/otherdomain-80
ServerName www.example2.org
DocumentRoot
/www/otherdomain-8080
?
基于域名和基于IP的混合虚拟主机的配置:
Listen 80
NameVirtualHost
172.20.30.40
DocumentRoot /www/example1
ServerName
www.example1.com
DocumentRoot /www/example2
ServerName
www.example2.org
DocumentRoot /www/example3
ServerName www.example3.net
?
?
?
自己的设置
?
hosts
?
?
?
127.0.0.1 localhost
127.0.0.1 fantsi
?
?
?
httpd.conf
?
?
?
Alias /fantsi/ "E:/xampp/htdocs/fantsi"
NameVirtualHost
127.0.0.1
DocumentRoot
"E:/xampp/htdocs"
ServerName localhost
ServerAlias
localhost
DocumentRoot "E:/xampp/htdocs/fantsi"
ServerName fantsi
ServerAlias fantsi

aphpdepentioncontiveContainerIsatoolThatManagesClassDeptions,增强codemodocultion,可验证性和Maintainability.itactsasaceCentralHubForeatingingIndections,因此reducingTightCightTightCoupOulplingIndeSingantInting。

选择DependencyInjection(DI)用于大型应用,ServiceLocator适合小型项目或原型。1)DI通过构造函数注入依赖,提高代码的测试性和模块化。2)ServiceLocator通过中心注册获取服务,方便但可能导致代码耦合度增加。

phpapplicationscanbeoptimizedForsPeedAndeffificeby:1)启用cacheInphp.ini,2)使用preparedStatatementSwithPdoforDatabasequesies,3)3)替换loopswitharray_filtaray_filteraray_maparray_mapfordataprocrocessing,4)conformentnginxasaseproxy,5)

phpemailvalidation invoLvesthreesteps:1)格式化进行regulareXpressecthemailFormat; 2)dnsvalidationtoshethedomainhasavalidmxrecord; 3)

tomakephpapplicationsfaster,关注台词:1)useopcodeCachingLikeLikeLikeLikeLikePachetoStorePreciledScompiledScriptbyTecode.2)MinimimiedAtabaseSqueriSegrieSqueriSegeriSybysequeryCachingandeffeftExting.3)Leveragephp7 leveragephp7 leveragephp7 leveragephpphp7功能forbettercodeefficy.4)

到ImprovephPapplicationspeed,关注台词:1)启用opcodeCachingwithapCutoredUcescriptexecutiontime.2)实现databasequerycachingusingpdotominiminimizedatabasehits.3)usehttp/2tomultiplexrequlexrequestsandredececonnection.4 limitsclection.4.4

依赖注入(DI)通过显式传递依赖关系,显着提升了PHP代码的可测试性。 1)DI解耦类与具体实现,使测试和维护更灵活。 2)三种类型中,构造函数注入明确表达依赖,保持状态一致。 3)使用DI容器管理复杂依赖,提升代码质量和开发效率。

databasequeryOptimizationinphpinvolVolVOLVESEVERSEVERSTRATEMIESOENHANCEPERANCE.1)SELECTONLYNLYNESSERSAYCOLUMNSTORMONTOUMTOUNSOUDSATATATATATATATATATATRANSFER.3)


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

安全考试浏览器
Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

Dreamweaver CS6
视觉化网页开发工具

Atom编辑器mac版下载
最流行的的开源编辑器