The first part is editing httpd-vhosts.conf on xampp server. This is to redirect server on the right configuration when browser call virtualhost. Second part is editing hosts file on windows. Configuration on this file contains the mappings of IP addresses to host names. It will allow you to call virtualhost from web browser
Editing httpd-vhosts.conf
1. Open %xampp folder%\apache\conf\extra\httpd-vhosts.conf with your favorites text editor. Usually the location is C:\xampp\apache\conf\extra\httpd-vhosts.conf
2. Uncomment #NameVirtualHost *:80 so it will be look
NameVirtualHost *:80
3. Uncomment all configuration script that located between
This is the example of virtualhost. First configuration is used for all requests that do not match a ServerName or ServerAlias in any
<VirtualHost *:80>
ServerAdmin test@test.com
DocumentRoot C:/xampp/htdocs
ServerName xampp
ErrorLog C:/xampp/htdocs/access_error.log
</VirtualHost>
<VirtualHost *:80>
ServerAdmin test@test.com
DocumentRoot C:/xampp/htdocs/example
ServerName example.com
ServerAlias www.example.com
ErrorLog C:/xampp/htdocs/example/access_error.log
</VirtualHost>
Below explanation of each configuration
<VirtualHost *:80>: virtualhost configuration according to NameVirtualHost
ServerAdmin: email administration
DocumentRoot: Docoment root folder for the virtualhost
ServerName: virtualhost or domain name
ServerAlias: virtualhost or domain name alias.
ErrorLog: File to create error for this virtualhost
4. Restart your xampp server
Second thing you need to add your virtualhost name into hosts file windows. You should do this in order your windows computer can call the virtualhost name from browser
Edit hosts.conf on Windows
1. Open %windows folder%\system32\drivers\etc\hosts with your favorites text editor. Usually the location is C:\WINDOWS\system32\drivers\etc\hosts. Remember hosts is name of nfile not directory.
2. Add all your virtualhost with ip 127.0.0.1. The IP is local IP address. Below the example:
127.0.0.1 localhost
127.0.0.1 example.ex
127.0.0.1 www.example.ex
127.0.0.1 thisisfor.example.ex
Now you can test from your favorite browser. Congratulation if it work!
Have a nice try!
No comments:
Post a Comment