Thoughts inspiring. Inspiring thoughts
Creating subdomain(s) in any web development environment is essential. For example, I have 2 projects going on at the same time and developement is concurrent. And subdomains were not created. So we have this scenario:
As you can see, I am assuming a Apache/PHP/MySql developemnt stack. 3 localhost urls that will be frequently accessed. Imagine what will happen when you want to access beta project? You “control+t” a new browser tab, and type in “localhost” only to have the url bar showing its history of the above 3 urls. Then you press the down arrow key to access the required url.
Waste of keystroke I will say. Now we create subdomains and we have:
So now when we want to access beta project? Type in “beta” and simply selected the required “remembered” url. Save some keystrokes and it will save up a a sizable amount of effort over time.
So how to create subdomain in Ubuntu?
Simple, I will cover the basic steps here. (Windows users, sorry, not here my friends).
Edit /etc/host and add the following line
127.0.0.1 alphaproject.localhost
Create a new configuration file in /etc/apache2/sites-available/alphaproject using
gksudo gedit /etc/apache2/sites-available/alphaproject
In this configuration file, have the following:
<VirtualHost *> DocumentRoot /home/username/alphaproject/ ServerName alphaproject.localhost<Directory /home/username/alphaproject/> Options Indexes FollowSymLinks MultiViews +Includes AllowOverride None Order allow,deny allow from all </Directory> </VirtualHost>
Save the file, and run the following:
sudo a2ensite alphaproject
Finally restart the Apache Server. Which I assume you should be using Apache2.
sudo /etc/init.d/apache2 restart
And by going to http://alphaproject.localhost/ you should be able to access you newly created subdomain.
On a ending note, phpmyadmin does come installed as a package but default to http://localhost/pma which I do strongly encourage users to change it to http://pma.localhost/
Think of the key strokes you be saving. And yes, do name your subdomain smartly, try picking each subdomain to have a different starting character.
ThinkingNectar talks about the interest of Chin Yong, a PHP/Python/Web developer residing in Singapore. Life, society, and codes should entails most of what goes between the ears of this coffee drinker.
What makes you think?
Tim Graham
March 29th, 2008 at 5:30 pm
An important note if you want to use .htaccess files to enable features like mod_rewrite: AllowOverride should be set to “All” instead of “None”
Getting Ubuntu to work: The Heron Had Landed | ThinkingNectar
May 6th, 2008 at 6:08 pm
[...] took another 30 minutes. Very much painless, less that the fact that I need to recheck every single Apache subdomain that I had created to make sure that there are still working. It was pretty scary when the updates [...]
Nicholas Hunter
May 16th, 2009 at 7:57 am
sudo a2ensite myconfig
should read
sudo a2ensite alphaproject
should it not?
Nicholas Hunter
May 16th, 2009 at 8:37 am
Also
<VirtualHost *>
needs to be
<VirtualHost *>
on my configuration (Apache/2.2.9 (Ubuntu) PHP/5.2.6-2ubuntu4.2 with Suhosin-Patch).
Nicholas Hunter
May 16th, 2009 at 8:37 am
Also
<VirtualHost *>
needs to be
<VirtualHost *:80>
on my configuration (Apache/2.2.9 (Ubuntu) PHP/5.2.6-2ubuntu4.2 with Suhosin-Patch).
Chin Yong
May 17th, 2009 at 9:36 am
@Nicholas
Yes, sudo a2ensite alphaproject is indeed correct. I updated the post to reflect that.
Thanks.
Sabot
December 7th, 2009 at 7:20 am
On windows this is nearly the same, host file is in “windir/system32/drivers/etc/host” and paths must have forward slash like “D:/webroot/site1″, put them in quotes if you have spaces in your path. Lastly, I couldnt get it working until I’ve put NameVirtualHost 127.0.0.1 at the top of vhosts conf file and then changed to . Dont forget to put your regular webroot at the top of these directives (also like virtual host) otherwise you wont be able to access it. Good luck.
Sabot
December 7th, 2009 at 7:22 am
Damn, my msg got mangled. I meant replace VirtualHost * with VirtualHost 127.0.0.1
Richard
March 13th, 2010 at 2:56 pm
Sweet thanks for this – I kind of hacked together the apache part of it but was missing the entry in the hosts file and the little a2ensite.
Gonzalo
April 24th, 2010 at 4:04 pm
Thank you very much. It worked!
Arastu
September 7th, 2010 at 10:20 pm
Tank you very very very … very much.
its very helpful for me.
Persian:
خیلی خیلی خوب بود، بسیار ممنون کارم راه افتاد.
jogesh
October 18th, 2010 at 3:02 am
thanks a lot to sharing your knowledge ,,
Creating Subdomain in Localhost on Ubuntu « Khmer Developer
March 10th, 2011 at 10:50 pm
[...] reference: http://thinkingnectar.com/2008/getting-ubuntu-to-work-creating-subdomain-in-localhost/ [...]
Christopher J
April 8th, 2011 at 5:57 pm
I liked the way you showed windows users the path: “Windows users, sorry, not here my friends” – I must remember to do something similar, should I write a ubuntu tutorial someday. Ha, ha.
Stephen Greenslade
September 20th, 2011 at 12:40 pm
On Ubuntu 11.04 I had to:
1) Remove the extra / on the end of DocumentRoot
2) Make sure that my default server had a name.
vi /etc/apache2/sites-available/default
ServerName localhost
Otherwise all working great. Thanks!
Localhost subdomain set up on ubuntu not working | web technical support
November 30th, 2011 at 11:19 pm
[...] I followed the steps in http://thinkingnectar.com/2008/getting-ubuntu-to-work-creating-subdomain-in-localhost/ [...]
HPluska
January 28th, 2012 at 8:02 pm
thanks a bunch!… this helped a lot
is needed for ubuntu 11.04
Also,
etc/hosts
not
etc/host
needed added line: 127.0.0.1 alphaproject.localhost
HPluska
January 28th, 2012 at 8:04 pm
*:80 is needed for ubuntu 11.04
Thevoyeurplanet.com
February 3rd, 2013 at 5:35 pm
Outstanding post however , I was wondering if you could write a
litte more on this subject? I’d be very thankful if you could elaborate a little bit further. Cheers!
www.prnewswire.com
March 27th, 2013 at 1:41 am
I have had my Environmentally friendly smoke for five months today and my own battery is still going powerful!
Thanks
Online Fax Guy
April 10th, 2013 at 6:50 am
Great stuff — this definitely helped me.
A few refinements tho:
You can use “apache2ctl configtest” to check your config files for any gross errors before you restart. Should be in your default path so no custom path should be required.
You should mention the possibility of using a “graceful” restart instead of a full restart to avoid blasting any current website users and causing possible half-page loads. For me, the command was “apache2ctl graceful” and the restart happened in seconds with no disruptions.
Lastly, if you get a “Could not reliably determine the server’s fully qualified domain name” but the site is in DNS and publicly visible, you can ignore the error.
bed bites
June 9th, 2013 at 9:01 am
Excellent post. I was checking continuously this blog and
I care for such info
I am impressed! Extremely useful info specially the last part
a lot. I was looking for this particular information for a very long time.
Thank you and good luck.
dealmoon
June 13th, 2013 at 12:37 pm
continuously i used to read smaller articles that as well clear
their motive, and that is also happening with this post which I am reading now.
laser printer ink
June 17th, 2013 at 5:24 pm
Have you ever considered about adding a little bit more than just your articles?
I mean, what you say is valuable and everything.
However imagine if you added some great photos or videos to
give your posts more, “pop”! Your content is excellent but with
pics and videos, this blog could certainly be one of the very best
in its field. Excellent blog!