Home » Php » php – How to make subdomain on my localhost?

php – How to make subdomain on my localhost?

Posted by: admin April 23, 2020 Leave a comment

Questions:

is it possible to create subdomains on my localhost? like sub.localhost
and would like to know how subdomains work.

How to&Answers:

Create a virtual host as such:

<VirtualHost *:80>
    ServerName sub.localhost
    DocumentRoot "C:/public_html/sub"
</VirtualHost>

And in your hosts file add this line:

127.0.0.0       sub.localhost

Here is a useful tutorial you might find helpful.

Answer:

You can make your browser to point to any domain/subdomain that you want as long as you put the ip – hostname definition in your c:\Windows\System32\drivers\etc\hosts file, for example:

127.0.0.1 localhost

127.0.0.1 sub.localhost

or on the same line separate by space:

127.0.0.1 sub.localhost subsub.localhost local.host

Answer:

Add the following to your local hosts file. On windows, it’s located at C:\WINDOWS\system32\drivers\etc\hosts.

127.0.0.1       sub.localhost

Replace 127.0.0.1 with whatever IP address you want.