[How To] Add a subdomain onto localhost


Recommended Posts

Well I needed to do this myself so I could replicate some scripts as they would appear on a remote server, so here is how to do it; it is very simple:

1) Open up your terminal

2) sudo pico /etc/hosts

3) Move to the next free line and add:

127.0.0.1 subdomain.localhost

4) Ctrl+o to save, then ctrl+x to exit

5) sudo pico /etc/httpd/httpd.conf

6) Ctrl+w to find: <VirtualHost *:80>

7) Add:

NameVirtualHost localhost

<VirtualHost localhost:80>

ServerName localhost

DocumentRoot "/path/to/default/dir/without/subdomain"

DirectoryIndex index.php index.html index.html index.htm index.shtml

</VirtualHost>

NameVirtualHost subdomain.localhost

<VirtualHost subdomain.localhost:80>

ServerName subdomain.localhost

DocumentRoot "/path/to/the/dir/that/you/want/to/use/as/your/subdir/"

DirectoryIndex index.php index.html index.html index.htm index.shtml

</VirtualHost>

8) Ctrl+o to save, then ctrl+x to exit

9) Now, restart Apache using:

sudo apachectl stop

sudo apachectl start

For Apache to notice the changes.

Done! :D

post-176093-1189268506_thumb.png

Edited by -Alex-
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

  • Recent Achievements

    • Week One Done
      davidbazooked earned a badge
      Week One Done
    • One Month Later
      Jamswaz earned a badge
      One Month Later
    • Week One Done
      Jamswaz earned a badge
      Week One Done
    • Rookie
      Marzoid went up a rank
      Rookie
    • Community Regular
      coch went up a rank
      Community Regular
  • Popular Contributors

    1. 1
      +primortal
      514
    2. 2
      PsYcHoKiLLa
      185
    3. 3
      +Edouard
      159
    4. 4
      Steven P.
      83
    5. 5
      ATLien_0
      75
  • Tell a friend

    Love Neowin? Tell a friend!