• Sign in to Neowin Faster!

    Create an account on Neowin to contribute and support the site.

Sign in to follow this  

[How To] Add a subdomain onto localhost

Recommended Posts

-Alex-    101

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-

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.