I've trying to create subdomain in my local xampp installation for some time. I tried editing my httpd.conf file and I entered the following:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /ecommerce
ServerName ecomm.localhost
</VirtualHost>
I also edited my windows hosts file and entered: 127.0.0.1 ecomm.localhost
But when I type 'ecomm.localhost' in my firefox it gives me: Access forbidden!!! Can please anybody help me out? What exactly I'm doing wrong? I'm fairly new to this. I simply want to create multiple folders in my 'htdocs' folder and use them as different websites with subdomain. For example: c:\xampp\htdocs\mainSite -----> mainSite.com or mainSite.localhost c:\xampp\htdocs\subSite -----> subSite.mainSite.com or subSite.mainSite.localhost
Try this :
NameVirtualHost 127.0.0.1:80
<VirtualHost *:80>
<Directory "C:\path\to\ecommerce">
Options FollowSymLinks Indexes
AllowOverride All
Order deny,allow
allow from All
</Directory>
ServerName ecomm.localhost
ServerAlias www.ecomm.localhost
DocumentRoot "C:\path\to\ecommerce"
</VirtualHost>
Yes you edited your hosts file correctly.
In addition to atabak's answer:
Go to Apache > Conf > Extra -> "httpd-vhosts.conf" file and add:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/subdomain"
ServerName subdomain.localhost.com
</VirtualHost>
Go to C:\WINDOWS\system32\drivers\etc -> "hosts" file and add:
127.0.0.1 subdomain.localhost
from Setting Up Multiple Subdomains Using Xampp /
In xampp\apache\conf\extra\httpd-vhosts.conf file add these line at the bottom of the file for subdomain support :
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/sandbox"
ServerName sandbox.localhost.com
</VirtualHost>
Then in C:\windows\System32\drivers\etc\hosts file add these line at the bottom of the file :
127.0.0.1 sandbox.localhost.com
After that re-start the xampp server and open a new tab, write in the address bar
sandbox.localhost.com
Then you will see the output of index.php file which was in the sandbox folder
This worked for me. Paste at the bottom of the httpd-vhost.conf file at xampp > Apache > Conf > Extra. Make sure not to comment any vitualhost tag you're adding or you get "Attempting to start Apache" error when you restart server.. foodporch is the name of my subdomain
<VirtualHost *:80>
DocumentRoot "c:/xampp/htdocs"
ServerName localhost
<Directory "c:/xampp/htdocs">
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "c:/xampp/htdocs/foodporch"
ServerName foodporch.localhost
<Directory "c:/xampp/htdocs/foodporch">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Remember to add this line to end of host file at C:\WINDOWS\system32\drivers\etc ->
127.0.0.1 foodporch.localhost.com
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With