[How To] Add a subdomain onto localhost


Recommended Posts

-Alex-

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-
Link to post
Share on other sites
This topic is now closed to further replies.
  • Recently Browsing   0 members

    No registered users viewing this page.