![]() |
ubuntu.com - launchpad.net - ubuntu help
|
|
|||||||
|
Tutorials & Tips The place to find Ubuntu related Tips & Tricks. |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Just Give Me the Beans!
![]() Join Date: Apr 2006
My beans are hidden!
|
HOWTO: localhost subdomains
It's a very simple and very useful hack. This was done on Apache2 under Gutsy.
1. Add your subdomain(s) to your hosts file:
localhost extra.localhost another.localhost 2. Apply subdomains to folders: Open up a terminal or the Run Application diaogue (Alt+f2), then run the command: gksudo gedit /etc/apache2/httpd.conf For each subdomain you need to add a VirtualHost clause, you also need to add one for the base localhost. The clause for each uses the template: <VirtualHost *> ServerName {Domain (e.g. localhost)} DocumentRoot {Absolute path to folder for this domain (e.g. /var/www/)} </VirtualHost> Your file should end up looking something like this: Code:
<VirtualHost *> ServerName localhost DocumentRoot /var/www/ </VirtualHost> <VirtualHost *> ServerName extra.localhost DocumentRoot /var/www/extra/ </VirtualHost> <VirtualHost *> ServerName another.localhost DocumentRoot /var/www/anothersite/ </VirtualHost> 3. Restart apache: Open up the terminal and run: sudo /etc/init.d/apache2 restart You should now be able to view your subdomains through whatever browser you use (but obviously only from your computer). All done! Making use of it: I write and test websites on my localhost before uploading them to my public sites and I don't want to go through my code renaming localhost to example.com every time I change something. Nor do I want to use relative URLs as they can get messy once you get folders involved. By putting each site I make on it's own local subdomain I can start all my URLs with a slash which means the URL starts at the base of the subdomain. That's why I use it anyway. -- Notes: - I couldn't find a way to apply wildcards to the hosts file (e.g. *.localhost), does anyone know? - There are ways to direct all subdomains to folders automatically (mod_rewrite is good for that) but that's less needed for this purpose and would require wildcards in the hosts file |
|
|
|
|
|
#2 |
|
5 Cups of Ubuntu
![]() |
Re: HOWTO: localhost subdomains
This will come in handy at work. Very useful tip, Stex.
I'm pretty sure I've read that hosts files are unable to accept wild card entries. I know that wasn't the answer you were looking for, but at least now it won't keep you up at night. Maybe theres another way. Hm. If anything pops into my brain I'll give you a holler.
__________________
- Meowsus (The Good Reverend Doktor Curdo) - http://www.fauxfetus.net - http://www.ughgod.org - http://myspace.com/ughgod |
|
|
|
|
|
#3 |
|
Gee! These Aren't Roasted!
![]() |
Re: HOWTO: localhost subdomains
For Kubuntu newbies like myself, there are slight alterations to steps 1 and 2.
Everything else remains the same, really. To the OP, thanks for this--I was unsure about the right format for step 2, and forgot the command to restart the apache server in step three. XD If you want to include the above in your HOWTO for us Kubuntu users, go right ahead. Last edited by Sarteck; November 25th, 2007 at 12:44 PM.. |
|
|
|
|
|
#4 |
|
5 Cups of Ubuntu
![]() Join Date: Jul 2007
Beans: 34
Xubuntu 8.04 Hardy Heron
|
Re: HOWTO: localhost subdomains
Of course - I found this post AFTER I made my own workaround. The subdomain trick is nice. However, I made my "multiple-virtual-local-servers"-thingy.
First, I added a couple of new hosts in /etc/hosts Code:
127.0.0.1 localhost 127.0.0.2 alpha 127.0.0.3 beta 127.0.0.4 gamma Code:
<?php echo getcwd(); ?> Code:
sudo touch greek sudo nano greek Code:
# alpha <VirtualHost 127.0.0.2> DocumentRoot /var/www/alpha/ </VirtualHost> # beta <VirtualHost 127.0.0.3> DocumentRoot /var/www/beta/ </VirtualHost> # gamma <VirtualHost 127.0.0.4> DocumentRoot /var/www/gamma/ </VirtualHost> Code:
sudo a2ensite greek sudo /etc/init.d/apache2 reload Code:
firefox alpha Last edited by firmit; March 19th, 2008 at 10:51 AM.. |
|
|
|
|
|
#5 |
|
First Cup of Ubuntu
![]() Join Date: Jun 2008
Location: Portugal
Beans: 4
Ubuntu 8.04 Hardy Heron
|
Re: HOWTO: localhost subdomains
firmit's solution has green light in 8.04
Fantastic! Thanks firmit! |
|
|
|
|
|
#6 |
|
Way Too Much Ubuntu
![]() Join Date: Feb 2007
Location: Kamloops, BC
Beans: 310
Ubuntu 9.04 Jaunty Jackalope
|
Re: HOWTO: localhost subdomains
Great tutorial! This one's going in as a keeper
|
|
|
|
|
|
#7 | |
|
First Cup of Ubuntu
![]() Join Date: Jul 2008
Beans: 1
|
Re: HOWTO: localhost subdomains
Quote:
Thank you for the tutorial. I'm sorry that I new to this features I had tried to set it and restart my apache server it prompt a message box request username and password ? May I know what is my username and password to login into the sub domain ? |
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|