Mar
4
Create a Subdomain Virtual Host on Ubuntu
March 4, 2008 |
In this article, I will teach you how to create a virtual host named www.wordpress.example.com on your local machine, which will point to a local folder named wordpress under a specified location like /home/host/ on your machine. The wordpress folder will be your working folder for all the files run on the virtual host, and you’ll load the sample pages through http://www.wordpress.example.com. I assume that you already have LAMP installed and configured on your machine, if not, then read this article first: Install and Configure LAMP on Ubuntu
1. Add your subomain to your hosts file
Open up your network settings (System > Administration > Network)
Click on the Hosts tab, select the localhost alias and click properties
Add the subdomain(s) you want alongside localhost, separate with new lines, in this exercise, we will add: www.wordpress.example.com
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:
<VirtualHost *>
ServerName www.wordpress.example.com
DocumentRoot /home/host/wordpress/
</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!
4. Making use of it:
create a file named hullo_word.php, inside the file write something, now
log on to www.wordpress.example.com/hullo_word.php, you should get a message says: hullo world.
Now you are done!
Similar Posts
- Install and Configure phpMyAdmin on Ubuntu LAMP
- Install and Configure LAMP on Ubuntu
- Linux Ubuntu Install Setup PHP cURL
- Create Read View Edit Word Document on Ubuntu
- Install Photoshop on Ubuntu
- Connect Ubuntu to Printer
- Virus on Ubuntu Wine
- Install Flash CS on Ubuntu
- Ubuntu Hardy Broadcom Wireless Setup
- Install and Play Diablo II on Ubuntu
- Play iTunes m4a Files on Linux Ubuntu
- Install and Play Enemy Territory Quake Wars on Ubuntu
- Burn Audio CD on Ubuntu
- Install and Play Quake 4 on Ubuntu
- Install and Play Red Alert 2 on Ubuntu
- Install and Run RealPlayer on Ubuntu
- Ubuntu Configure Disable Touchpad
- Install and Play Quake III Arena on Ubuntu
- Install Run and Play Doom 3 on Ubuntu
- Ubuntu Best CHM Viewer
- Install and Play Unreal Tournament on Ubuntu
- Ubuntu Install Chinese Input
- Create Compile and Run .NET on Ubuntu
- Install and Configure Wine on Ubuntu
- Open VCD Using VLC on Ubuntu
- Burn Iso on Ubuntu
- Best BitTorrent Client On Ubuntu
- Install Google Earth on Ubuntu
- Use New iPod Nano with Ubuntu
- Manipulate Files Directories using Unix Shell
- Ubuntu Seperate Audio From Video
- Make Acer Extensa headphone speakers Work on Ubuntu
- Create Read View Edit Excel File on Ubuntu
- Transfer music mp3 to and from iPod Ubuntu
- Manage Ubuntu Repository
- Using Gmail With Evolution on Ubuntu
- Play iPod music on Ubuntu
- Ubuntu Change Password
- Install and Use Skype on Ubuntu
- Amarok audio output unavailable the device is busy Solution
- Ubuntu’s Equivalent to Task Manager
- Install and Use Audacity on Ubuntu
- SCIM Filesystem Name Rename Problem
- Use IRC to Chat on Ubuntu
- Install and Chat use QQ on Ubuntu
- Use MySpaceIM to Chat on Ubuntu
- Install and Play Quake 2 on Ubuntu
- Install and Use Google Talk to Chat on Ubuntu
- Install and Play Counter Strike on Ubuntu
- Install BitTorrent GUI Azureus on Ubuntu
Comments
9 Comments so far



































Hi, this is a really nice post, I have been reading a book called ‘Professional Search Engine Optimization with PHP: A Developer’s Guide to SEO’, the book only teaches Mac and Windows users. Linux users like me are non-existing to them. Lucky that I found your post. This is great man.
[...] Related Articles: Install and Configure phpMyAdmin on Ubuntu LAMP Create a Subdomain Virtual Host on Ubuntu [...]
[...] Related Article: Create a Subdomain Virtual Host on Ubuntu [...]
With options such as creating a subdomain virtual host, its quite obvious why Ubuntu is one of the most popular threads of Linux.
Thanks a lot for a fine read. Keep up the hard work :)
[...] or you previously installed LAMP, then you can read on, if not, please read this article first before [...]
Hi Highub, I’m hoping you can help me out and help me from going insane :-)
I’m trying to do exactly what you have outlined, but I’m having a terrible time and I think its something to do w/ my Apache configuration.
Here’s the nitty gritty:
If I create an index.html file, then http://wp.domain.com goes to my wp directory. But, if I remove that index.html or insert a DirectoryIndex directive so it hits the default index.php file, the I’m redirected to http://www.domain.com. very weird. Below are the relevent segments of my config:
ServerName wp.acmespringinc.com
ServerAlias http://www.wp.acmespringinc.com wp.acmespringinc.com
DocumentRoot /var/www/wp/
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml
Options Indexes FollowSymLinks MultiViews +Includes
AllowOverride None
Order allow,deny
allow from all
/etc/hosts:
127.0.0.1 localhost acmespringinc.com wp.acmespringinc.com
Hi, josh
Is your wp a fresh install or you moved it from main domain to subdomain? is your index.php the default wordpress index.php file?
hi i have doubt in dynamic virtual subdomain creation. so i need help with full procedure ex- code for httpd.conf file ,hosts file, and ht access file .im using like test.com and i want to give individual sub domain each registered users. pls help me..
Hi rajesh,
i am afraid that test.com can’t be used for local testing.
The only domains I know that can be used for local testing are something.example.com or http://localhost