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


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"

And in your hosts file add this line:       sub.localhost

Here is a useful tutorial you might find helpful.


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: localhost sub.localhost

or on the same line separate by space: sub.localhost subsub.localhost local.host


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

Replace with whatever IP address you want.