配备PHP虚拟目录
配置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

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

To set up a CGI directory in Apache, you need to perform the following steps: Create a CGI directory such as "cgi-bin", and grant Apache write permissions. Add the "ScriptAlias" directive block in the Apache configuration file to map the CGI directory to the "/cgi-bin" URL. Restart Apache.

When the Apache 80 port is occupied, the solution is as follows: find out the process that occupies the port and close it. Check the firewall settings to make sure Apache is not blocked. If the above method does not work, please reconfigure Apache to use a different port. Restart the Apache service.

Apache connects to a database requires the following steps: Install the database driver. Configure the web.xml file to create a connection pool. Create a JDBC data source and specify the connection settings. Use the JDBC API to access the database from Java code, including getting connections, creating statements, binding parameters, executing queries or updates, and processing results.

There are 3 ways to view the version on the Apache server: via the command line (apachectl -v or apache2ctl -v), check the server status page (http://<server IP or domain name>/server-status), or view the Apache configuration file (ServerVersion: Apache/<version number>).

Apache cannot start because the following reasons may be: Configuration file syntax error. Conflict with other application ports. Permissions issue. Out of memory. Process deadlock. Daemon failure. SELinux permissions issues. Firewall problem. Software conflict.

How to view the Apache version? Start the Apache server: Use sudo service apache2 start to start the server. View version number: Use one of the following methods to view version: Command line: Run the apache2 -v command. Server Status Page: Access the default port of the Apache server (usually 80) in a web browser, and the version information is displayed at the bottom of the page.

The steps to start Apache are as follows: Install Apache (command: sudo apt-get install apache2 or download it from the official website) Start Apache (Linux: sudo systemctl start apache2; Windows: Right-click the "Apache2.4" service and select "Start") Check whether it has been started (Linux: sudo systemctl status apache2; Windows: Check the status of the "Apache2.4" service in the service manager) Enable boot automatically (optional, Linux: sudo systemctl

To delete an extra ServerName directive from Apache, you can take the following steps: Identify and delete the extra ServerName directive. Restart Apache to make the changes take effect. Check the configuration file to verify changes. Test the server to make sure the problem is resolved.
