Apache set up virtual WEB_PHP tutorial
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>

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

AI Hentai Generator
Generate AI Hentai for free.

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



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.

PHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability.

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.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

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

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.

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.
