how to create virtual host on XAMPP
Solution 1
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. :)
Solution 2
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
Solution 3
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
Solution 4
Write these codes end of the C:\xampp\apache\conf\extra\httpd-vhosts.conf file,
DocumentRoot "D:/xampp/htdocs/foldername"
ServerName www.siteurl.com
ServerAlias www.siteurl.com
ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log" common
between the virtual host tag.
and edit the file System32/Drivers/etc/hosts use notepad as administrator
add bottom of the file
127.0.0.1 www.siteurl.com
Solution 5
<VirtualHost *:80>
DocumentRoot "D:/projects/yourdirectry name"
ServerName local.yourdomain.com
<Directory "D:/projects/yourdirectry name">
Require all granted
</Directory>
</VirtualHost>
Save the Apache configuration file.
for detailed info refer to this
Paras Arora
I'm here as a lifelong learner, I thank all the members the StackExchange's community for the great help that comes to me and I try in my turn to give my little help as I can. -about me at Magento Developer
Updated on June 18, 2021Comments
-
Paras Arora almost 3 years
I am sure this question is being asked many times but I am not encounter with a problem. I am using XAMPP where I configure Zend framework.
XAMPP is running on port 8081 as 80 is being occupied by some Windows process I need to use virtual host for that I configure with following code in
C:/xampp/apache/config/extra/httpd-vhosts.config
(orC:/xampp/apache/conf/extra/httpd-vhosts.conf
in newer releases).<VirtualHost *:80> 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>
and also update the hosts file with
127.0.0.1 comm-app.local
and try to re-start apache but it is showing error.15:03:01 [Apache] Error: Apache shutdown unexpectedly. 15:03:01 [Apache] This may be due to a blocked port, missing dependencies, 15:03:01 [Apache] improper privileges, a crash, or a shutdown by another method. 15:03:01 [Apache] Press the Logs button to view error logs and check 15:03:01 [Apache] the Windows Event Viewer for more clues 15:03:01 [Apache] If you need more help, copy and post this 15:03:01 [Apache] entire log window on the forums
-
Steini over 9 yearsThat is a misstake yes, but this would not prevent the apache service from starting, this would merely throw a warning and the vhost would not work
-
Paras Arora over 9 yearsApache start running after these correction but comm-app.local is still nor found on server showing Not Found HTTP Error 404. The requested resource is not found.
-
Paras Arora over 9 yearsApache start running after these correction but comm-app.local is still nor found on server showing Not Found HTTP Error 404. The requested resource is not found.
-
Steini over 9 yearsHave you set-up comm-app.local to redirect to 127.0.0.1 in your hosts file? And are you sure that your path is correct? Oh and ofcours you have to close the VirtualHost container if you didnt... (Updated my post)
-
Paras Arora over 9 yearsyes I just places 127.0.0.1 comm-app.local in hosts file and even restart server
-
Steini over 9 yearsAnd you entered comm-app.local:8081 in browser? (Forgot port maybe)? Rmember to restart your apache after changing config. However if this still wont work something else is wrong in your config-file...
-
karim_fci almost 9 yearsHi! Steini. I am experiencing same problem. Is there any way to avoid typing port no after virtual host name. Thanks in advance
-
Jason Krs about 6 yearsHey amit... Mine is surprisingly not working.... The only differences in my settings are :
127.0.0.4 mycustomdomain
and it runs on port 90 so I used<VirtualHost 127.0.0.4:90>
. It fails when I try in the browserhttp://mycustomdomain
-
Jason Krs about 6 yearsHey amit... Mine is surprisingly not working.... The only differences in my settings are :
127.0.0.4 mycustomdomain
and it runs on port 90 so I used<VirtualHost 127.0.0.4:90>
. It fails when I try in the browserhttp://mycustomdomain
-
Steini almost 6 yearsup "mycustomdomain" must also be redirected to 127.0.0.4. this only happens when its set-up in your hosts file.
-
Moeez about 2 yearsGetting 404 error
-
Moeez about 2 yearsgetting 404 error on browser
-
Moeez about 2 years@ParasArora did you find the solution?
-
Moeez about 2 yearstried with you solution but getting 404 error
-
Moeez about 2 yearsI am getting 404 error
-
Moeez about 2 years@JasonKrs Did you find any solution for it ?