Home Backend Development PHP Tutorial Apache set up virtual WEB_PHP tutorial

Apache set up virtual WEB_PHP tutorial

Jul 21, 2016 pm 04:08 PM
apache php web example virtual set up


Apache Server sets up virtual WEB

Let’s give an example first:
Suppose your PHP is installed under d:/php/.
Copy php4apache.dll (php4apache2.dll) to d:/php/
Add below Aapche’s httpd.conf:

############################### #####################
Aapche1 is:
LoadModule php4_module "d:/php/php4apache.dll"
Aapche2 is:
LoadModule php4_module "d:/php/php4apache2.dll"

Add extension parsed by PHP:
AddType application/x-httpd-php .phtml .pwml .php3 .php4 .php . php2 .inc .izz
######################################### ############

Now, you only need to restart Apache to support PHP.

#The following line is only supported by Apache1
LoadModule gzip_module modules/ApacheModuleGzip.dll



ApacheModuleGzip (ie: mod_gzip) is an Apache module provided for free by Remote Communications, which can compress static web pages. It works just fine, you just need to compile it with apache (or use it as a DSO).

You can also download it from Bingbing’s website:
http://justdn.com/down/apache/ApacheModuleGzip.dll

More PHP acceleration and buffering suggestions can be found at Bingbing Get it from the PHP document.

How does Apache build a virtual host? The following is a brief introduction to virtual hosts based on domain names.
For example, your server address is: 61.132.27.69 (this is Bingbing), now We want to build two virtual hosts www.justdn.org and www.justdn.com.
Add the following code after Apache’s httpd.conf

########## ###########################################
NameVirtualHost 61.132. 27.69

ServerAdmin webmaster@justdn.com
DocumentRoot C:/home/justdn.com/
ServerName www.justdn.com
ServerAlias ​​justdn.com wwww.justdn.com
ErrorLog logs/www.justdn.com-error_log
CustomLog logs/www.justdn.com-access_log common
ErrorDocument 404 /404.html


ServerAdmin webmaster@justdn.com
DocumentRoot c:/home/justdn.org/
ServerName www.justdn.org
ServerAlias ​​wwww.justdn.org justdn.org
ErrorLog logs/www.justdn.org-error_log
CustomLog logs/www.justdn.org-access_log common

######### ###########################################

Explanation below,
ServerAdmin, is the administrator’s email.
DocumentRoot, the site document directory of the virtual host.
ServerName, the domain name.
ServerAlias ​​justdn.com wwww.justdn.com , indicating that you can use www.justdn.com to access the site, and you can also use justdn.com to access the site.
ErrorDocument 404 /404.html, which refers to customizing the 404 page of the site as the 404.html file in the root directory of the site .



Note:
Unix platform and NT platform use the same apache server settings. The following focuses on the unix platform as an example to illustrate the settings of apache server. It is also worth noting that for the successful setup of a virtual web, about 50% of the workload is in the registration and resolution of domain names. Therefore, generally register the domain name first and then do the virtual WEB settings.

1. IP-type virtual host
IP-type virtual host means that each virtual host corresponds to a unique IP. Multiple IPs can be achieved through multiple physical network cards or virtual network ports. Both Solaris2.5 and Windows NT support this method.
Two methods to configure multiple virtual hosts:
1. Start an httpd process for each virtual host.
Use this method under the following circumstances:
1) Security isolation issues need to be considered. For example, two httpds run on different User, Group, Listen, and ServerRoot. Users of the two cannot access other data except browsing each other's data through the Web. data.
2) Can provide sufficient memory and file descriptors.
Setting method:
Create an independent httpd installation for each virtual host. In the configuration file httpd.conf of each installation path, use the Listen command to specify the IP of the process service, such as: Listen 10.68.37.10: 80
2. Start an httpd process for all virtual hosts.
Use this method in the following situations:
1) Allow sharing httpd configuration between virtual hosts.
2) The computer serves a large number of requests, and running multiple processes reduces server performance and becomes an important consideration.
Setting method:
In the configuration file httpd.conf, use the VirtualHost command to set ServerAdmin, ServerName, DocumentRoot, ErrorLog, TransferLog or CustomLog for each virtual host, such as:
〈VirtualHost www.smallco.com 〉 #It is recommended to use IP here
ServerAdmin webmaster@mail.smallco.com
DocumentRoot /usr/local/etc/httpd/htdocs/smallco
ServerName www.smallco.com #It is recommended to use domain name here
ErrorLog /usr/local/etc/httpd/logs/smallco/error_log
TransferLog /usr/local/etc/httpd/logs/smallco/access_log
〈/VirtualHost〉
〈VirtualHost www.baygroup .org〉 #It is recommended to use IP here
ServerAdmin webmaster@mail.baygroup.org
DocumentRoot /groups/baygroup/www
ServerName www.baygroup.org #It is recommended to use domain name here
ErrorLog / groups/baygroup/logs/error_log
TransferLog /groups/baygroup/logs/access_log
〈/VirtualHost〉
At the same time, you need to configure the virtual network port or network card, and you need to make corresponding settings in DNS.
2. Name-based virtual host (supported by Apache 1.3 or above)
Although IP-based virtual host is good, it is not the best solution. It requires each virtual host to have a dedicated IP, which is difficult to implement on some machines. Name-type virtual host means that each virtual host has a different name but the same IP. Its advantage is that it does not limit the number of virtual hosts, is simple to configure and use, and does not require additional software or hardware. The disadvantage is that the client must support this part of the protocol. Recent versions of browsers support it, but some older versions of browsers do not. But Apache provides a workaround for this.
Setting method:
In the configuration file httpd.conf, use the NameVirtualHost command to set the virtual host, such as:
NameVirtualHost 111.22.33.44
〈VirtualHost 111.22.33.44〉 #It is recommended to use IP here
ServerName www.domain.tld #It is recommended to use the domain name here
DocumentRoot /web/domain
〈/VirtualHost>
At the same time, define www.domain.tld in DNS to point to 111.22.33.44.
Note: When using IP after the NameVirtualHost directive, any URL request using IP is for the virtual host, and the main server will never respond to a URL request using IP. Additionally, some servers wish to be accessed under multiple names. For example, suppose there is a server with a certain IP and you want to be able to access it with the names domain.tld and www2.domain.tld. The method is to use the ServerAlias ​​directive in the VirtualHost directive section. For example: ServerAlias ​​domain.tld *.domain.tld
Attached are some virtual host setting examples.


Attachment: Virtual host setup example
IP type virtual host configuration
Setup 1: The server has two IPs,
111.22.33.44 server.domain.tld
111.22.33.55 www.otherdomain.tld
www.domain.tld is the alias (CNAME) of server.domain.tld, which represents the main server.
Server configuration:
...
Port 80
DocumentRoot /www/domain
ServerName www.domain.tld
〈VirtualHost 111.22.33.55〉
DocumentRoot /www/ otherdomain
ServerName www.otherdomain.tld
...
〈/VirtualHost〉
Setup 2: Basically the same as Setup1, but without setting up a dedicated main server.
Server configuration:
...
Port 80
ServerName server.domain.tld
〈VirtualHost 111.22.33.44〉
DocumentRoot /www/domain
ServerName www.domain .tld
...
〈/VirtualHost〉
〈VirtualHost 111.22.33.55〉
DocumentRoot /www/otherdomain
ServerName www.otherdomain.tld
...
〈/VirtualHost〉
This setting only hits the main server when the URL is http://server.domain.tld
Setup 3: The server has two IPs,
111.22.33.44 server.domain .tld
111.22.33.55 www-cache.domain.tld
www.domain.tld is the alias (CNAME) of server.domain.tld and represents the main server.
www-cache.domain.tld is proxy-cache, the port is 8080, and the web server uses the default 80.
Server configuration:
...
Port 80
Listen 111.22.33.44:80
Listen 111.22.33.55:8080
ServerName server.domain.tld
〈VirtualHost 111.22 .33.44:80〉
DocumentRoot /www/domain
ServerName www.domain.tld
...
〈/VirtualHost〉
〈VirtualHost 111.22.33.55:8080〉
ServerName www-cache.domain.tld
...
〈Directory proxy:〉
order deny,allow
deny from all
allow from 111.22.33
〈/Directory〉
〈/VirtualHost〉

Named virtual host configuration
Setup 1: The server has an IP,
111.22.33.44 server.domain.tld.
www.domain.tld and www .sub.domain.tld is an alias (CNAMEs).
Server configuration:
...
Port 80
ServerName server.domain.tld
NameVirtualHost 111.22.33.44
〈VirtualHost 111.22.33.44〉
DocumentRoot /www/domain
ServerName www.domain.tld
...
〈/VirtualHost〉
〈VirtualHost 111.22.33.44〉
DocumentRoot /www/subdomain
ServerName www.sub.domain.tld
...
〈/VirtualHost>
If you use IP to access the server, since www.domain.tld has the highest priority, it is considered to be the default server or
the first server.
Setup 2: The server has two IPs,
111.22.33.44 server1.domain.tld is used for the main server
111.22.33.55 server2.domain.tld is used for the virtual host
alias www.domain. tld is used for the main server,
alias www.otherdomain.tld is used for one virtual host,
alias www.sub.domain.tld, *.sub.domain.tld is used for another virtual host,
Server configuration:
...
Port 80
ServerName www.domain.tld
DocumentRoot /www/domain
NameVirtualHost 111.22.33.55
〈VirtualHost 111.22.33.55〉
DocumentRoot /www/otherdomain
ServerName www.otherdomain.tld
...
〈/VirtualHost〉
〈VirtualHost 111.22.33.55〉
DocumentRoot /www/subdomain
ServerName www. sub.domain.tld
ServerAlias ​​*.sub.domain.tld
...
〈/VirtualHost〉
Mixed (IP/name) virtual host configuration
Setup: There are three servers IP,
111.22.33.44 server.domain.tld is used for name-type virtual host
111.22.33.55 www.otherdomain1.tld is used for IP-type virtual host
111.22.33.66 www.otherdomain2.tld is used for IP Type virtual host
Server configuration:
...
Port 80
ServerName server.domain.tld
NameVirtualHost 111.22.33.44
〈VirtualHost 111.22.33.44〉
DocumentRoot / www/domain
ServerName www.domain.tld
...
〈/VirtualHost〉
〈VirtualHost 111.22.33.44〉
DocumentRoot /www/subdomain1
ServerName www.sub1. domain.tld
...
〈/VirtualHost〉
〈VirtualHost 111.22.33.44〉
DocumentRoot /www/subdomain2
ServerName www.sub2.domain.tld
...
〈/VirtualHost〉
〈VirtualHost 111.22.33.55〉
DocumentRoot /www/otherdomain1
ServerName www.otherdomain1.tld
...
〈/VirtualHost〉
〈 VirtualHost 111.22.33.66〉
DocumentRoot /www/otherdomain2
ServerName www.otherdomain2.tld
...
〈/VirtualHost〉
Port type virtual host configuration
Setup: The server has An IP,
111.22.33.44 www.domain.tld
does not require another alias or IP. Using a port-type virtual host, you can set up a virtual
virtual host with a configuration different from the main server.
Server configuration:
...
Listen 80
Listen 8080
ServerName www.domain.tld
DocumentRoot /www/domain
〈VirtualHost 111.22.33.44:8080〉
DocumentRoot /www/domain2
...
〈/VirtualHost>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/314749.htmlTechArticleApacheServer sets up a virtual WEB. Let’s give an example first: Assume that your PHP is installed under d:/php/. Copyphp4apache. dll (php4apache2.dll) to d:/php/ Add below Aapche’s httpd.conf: ###################...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

How to set the cgi directory in apache How to set the cgi directory in apache Apr 13, 2025 pm 01:18 PM

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.

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP's Purpose: Building Dynamic Websites PHP's Purpose: Building Dynamic Websites Apr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

What to do if the apache80 port is occupied What to do if the apache80 port is occupied Apr 13, 2025 pm 01:24 PM

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.

How to connect to the database of apache How to connect to the database of apache Apr 13, 2025 pm 01:03 PM

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.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

How to start apache How to start apache Apr 13, 2025 pm 01:06 PM

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

See all articles