To know how to install "Apache", read :
- Our tutorial "Simultaneous installing PHP 5 and PHP 4 on a Windows computer" to manually install apache and php.
- Or our tutorial "How to install Apache / PHP / MySQL Server Easily" to install easily : apache, php and mysql
To create "VirtualHost" accessible from the local network, you must edit the "httpd.conf" file located in "[apache_folder]\conf". Configuring virtual host is the end of this file.
For this tutorial, we will use "IP addresses" filters defined by the first line "<VirtualHost *:80>" :
- The "*" character is a character that means no matter what character string so in our case it takes all IP or domain name but if you want to use a domain name you will need a DNS server in your local network for this to work.
- And the number after the ":" is the port number. In this cas, is the port "80" because it's the port that is used by default by the "HTTP" protocol.
So we will create and implement some VirtualHost and set a different port per website (VirtualHost).
To configure the VirtualHost, you must first add the port you want to use in the listen ports of Apache. For this, look for this line :
Once this line found, for example, add this line just below :
Now our apache server "listens" on ports 80 and 81.
We will now create two VirtualHost.
1) Let the line "NameVirtualHost localhost" as is. For those who don't know what is "localhost", it is a domain redirected to the IP address "127.0.0.1" that corresponds to the IP address of your network card. You can access your website hosted with your apache server by typing this address. But to access your website by the network, you must use the IP address of the machine and not the IP : "127.0.0.1".
To know the IP address of your machine, read our tutorial "Know your LAN IP address".
2) Create 2 virtualhost respecting this :
<VirtualHost *:[port_number]> ServerAdmin [your_name]@[gmail,hotmail,...].com DocumentRoot [absolute path to the directory of your website without the / at the end] </VirtualHost>
Note : Here is an example that we use on our own local server. Knowing that our first website is located in the root folder (by default called htdocs) containing web pages and our second site named "InformatiWeb-v2" which is located in a folder named "InformatiWeb-v2".
# # Use name-based virtual hosting. # NameVirtualHost localhost # # VirtualHost example: # Almost any Apache directive may go into a VirtualHost container. # The first VirtualHost section is used for requests without a known # server name. # <VirtualHost *:80> ServerAdmin email@example.com DocumentRoot f:/server/www-php5 </VirtualHost> <VirtualHost *:81> ServerAdmin firstname.lastname@example.org DocumentRoot f:/server/www-php5/InformatiWeb-v2 </VirtualHost>
It's recommended to set a static IP address to prevent it changes every x time, for that follow our tutorial : "Define a private static IP address".
® InformatiWeb.net 2008-2020 - © Lionel Eppe - All rights reserved.
Total or partial reproduction of this site is prohibited and constitutes an infringement punishable by articles L.335-2 and following of the intellectual property Code.