How To Subdomain Localhost — Ubuntu / OSX

Using Gnome + Ubuntu (7.04 Feisty Fawn) + Apache 2

Step 1:
In gnome goto System -> Administration -> Network and click on the ‘Hosts’ tab

Step 2:
For your normal localhost (127.0.0.1) double-click or hit ‘properties’ to edit it. Add your list of subdomains under localhost.

*Ignore the text in this pic, I overlooked that you had to include _all_ aliases in the same box. Whoops

Step 3:
The fun step
Open a terminal and type sudo gedit /etc/apache2/sites-available/default — assuming you’re using the “default” httpd.conf. Chances are that you will be, and if you aren’t you should know what file I’m talking about anyway. (If you don’t, just load one of the enabled apache configuration files)

Change these lines:

NameVirtualHost *
<VirtualHost *>

to

NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1>

Step 4:
Add the following (for each subdomain you made) — changing the ServerName to whatever you aliased in the network host dialogue and DocumentRoot to wherever you want the subdomain to point.

<VirtualHost 127.0.0.1>
	ServerName mysql.localhost
	DocumentRoot /var/www/phpmyadmin
</VirtualHost>

Step 5:
In a terminal type: sudo apache2ctl restart
When that finishes, browse to http://mysql.localhost and you should see phpMyAdmin (going by my example)

On OSX + Apache 1.33

Step 1:
Open /Applications/Utilities/NetInfo Manager and click on “machines”
I usually just duplicate the localhost settings, or just create a new record below localhost that is something like:

ip_address: 127.0.0.1
name: mysql.localhost
serves: ./local

Click for bigger version

Step 2:
Repeat Steps 3-5 above only editing “/etc/httpd/users/{yourname}.conf” instead.

Click for bigger version

Restart Apache and hopefully all went well. I found this useful because I hate typing unnecessary paths :)



Comments

  1. Matt Alexander September 30th

    Comment Arrow

    THANK YOOOUUU!!


  2. Moloch November 2nd

    Comment Arrow

    I believe you can use the full 127.0.0.0/8 range too.

    Not sure what it brings you, just a fwiw.


  3. elixir November 18th

    Comment Arrow

    This worked perfectly for me, though the NameVirtualHost *
    lines didn’t pre-exist in OSX.

    Many thanks!


  4. joe February 19th

    Comment Arrow

    Damn, its not working for me, for weird reason i followed all the steps and… when i do a sdfmud.firecrap.com the site its nos displayed… my vhost is like this:

    ServerName sdfmud.firecrap.com
    ServerAdmin youremail@mydomain.org

    DirectoryIndex index.html index.php
    DocumentRoot /var/www/sdfmud

    Options Indexes FollowSymLinks MultiViews
    # pcw AllowOverride None
    AllowOverride All
    Order allow,deny
    allow from all
    # This directive allows us to have apache2’s default start page
    # in /apache2-default/, but still have / go to the right place
    # Commented out for Ubuntu
    #RedirectMatch ^/$ /apache2-default/

    ErrorLog /var/log/apache2/sdfmud/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/apache2/sdfmud/access.log combined
    ServerSignature On


  5. Mike April 9th

    Comment Arrow

    Thanks! I was having trouble using absolute paths and needed to dedicate subdomain.localhost/ to get it to play nice. Adding the virtualhost made it happen. Thanks again!


  6. ehsan January 2nd

    Comment Arrow

    i cant find this address on my mac ! :
    /Applications/Utilities/NetInfo Manager and click on “machines”


Add Yours

  • Author Avatar

    YOU


Comment Arrow



About Author

Rob Hurring

Ruby, Rails, PHP, bash... oh my!