how to create virtual host on XAMPP [duplicate]
Step 1) C:\WINDOWS\system32\drivers\etc\ Open the "hosts" file :
127.0.0.1 localhost
127.0.0.1 test.com
127.0.0.1 example.com
Step 2) xampp\apache\conf\extra\httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot C:/xampp/htdocs/test/
ServerName www.test.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot C:/xampp/htdocs/example/
ServerName www.example.com
</VirtualHost>
Step 3) C:\xampp\apache\conf\httpd.conf. Scroll down to the Supplemental configuration section at the end, and locate the following section (around line 500), Remove the # from the beginning of the second line so the section now looks like this:
#Virtual hosts
Include conf/extra/httpd-vhosts.conf
Step 4) Restart XAMPP and now run in your browser :
www.example.com or www.test.com
I see two errors:
<VirtualHost *:80> -> Fix to :8081, your POrt the server runs on
ServerName comm-app.local
DocumentRoot "C:/xampp/htdocs/CommunicationApp/public"
SetEnv APPLICATION_ENV "development"
<Directory "C:/xampp/htdocs/CommunicationApp/public" -> This is probably why it crashes, missing >
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
-> MIssing close container: </VirtualHost>
Fixed version:
<VirtualHost *:8081>
ServerName comm-app.local
DocumentRoot "C:/xampp/htdocs/CommunicationApp/public"
SetEnv APPLICATION_ENV "development"
<Directory "C:/xampp/htdocs/CommunicationApp/public">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
One thing to mention:
You can always try and run command:
service apache2 configtest
This will tell you when you got a malformed configuration and maybe even can tell you where the problem is.
Furthermore it helps avoid unavailability in a LIVE system:
service apache2 restart
will shutdown and then fail to start, this configtest you know beforehand "oops I did something wrong, I should fix this first" but the apache itself is still running with old configuration. :)
Add this Code in C:\xampp\apache\conf\extra\httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName qa-staging.com
ServerAlias www.qa-staging.com
<Directory "c:/xampp/htdocs">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Now Add your virtual host name in bellow file.
C:\Windows\System32\drivers\etc\hosts
127.0.0.1 qa-staging.com
If you are not able to save this code in host file then right click on notpad select Run as administrator and then you can able to save your custom code now restart your XAMP