With PHP virtual directory

Source: Internet
Author: User

Configure the PHP virtual directory

----------
Summary
----------
This article provides a very brief overview of how to install apache2.2.x and configure virtual directories under the Windows platform. As a reference for quick installation. The detailed setup of the best documentation is the official documentation in the link below, which is a good solution when installing the configuration with a careful review of the documentation.
1. Apache HTTP Server version 2.2 English document
2. Apache HTTP Server Version 2.2 Chinese document

----------
Preparation Conditions
----------
Tohttp://httpd.apache.org/Download the appropriate version of Apache. (Note: 2.0 and 2.2 versions of Apache corresponding to the module version of the page are not compatible with each other, so you need to download the corresponding version of Apache according to the application). If you do not need to use SSL, download the Apache 2.x.x-win32-x86-no_ssl.msi and if you need to use it, you will need to download Apache 2.x.x-win32-x86-openssl-x.x.x.msi

----------
installation
----------
double-click on the Installer and it will guide you through the installation process. Make sure you enter the correct server URL (if your server does not have a DNS name, you can enter the IP address directly). It is recommended that Apache be installed as "for all Users,on Port 80,as a service" Apache will automatically install a system service to start automatically. Note: If you already have an IIS or other program that uses port 80, the installation may fail. If so, you can find the file httpd.conf in the Apache group\apache2\conf directory under the program directory and change listen 80 to a unused port, such as Listen 81. Then rerun the installer and this time there should be no more problems.

After the installation is complete ,type Http://loccalhost in the browser, and if a Web site is already configured, Apache will be installed successfully. If you install Apache as a service, it will run as the local System account. It would be safer to create a separate user for Apache to run it.

Open the Apache installation directory, locate the file/conf/httpd.conf, and open it for configuration editing. There is a more detailed description of each item in the configuration file, and you can run the test Configuration tool in the Apache installation folder on the Start menu to verify that the profile is correct after the configuration is complete. If the configuration is not correct, a brief description is given. If the test configuration tool is passed after the configuration is complete, but the Apache is still not running smoothly, you can view the records in the [Apache installation directory]/logs/This directory to find out where the problem is.

----------
Configuring the httpd.conf file
----------
# Set the document home directory, followed by the directory of the disk
documentroot "D:/programs/apache2.2/htdocs"

# Add a virtual directory, the following settings in the browser input http://localhost/webpath/when the opportunity to access the server's "D:/programs/webpath" directory
alias/webpath/"D:/programs/webpath"
# when the/webpath does not add "/", in the browser can be entered Http://localhost/webpath Apache will automatically add "/" in the back
Alias/webpath "D:/programs/webpath"

# URL Redirection
Redirect permanent/foo/http://www.example.com/bar/

# Set up a virtual host: Please refer to http://lamp.linux.gov.cn/Apache/ApacheMenu/vhosts/index.html

?

Installing the Apache Configuration virtual directory under win is basically the same as Unin
is to modify httpd.conf
 1: Single IP corresponds to single corn
For example: www.phpunion.com corresponds to 192.168.1.1
Www.feelone.net Correspondence 192.168.1.2
Add the following instructions to the httpd.conf
   #对应玉米所指向的IP
DocumentRoot "c:/web/php" #www. Phpunion.com the directory you want to point to, be sure to have ""
ServerName www.phpunion.com #所要绑的玉米
  

?


   #对应玉米所指向的IP
DocumentRoot "C:/web/feel" #www. Feelone.net the directory you want to point to, be sure to have ""
ServerName www.feelone.net #所要绑的玉米
  
The rest can continue to be tied!

?


2: Single IP corresponds to multiple maize

?

Namevirtualhost 192.168.1.1 #记得一定要有着句啊!
   #对应玉米所指向的IP
DocumentRoot "c:/web/php" #www. Phpunion.com the directory you want to point to, be sure to have ""
ServerName www.phpunion.com #所要绑的玉米
  

#对应玉米所指向的IP
DocumentRoot "C:/web/feel" #www. Feelone.net the directory you want to point to, be sure to have ""
ServerName www.feelone.net #所要绑的玉米
  



This binds to the corresponding directory, if there is no namevirtualhost 192.168.1.1 This command, all the corn will refer to the PHP directory.
Then restart Apache and you will see the corresponding virtual directories for the corn you are referring to!

?


Example:

ServerAdmin [email protected]
Documentroot/www/docs/host.example.com
ServerName host.example.com
Errorlog Logs/host.example.com-error_log
Transferlog Logs/host.example.com-access_log

?

?

?

?

?

Today's website Construction Technology Department of PHP programmer taught me a local implementation of virtual a domain name to access the data of the computer, first of all, I said that my local environment is: WIN2003+XAMPP. In fact, can achieve the effect of the line, the best way to directly use XAMPP is to save the hassle, without a software installation! Then the following step by step implementation virtual a www.123.com to access the local Web site program.
1. Close Xampp Apache, and then locate the C:\xampp\apache\conf\extra\httpd-vhosts.conf file:
Add the following code to the # #NameVirtualHost *:80, where the IP is the IP of the local computer and can go to cmd using ipconfig query to the native IP
Namevirtualhost 192.168.1.101:80
Then copy the following code
##
# #ServerAdmin [email protected]
# #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
##
Change to the following code

# #ServerAdmin [email protected]
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

Which DocumentRoot is the path of the production process of the machine site, servername and Serveralias is to be a virtual domain URL, this is you happy
2. Locate the C:\xampp\apache\conf\httpd.conf file and locate the following code:
DocumentRoot "C:/xampp/htdocs"

Change the path of the above two web directories to the path set above
DocumentRoot "e:/php"

Because the virtual domain URL is set, the path is not added to the site's folder name.
3. Then open the C:\WINDOWS\system32\drivers\etc\hosts file,
Add the virtual domain URL you want to add under 127.0.0.1 localhost
127.0.0.1 localhost
192.168.1.101 www.123.com
Oh, modify the three files after the OK, now you can restart Xampp Apache, and then enter the www.123.com in IE can access the local Web site program, so the benefits of testing is able to put this machine virtual server, some things are very convenient to debug! Of course, With localhost is also accessible, this function is not necessary to do so, I am because sometimes use the Magento program, the use of domain names will be better, there will not be some inexplicable problems. Of course, if you have several sites, every time you have to modify the C:\xampp \apache\conf\extra\httpd-vhosts.conf corresponding DocumentRoot "e:/php/ecshop2.72", Because my web design PHP program is placed in the E-disk under the PHP folder, and then each site on a folder, so each time only need to modify a file OK, see personal hobbies, sharing out let everyone play, hey!

?


?

Detailed configuration: http://httpd.apache.org/docs/2.2/vhosts/

Chinese configuration: http://www.zzxj.net/web/manual/ApacheMenu/rewrite/rewrite_guide.html

?

?

?

?

Configuration of Apache Virtual host

?

Configuration of the virtual host

?

IP address-based virtual host configuration
Listen 80
Documentroot/www/example1
ServerName www.example1.com
Documentroot/www/example2
ServerName www.example2.org

?

?

?

IP and multi-port-based virtual host configuration
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

?

Domain-based virtual host configuration on the server for a single IP address :
# 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

?

to configure a domain-based virtual host on a server with multiple IP addresses :
Listen 80
# This is the ' main ' server running on 172.20.30.40
ServerName server.domain.com
Documentroot/www/mainserver
# This was the other address
Namevirtualhost 172.20.30.50
Documentroot/www/example1
ServerName www.example1.com
# Other directives ...
Documentroot/www/example2
ServerName www.example2.org
# Other directives ...

?

to run a different site on a different port :
Configure a domain-based virtual host on a multi-port-based server.
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

?

configuration of domain-based and IP-based hybrid virtual hosts :
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

?

?

?

Your own settings

?

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

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    Tags Index: