Search code examples
apachenetwork-programmingdnswebserverlan

access local apache server with imaginary domain


I actually don't know many things about server-side things (other than some PHP), but I'm trying to get familiar with it, so here's the problem:

I just downloaded Apache HTTP Server and it works like a charm. I even tried it on local network and it still does work, but when I need to access files, I need to type local ip address like "192.168.1.33", but I need to access it by domain name that doesn't exist on web. The whole network is isolated and it is not connected to internet. Is there any way to do so?

For example, would it be possible to access my server with domain like "myname.com" or "myname.local"';

I tried to find solution to this problem both on google and here too, but without luck, but maybe that is due to my lack of knowledge, so I will apologise in advance if I'm asking something really easy or silly and if there is a resource that could help me, I would really appreciate giving me directions ;)


Solution

  • Follow these steps to configure a custom domain on apache through windows:

    Open Notepad (As Administrator): c:\windows\System32\drivers\etc\hosts

    Add a line to the bottom:

    127.0.0.1     yourfakedomain.local
    

    Then, open your apache configuration: /bin/apache/Apache/conf/httpd.conf

    Add these lines to the bottom:

    <VirtualHost *:80>
      ServerName yourfakedomain.local
      ServerAlias www.yourfakedomain.local
      DocumentRoot "c:\path\to\your\code"
      DirectoryIndex index.php
    </VirtualHost>
    

    Note: you can also put the apache configuration in your /bin/apache/conf/extra/httpd-vhosts.conf file if you have it set to be read in httpd.conf.

    Then, gracefully restart apache:

    From Command prompt: service httpd graceful

    ..or Restart Services from your GUI.