Here is a tutorial on how to setup Apache 2.x to host a domain name with Virtual Host using Dynamic DNS. In order to do this, you will need a domain name. If you don¡¯t have one, you can register on at GoDaddy.
Note: I will be using domainname1.com and domainname2.com in the examples below. Remember to change these example domain names with your actual domain name(s).
Note 2: For this tutorial, I will be showing you how to setup your domain name registered at GoDaddy. If you did not register your domain name at GoDaddy, you can still follow this tutorial.
Before we go any further, there are some technical terms you need to know:
For more info on NameServer, check out:
http://en.wikipedia.org/wiki/Nameserver
For more info on Dynamic DNS check out:
http://en.wikipedia.org/wiki/Dynamic_dns
More info on all DNS Record types:
http://en.wikipedia.org/wiki/A_record#Types_of_DNS_records
The first step you need to do is sign up for an account at ZoneEdit. ZoneEdit is one of the most popular Dynamic DNS services out there, and they are also free. Another great feature about the site is it is loaded with tutorials and examples on how to setup and manage DNS and other settings for your domain name.
Now that you have signed up for an account at ZoneEdit, login to your account. Click on the Add Zones link at the top of the page. In the box to the right of Enter Domain Name enter your domain name. Enter it in the format domainname.com. Do not add http:// or www. in front of your domain, just enter the domain name. Click on the Add Zone button just below the text box you entered your domain name in to add your domain.
After you press the Add Zone button, you will be taken to a page with this message at the top:
IMPORTANT: Before your ¡°domainname1.com¡± site is live you must contact your registrar (the people from whom you purchased this domain name) and tell them to change its nameservers to:
This message tells you what NameServer¡¯s to use for your domain name. Just below that warning will be two NameServer addresses in this format (don¡¯t worry if your NameServer¡¯s do not match mine in this example, ZoneEdit uses many different NameServer¡¯s, all with different addresses):
Nameserver 1: ns2.zoneedit.com (69.72.158.226)
Nameserver 2: ns7.zoneedit.com (216.122.7.155)
So, the two NameServer¡¯s I need to use for my domain name are:
ns2.zoneedit.com
ns7.zoneedit.com
Note: Your NameServer¡¯s might be different than mine shown here. You should write your NameServer¡¯s down now because you are going to need them later.
Now click on the Start Editing Zone button at the bottom of the page. You now need to do what in technical terms is called creating an A Record to tie your IP address to your domain name. So, now click on the IP Addresses link. You will now be taken to the IP Addresses page. Here is where we will create two A Records. One will tie domainname1.com to your IP address and the other will tie www.domainname1.com to your IP address. This way people can access your website if the type domainname1.com and www.domainname1.com. To create the first record, leave the box below Name blank. In the box under Numeric IP, enter your IP address. If you do not know your IP address go whatismyipaddress.com. Now click on the Add New IP Address button. You will now be prompted with this confirmation:
Are you sure you would like to add the following IP Addresses?
Both ¡°domainname1.com¡± and ¡°www.domainname1.com¡± will have the IP 71.152.144.215.
Click on the first Yes button at the top and it will to add both domainname1.com and www.domainname1.com. After you click the Yes button you will be taken back to the IP Addresses page and you will now see both domainname1.com and www.domainname1.com listed there with your IP address next to them.
You are now finished with ZoneEdit. Now you will need to login to wherever you registered your domain name and change the NameServer settings for that domain. I use GoDaddy as my domain name register, and since they are the most popular domain name register on the net, I will use them in this tutorial. If you do not not use GoDaddy, you can still change the NameServer settings yourself. If you cannot figure out how to do it, contact your domain name registers tech support and ask them to set your domain name¡¯s NameServers to the NameServer¡¯s ZoneEdit gave you.
Log in to your GoDaddy account. Then click on the My Account link. Now scroll down to about the middle of the page, and click on the Manage Domains link. Now you are at your domain name administration screen. Now click on the domain name you want to use (it needs to be the same one you setup at ZoneEdit).
If your domain name is locked, you will need to unlock it before you can change the NameServer setting. Click on the Lock button in the top menu and you will be taken to the lock page. Select Unlock and press the OK button. On the next screen just click on the OK button. Now click on the NameServers button in the top menu to set the NameServer¡¯s. You may get a message saying ¡°An update is being processed for the selected domain. You will be able to change nameservers when this processing is done. Please try again later.¡± If you get that message it just means your domain name lock request is still being processed by GoDaddy. It may take a few minutes (I have waited up to 10 minutes) for the processing to finish. Once it has finished processing you will be able to change the NameServer settings.
So, if are not at the Set NameServers page, click the NameServers button in the menu at the top of the page. In the Nameserver 1 box, enter the first NameServer address from ZoneEdit. In the box next to Nameserver 2, enter the second NameServer from ZoneEdit. Now click on the OK button to submit your new NameServers to GoDaddy. Now click the OK button on the next screen.
That is it. You have now successfully changed your NameServer settings for your domain name now. If you have any other domains you want to use, now do the same process for those domains. Now you need to lock your domain name. Use the same procedure I wrote about above.
Now you will need to create a location on your server where you are going to store all your virtual hosted websites. To make things easier, I suggest you put all your virtual host websites in one location, versus all over your computer. This will make using, and editing your website files much easier, since you now they are in one place versus all over your computer. I put all mine in a folder I call users.
For Windows, that would be:
C:\users
For Linux that would be:
/home/users
Now create a folder inside your users folder and name it your domain name. So, in this example, I will name it dominname1.com.
For Windows, that would be:
C:\users\dominname1.com
For Linux that would be:
/home/users/dominname1.com
Now you need to create two new folders in the domainname1.com folder, one name logs and one named public_html. The logs folder is where your apache error and access logs for that domain name be stored. The public_html folder will store all your domain name¡¯s website files (html, php, css, images, etc).
For Windows, that would be:
C:\users\dominname1.com\logs
C:\users\dominname1.com\public_html
For Linux that would be:
/home/users/dominname1.com\logs
/home/users/dominname1.com\public_html
Now we will need to edit your Apache¡¯s virtual host config file. Open up the file httpd-vhosts.conf, located in apache/conf/extra/httpd-vhosts.conf
Find this line:
NameVirtualHost *:80
If that line has a pound sign ( # ) in front of it, remove it to enable VirtualHost.
To setup virtual host for your domain, add this line below the NameVirualHost line. For Windows, on the next line add this:
<VirtualHost *:80>
ServerAdmin admin@domainname1.com
DocumentRoot C:/users/dominname1.com/public_html
ServerName www.domainname1.com
ServerAlias domainname1.com
ErrorLog C:/users/dominname1.com/logs/error.log
CustomLog C:/users/dominname1.com/logs/access.log common
</VirtualHost>
For Linux, on the next line add:
<VirtualHost *:80>
ServerAdmin admin@domainname1.com
DocumentRoot /home/users/dominname1.com\public_html
ServerName www.domainname1.com
ServerAlias domainname1.com
ErrorLog /home/users/dominname1.com/logs/error.log
CustomLog /home/users/dominname1.com/logs/access.log common
</VirtualHost>
If you have any more domain names you want to add, add them just below the previous example above. Here is an example:
Multiple domain names for Windows, on the next line add this:
<VirtualHost *:80>
ServerAdmin admin@domainname1.com
DocumentRoot C:/users/dominname1.com/public_html
ServerName www.domainname1.com
ServerAlias domainname1.com
ErrorLog C:/users/dominname1.com/logs/error.log
CustomLog C:/users/dominname1.com/logs/access.log common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin admin@domainname2.com
DocumentRoot C:/users/dominname2.com/public_html
ServerName www.domainname2.com
ServerAlias domainname2.com
ErrorLog C:/users/dominname2.com/logs/error.log
CustomLog C:/users/dominname2.com/logs/access.log common
</VirtualHost>
Multiple domain names for Linux, on the next line add this:
<VirtualHost *:80>
ServerAdmin admin@domainname1.com
DocumentRoot /home/users/dominname1.com/public_html
ServerName www.domainname1.com
ServerAlias domainname1.com
ErrorLog /home/users/dominname1.com/logs/error.log
CustomLog /home/users/dominname1.com/logs/access.log common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin admin@domainname2.com
DocumentRoot /home/users/dominname2.com/public_html
ServerName www.domainname2.com
ServerAlias domainname2.com
ErrorLog /home/users/dominname2.com/logs/error.log
CustomLog /home/users/dominname2.com/logs/access.log common
</VirtualHost>
Now you need to save the file httpd-vhosts.conf and restart Apache for the new settings to take effect. Note however, that it will take between 12-48 hours for your NameServer changes for your domain name to take effect. This means it will not work until it has fully propagated through the DNS system.
More info on Domain Name Propagation:
http://en.wikipedia.org/wiki/Domain_name_system#Caching_and_time_to_live
I have noticed with GoDaddy, domain name propagation only takes a few minutes. To see if your domain name has fully propagated, use dnstools.com. Enter your domain name in the box. If your see your ZoneEdit NameServer¡¯s listed in the whois report, your domain name has fully propagated. If not, you will need to wait a bit longer and try again.
discuss this topic to forum
