Part 3 (final) – Setting up a Domain Name to Point to WordPress Host in Virtual Machine Instance
The final section is to setup a domain name and connect it to your virtual machine instance, so your website will be accessed via a domain name rather than a IP address. This is the only part you need to spend some money and it could be less than a $1 e.g. int the time I am writing this tutorial NameCheap offers some domain registrations for only $0.88 and of course for the first year and GoDaddy offers a .com registration for only 0.99 CAD (one time per one person). And you could find a domain suffix (a.k.a top-level domains) of your country of residence (2 letter domain names) for a very low price. I am sure you could find one if you google some thing like “domain name registration lowest price“. The other option will be to register a one with regular price on Google Domins. For the rest of article, I am assuming you have registered “mydomain.com” in a non-google registrant.
Click on the “Create Zone”. This will create you a managed zone.
This zone will provide set of services on your virtual machine instance to accept and response DNS queries. DNS zones are also responsible to stores all the DNS records of the same DNS name suffix in their database. It means that if you setup a DNS zone to point to “mydomain.com” any other sub domains like “sub.mydomain.com” should have a record in that DNS zone as well. Fill in the zone name with a proper and valid name like “mydomain-com” (spaces are not acceptable) and in the DNS name your registered “mydomain.com”. Then click Create.
With the creation of DNS zone you might notice existing of two records of type NS & SOA. The NS records are important ones, these will used later to configure registrant domain management panel. Some domain registrant also provide free DNS zones, you could do all the stuff their as well, but it is a good idea to keep DNS zone next to the place where our host is located.
“A records” in DNS zones are used to resolve DNS queries to IP addresses. So, we need to create an “A record” to point our domain to the virtual machine instance IP address. click on “Add record set”. Left the DNS name value to be “.mydomain.com” and for resource record type select “A” (If you are using IP V6 select AAAA) and enter your IP address in the related field. then click Create.
Another thing that is optional but also required is to add a “www” prefix to your domain name. Some people are used to enter “www” whenever they want to reach a site (for some historical reasons 😐 ). So, almost all the sites worldwide provide this option for their audiences and as a result they could access the site URL both with typing or not typing “www” prefix. In technical terms it is a sub-domain for “mydomain.com” and since it is supposed to point to the same location of “mydomain.com”, it is considered as an alias to our domain name. In DNS terminology it is call canonical name or briefly CNAME. long story short, we need to add another record of type CNAME to the DNS zone. This will help users reach our site with or without typing “www”. After clicking “Add record set” enter “www.mydomain.com” for DNS name and in resource record type select “CNAME”. For the canonical name field enter “mydomain.com.”, and the “www.mydomain.com” will become an alias for “mydomain.com”
In the DNS zone details page you might have noticed an existing record of type NS, the Data values of this record (ns-cloud-a1.googledomains.com and …) is required to complete connecting domain name to the IP address. (Attention the trailing dot in NS records is not included) We need to enter all these four records in the domain management portal provided with in the registrant client area.
Here you could see the WHC domain management section I enter these four NS records. While using copy and paste technique, make sure you are not selecting the “.” at the end of NS values that will result in error message “Create the host on the Registry system before you assign it to a domain”. If you could n’t find this area in your registrant portal ask them for help in setting up nameservers or email the nameservers to them and they will update the NS records for you free of charge.
Now we have successfully created our DNS zone with all the records required. All these changes will take up to 48 hours to take effect (for worldwide propagation purposes) and then your website will be available vai a domain rather than a IP address. It is better to update the IP address in the PuTTY, FileZilla and Netbeans to your new domain name if you skipped this section of the tutorial to last.
An alternative free option for domain name registration, if you already have a domain is to use a sub domain, simply you could create a sub domain for your own domain and point the IP address to that sub domain. If you need help on this let me know.
Now almost everything is done except one more and important thing. Remember that we first created our WordPress in VM with IP address. So, the WordPress database is configured to use the IP Address of VM and that ‘s why while you navigate from homepage to every link in the site the domain name changes to IP Address. This means that if your VM gets restarted every thing will be messed up in your site and you should update these values to your domain name. Login to WordPress and in the menu go to the “Settings | General” update the values for WordPress Address and Site Address from IP address to domain name.
If it is too late and you already restarted your VM and you lost your access to WordPress administration page to update those values, Don’t worry you could update them through PHPMyAdmin database. Login to PHPMyAdmin from http://IPAddress/phpmyadmin and then from Databases choose wpdatabase and then wp_options the siteurl and home records state for the same fields in setting page. You could just fill the siteurl and empty the home record in this case it will be interpreted to the same address by Apache.
For the final step it is better to employ another security patch to your WordPress site. The default location of phpmyadmin (http://yourdomain/phpmyadmin/) is the first guess for any intruder and the fact that the defualt privileged username is root will add to the crisis, so this should be chanbed to another location like http://yourdomain/hereismydb. To apply these changes first the alias field value in phpmyadmin config file should be edited.
sudo nano /etc/phpmyadmin/apache.conf
Comment out the alias line and add a new one:
# Alias /phpmyadmin /usr/share/phpmyadmin
Alias /hereismydb /usr/share/phpmyadmin
The restart the apache2 service:
sudo service apache2 restart
This tutorial ends here, I hope you could setup your site using this tutorial. Any comments or suggestions are welcome for improving the article.