Where can I find the httpd-vhosts.conf file to setup virtual hosts when using XAMPP?
Windows: C:\XAMPP\apache\conf\extra\httpd-vhosts.conf
Mac: /Applications/XAMPP/xamppfiles/etc/extra/httpd-vhosts.conf
Linux: /opt/lampp/etc/extra/httpd-vhosts.conf
Note that you have to edit the httpd.conf in the parent folder to include the file:
Include etc/extra/httpd-vhosts.conf
Alternatively, you can also insert virtual hosts in the httpd-xampp.conf which is included in XAMPP by default:
Windows: C:\XAMPP\apache\conf\extra\httpd-xampp.conf
Mac: /Applications/XAMPP/xamppfiles/etc/extra/httpd-xampp.conf
Linux: /opt/lampp/etc/extra/httpd-xampp.conf
Related
So, i have a little issue here, i installed XAMPP which uses Apache on a Ubuntu desktop Virtual machine(on vbox), i also created a Laravel project on it and it works fine when i access it from the same VM itself !
Accessing the home page from firefox ubuntu
however when i try to access it from my host windows machine it just access to the XAMPP home page like this :
access from chrome windows
now my ubuntu VM has its address set to 192.168.1.50 and my windows 192.168.1.8 !
i also added to the windows machine "etc" file the entry :
192.168.1.50 usthbcloud.com
and to my ubuntu machine:
127.0.0.1 usthbcloud.com
my httpd.conf file of the XAMPP includes the file : httpd-vhosts.conf
i modified the httpd-vhosts.conf to the following :
vhosts.conf
Any solutions ?..
You're Facing issues in windows. Try this
<VirtualHost *:80>
DocumentRoot "D:/XAMPP/htdocs/"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "D:/XAMPP/htdocs/eduguru/public/"
ServerName eduguruacademy.com
</VirtualHost>
Try this in your httpd-vhosts.conf. Replace with your DocumentRoot & ServerName Accordingly. Then restart XAMPP
Actually I have many sub folders inside htdocs directory each folder contain an index.php file and have a separate action.
How may I set my domain name so it will be pointing to all of these sub folders?
Lets say i have c:\server\ht docs\folder1, c:\server\ht docs\folder2 and so on. I would like my domain name to act like localhost. When typing www.domain name.com/folder1 it will take me to c:\server\folder1 and so on for all of the folders.
I tried with localhost and it works.
Step 1:
Edit the windows "host" file located in
C:\Windows\System32\drivers\etcas an administrator.
Add the following line in the host file and save it:
127.0.0.1 www.domain_name.com
Step 2:
Open the "httpd-vhosts.conf" file located in
C:\xampp\apache\conf\extra
Add the below lines and save.
<VirtualHost *:80>
ServerName www.domain_name.com
ServerAlias www.domain_name.com
DocumentRoot c:/xampp/htdocs
</VirtualHost>
Now restart apache server using XAMPP Control Panel
You can resolve using VirtualHost configure or redirect URL
All the answers about adding domain to xampp subfolders are missing some steps, so I'll add mine which is more or less complete.
If you've changed httpd.conf or httpd-vhosts.conf files, return them to default. Specifically, in httpd.conf make sure your DocumentRoot points to default location, we will instead use vhosts file to point domains to different subfolders each:
DocumentRoot "/opt/lampp/htdocs/"
<Directory "/opt/lampp/htdocs/>
in httpd.conf file (main apache config) find and uncomment:
#Include etc/extra/httpd-vhosts.conf to: Include etc/extra/httpd-vhosts.conf
in etc/extra/httpd.vhosts file, add your domain and specify its DocumentRoot (That should be one of the folders in htdocs):
<VirtualHost *:80>
ServerAdmin webmaster#example.ge
DocumentRoot "/opt/lampp/htdocs/example-landing-testing"
ServerName example.local
ErrorLog "logs/example.testing-error_log"
CustomLog "logs/example.testing-access_log" common
</VirtualHost>
in your system's hosts file, add the following:
127.0.0.1 example.local
restart apache
no need to restart system
Optional: If you're running xampp in WSL, you will also need to modify windows's hosts file to point to WSL's IP:
Open notepad as administrator
Open file: C:\Windows\System32\drivers\etc\hosts
In wsl terminal instance, run this handy command to get its IP:
ip addr show eth0 | grep 'inet\b' | awk '{print $2}' | cut -d/ -f1
Add IP to hosts file:
172.20.13.40 example.local
Save, no need to restart system
I have been following this steps setup apache virtualhost (windows) to create a Virtual Host in Windows but I don't know what is wrong because it doesn't work.
I want a virtual host with this url: http://local.shop.
httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "C:/Apache24/htdocs/"
ServerName localhost
ServerAlias localhost
<Directory "C:/Apache24/htdocs/">
AllowOverride All
</Directory>
<VirtualHost *:80>
DocumentRoot "C:/Apache24/htdocs/shop/"
ServerName local.shop
ServerAlias local.shop
<Directory "C:/Apache24/htdocs/shop/">
AllowOverride All
</Directory>
ErrorLog "logs/localhost.html-error.log"
CustomLog "logs/localhost.html-access.log" common
</VirtualHost>
hosts
127.0.0.1 localhost
127.0.0.1 local.shop
If I try to access to http://localhost the page served is the page which is on C:/Apache24/htdocs/shop/ but if I try to access to http://local.shop I've got the next error ERR_NAME_NOT_RESOLVED
What am I doing wrong?
Edit 1:
I have removed ServerAlias directives and now If I try to access to http://localhost the page served is the right page, but if I try to acces to http://local.shop still doesn't work. I've got the same error ERR_NAME_NOT_RESOLVED
Edit 2:
I have used "ping" command from windows to try to reach to each host. And I get a response from localhost but not from local.shop
Edit 3:
I have made a change in my definition of localhost in httpd-vhosts.conf. I have changed DocumentRoot to "C:/Apache24/htdocs/shop"
<VirtualHost *:80>
DocumentRoot "C:/Apache24/htdocs/shop"
ServerName localhost
ServerAlias localhost
<Directory "C:/Apache24/htdocs/">
AllowOverride All
</Directory>
</VirtualHost>
Instead of getting the default page from shop directory, I still getting the default page from original localhost. It seems like Apache ignore httpd-vhosts.conf file.
Apache maybe listening (in case you restarted it after editing vhosts file), but nothing points to it. You need to edit your hosts file (located under C:\Windows\System32\drivers\etc\hosts) and point domain "local.shop" to IP address 127.0.0.1 so Apache can pickup from there. You may edit that file with Notepad, opened with admin rights.
It should looks something like this:
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 local.shop
I encountered this same issue installing Apache 2.4 on Nov. Tuesday 2nd, 2021 at 2:37 pm.
Things you need to do if you are installing Apache without WAMP or LAMP:
If you do not want to do much configurations, unzip your downloaded files on c:\Apache 2.4 as many tutorials asked you to do.
If you want to use httpd command variable you need to add c:\Apache 2.4\bin into your Environment Variables path.
THIS IS WHAT MOST PEOPLE FAILED TO ADDRESS :: If you are going to create Virtual Hosts you need to open c:\Apache 2.4\bin\conf\httpd.conf in your favorite text editor or IDE and look for the line or statement #Include conf/extra/httpd-vhosts.com and uncomment it, which means removing the # (pound) sign at the beginning. At the time of this writing is line 510. It should look as follow:
509 #Virtual hosts
510 Include conf/extra/httpd-vhosts.conf
You need to open you text editor as admin and edit c:\windows\system32\drivers\etc\hosts file and add all your virtual hosts as so, you get the idea:
127.0.0.1 vhOne.com #your virtual host server name
127.0.0.1 vhTwo.com #your second virutal host server name
After doing that close any terminal and open that again, and you should be able to go to your terminal, without having to cd to the Apache directory all the time, just by typing:
> httpd -k install
> httpd -v
> httpd -k restart
You should also be able to ping your virtual host from the terminal and expect the response desired:
ping vhOne.com
And you should be able to visit your virtual host URL. Keep in mind that at first most browsers won't recognized 127.0.0.1 URL to be web addresses but search string so you have to type http://vhOne.com with the http:// in the URL. After that first visit you can go back by typing the server name without the http://
We are using an AFP server in our network to synchronize all home directories on all mac's in the office. This is working just fine, only not when an user is moving to another mac and wants to reach for it's "htdocs" files (this directory won't sync because it's not in the home directory).
I found out that there is a possibility to change the location of the localhost root directory. To change the root directory you've to modify the DocumentRoot and Directory path inside the /Applications/XAMPP/xamppfiles/etc/httpd.conf file. Unfortunately it's not possible to use a path similar to ~/ this will give the following error, when restarting Apache:
AH00526: Syntax error on line 229 of /Applications/XAMPP/xamppfiles/etc/httpd.conf:
DocumentRoot must be a directory
Is it possible to use for example ~/www so all user that login on the mac will have there own xampp directory. I also wonder if it's possible to make an alias to escape the error?
Refering to the answer on the question, "Apache wildcard documentroot".
Use VirtualDocumentRoot.
<VirtualHost *:80>
ServerName localhost
ServerAlias *.local
VirtualDocumentRoot /Users/%1/Sites
</VirtualHost>
I set up XAMPP running apache and tried to set up the virtual host, but it wouldn't work, I keep getting routed to the XAMPP splash page. http://localhost/index.html says "It works!"
I uncommented the are where it said vhost_alias module, httpd-vhosts and rewrite_module.
I also added the following to my httpd-vhosts.conf & httpd.conf files:
<Directory "C:/Sites/test.dev-web">
Allow From All
AllowOverride FileInfo
Options +FollowSymLinks
</Directory>
<VirtualHost *:80>
ServerName "test.dev-web"
DocumentRoot "C:/Sites/test.dev-web"
</VirtualHost>
I also added this to my hosts file in my system32\drivers\etc:
127.0.0.1 test.dev
I also have 127.0.0.1 localhost in that file
However whenever I type in test.dev in chrome, it takes me to the xampp splash page (test.dev/xampp).
Running windows 7 and XAMPP 1.7.4
XAMPP says that apache is running on the control panel.
I shut off all programs that could be running port 80 (skype)
Any ideas on what's wrong?
Follow the step mentioned here -
http://foundationphp.com/tutorials/apache22_vhosts.php
Easy solution: Delete XAMPP's local test site (xampp/htdocs) and replace it with your own site.
The Correct solution: Set up proper virtual hosts. Set up multiple virtual hosts on windows
or the link that Vinay shared will give you a good guide.