how may i set a domain name to point to many subfolders in xampp? - 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

Related

Public folder must be the root if virtual server on Apache is setup correctly

My project name is lsapp (which is inside htdocs)
The problem is when I go to localhost or localhost/lsapp the directory of files is shown on the browser.
I have setup up the C:\xampp\apache\conf\extra
and modified httpd-vhosts.conf as required, Opened hosts files in C:\Windows\System32\drivers\etc and modified as required.
I have checked several times for any typos etc. Everything in these files are now fine.
And there is another file httpd.conf in which I have removed the # in the second line as follows.
.# Virtual hosts
Include conf/extra/httpd-vhosts.conf
One thing is I have found two http.conf files, in the following different locations. All these files are similar. Do I have to do
1) C:\xampp\apache\conf
(The setting is as below)
.# Virtual hosts
Include conf/extra/httpd-vhosts.conf
2) C:\xampp\apache\conf\original
.# Virtual hosts
.#Include conf/extra/httpd-vhosts.conf
Also there is one more http-vhosts.conf file inside C:\xampp\apache\conf\original\extra
IT HAS NO # AND IS AS FOLLOWS:
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "${SRVROOT}/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log" common
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "${SRVROOT}/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
At this point Im not sure about the changes have to me made to these files.
I have restarted Apache and nothing changed.
No codes in this question
The public folder must be the root and the Directory must not be visible on the browser.
On browser lsapp.test gives OBJECT NOT FOUND! ERROR 404 Also it automatically turns to http://lsapp.test/home
This is how the above mentioned files should be setup:
(C:\xampp\apache\conf\extra) httpd-vhosts.conf
....
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/lsapp/public/"
ServerName lsapp.dv
</VirtualHost>
(C:\Windows\System32\drivers\etc) hosts
127.0.0.1 localhost
127.0.0.1 test.com
127.0.0.1 lsapp.dv
(C:\xampp\apache\conf) httpd.conf
#Virtual hosts
Include conf/extra/httpd-vhosts.conf
When you open the upper file, remove the # character from the beginning of the line so that it should look like the above one.
Then restart your local server and go to browser and type in lsapp.dv.

Apache 2.4 ignore httpd-vhosts.conf file

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://

How to Vagrant scotchbox subdomain virtualhost

I have installed vagrant and scotchbox from scotch.io to develop locally and is running like a charm.
Now I need use the subdomains as variable, and i have googled about, but still no working.
I have changed the hosts file and added
192.168.33.10 scotch.box
Is needed add a line for wildcard subdomain hosts?
Also I have added the next line to my conf file
<VirtualHost *:80>
DocumentRoot /var/www/public
ServerName tenant.scotch.box
ServerAlias *.scotch.box
</VirtualHost>
Sorry for my broken english.
Just add
192.168.33.10 tenant.scotch.box
to hosts.
I had the same problem a couple of months ago. On the hosting OS you have to edit the hosts file.
On Windows
C:\Windows\System32\drivers\etc\hosts
On linux
sudo nano /etc/hosts
you have then to add the ip-address of your scotch box with the desired host name
192.168.33.10 tenant.scotch.box
You can even add multiple lines to your hosts file if you have multiple subdomains or you are developing multiple web applications on the same scotch box. For example :
192.168.33.10 sub1.scotch.box
192.168.33.10 sub2.scotch.box
192.168.33.10 sub3.scotch.box
BUT don't forget to edit the virtual host file inside Scotch Box which is located /etc/apache2/sites-available/YOUR_CONFIG.conf
You will need a <VirtualHost *:80> </VirtualHost> for each sub domain. Example:
<VirtualHost *:80>
DocumentRoot /var/www/public
ServerName sub1.scotch.box
ServerAlias *.scotch.box
</VirtualHost>

Virtualhost setup on localhost displays indexof

I'm attempting to set up a virtual host on Windows vista32. I keep getting a listing of the root folder htdocs instead of the site I've setup.
Here's my virtual host entry in Apache httpd-vhosts.conf:
<VirtualHost *:80>
ServerName site-ashback.co.uk
ServerAlias www.site-ashback.co.uk
DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/site-ashback.co.uk"
DirectoryIndex index.php
</VirtualHost>
Hosts file:
127.0.0.1 site-ashback.co.uk
None of the examples I've been using have shown a few entries which are present in my hosts file thus:
127.0.0.1 localhost
::1 localhost
These two lines appear after all the commented examples and I've put my entry after these. Does this suggest I should use'localhost' instead of 127.0.0.1?
When I click my site in the listing it takes me to the site properly but the address then reads: site-ashback.co.uk/site-ashback.co.uk/. All I wanted to do is remove the word 'localhost' from local sites addresses when testing so that the path read like the real domain name when we go live.

Serving several host/domain names on local machine

I have a local PHP server on a Windows machine and the trouble I am having is that within the main root 127.0.0.1/localhost I would like to have several folders/sites that I can call on.
At present I can do localhost/siteA or localhost/siteB with no problem, but what I would like to do is to assign these locations test domain names:
EG: localhost/siteA would be sitea.dev, localhost/siteB would be siteb.dev
Not a problem as I have set up one on the host file and vhost config files.
mysites.dev which is linked to the root/localhost. So I can use it as above
mysites.dev/siteA and mysites.dev/siteB
But I would like to give each of these sites its own vhost name as mentioned above. So I have added the following:
Hosts File
127.0.0.1 mysites.dev
127.0.0.1 sitea.dev
vhost file
<VirtualHost *:80>
DocumentRoot "C:\Websites\"
ServerName mysites.dev
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:\Websites\sitea\"
ServerName sitea.dev
</VirtualHost>
The trouble is that whichever one I call they all seem to simply load the first one, or at least it seems like that, but without the vhost details they all still go to the root so it looks like the host file is directing them to 127.0.0.1 and that it the vhost file seems to be ignored.
SO what am I missing in order to hook up mty individual local sites?
SOLVED: See my answer will mark it as the correct one when i can in a few days.
Your vhosts are both trying to catch anything that comes in on port 80: <VirtualHost *:80>.
You need to specify the vhost name to point to a particular folder:
<VirtualHost sitea.dev:80>
DocumentRoot "C:\Websites\sitea\"
ServerName sitea.dev
</VirtualHost>
<VirtualHost siteb.dev:80>
DocumentRoot "C:\Websites\siteb\"
ServerName sitea.dev
</VirtualHost>
You can find more info on this in the Apache docs: http://httpd.apache.org/docs/2.2/vhosts/examples.html
Well i do feel stupid. After a long look i then noticed that in the config file it was not calling in the vhost file as i placed them in the main httpd.conf and it worked.
So i had to uncomment the following within the httpd.conf file:
# Virtual hosts
Include conf/extra/httpd-vhosts.conf

Resources