
If you are on a shared hosting, you don’t have to worry about it that much, as you get a nice control panel to manage domains easily. Well, if you now move to a VPS or dedicated server, you can still have it easily with help of cpanel or such service. But, here we are talking about to take this control on ourselves. We are here to set up a full LAMP stack development environment on Ubuntu cloud VPS server, without help of other third-party, all by ourselves! Yes! Its fun and you should try it out. This tutorial is being released as a part of AWS tutorials series for developers. Today, we will learn Apache domain name management. If you are on AWS cloud platform, you must should have set up domain with AWS route 53 service, as otherwise you won’t get it completely working. Now, lets start our quest 🙂
Look For Enabled Sites And Available Sites:
Normally, apache is being installed on “/etc/apache2” path. Lets go to this path first:
$cd /etc/apache2
Here’s my apache directory listing looks like:
Here, for today, most important directories are ‘sites-enabled’ and ‘sites-available’. ‘sites-enabled’ directory contains the configured all virtual host files for domains, including live sites. The ‘sites-available’ directory contains only the configurations which are currently live. If we configure a new site and keep that file on this directory, it will be automatically available in ‘sites-enabled’ directory too. Also, another thing to remember, these configurations file doesn’t have any extensions. We will edit/create these files using ‘vim'(in short ‘vi’) editor. A default configuration is already provided by apache installation named ‘default’/’000-default’. Lets just copy that for our site:
$sudo cp default mydomain_name.tld $sudo vi mydomain_name.tld
The name of the site is totally optional and up to you to what to name, usually its better to name it after the domain name to recognize it easily.
Setting Up The Root Apache Domain Name:
If you open the file we just copied, you will see something like as below. Note the “{*}” parts where we need to change:
<VirtualHost *:80> ServerAdmin {myemail@mydomain.tld} ServerName {www.mydomain.tld} DocumentRoot /home/{path_to_mydomain_root_directory} <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /home/{path_to_mydomain_root_directory}/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined Alias /doc/ "/usr/share/doc/" <Directory "/usr/share/doc/"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 </Directory> </VirtualHost>
First one “myemail@mydomain.tld”, is the email address you want to associate. Second one, “www.mydomain.tld”, it’s the most important, to indicate the original server/domain name. Then, “path_to_mydomain_root_directory” is the path where site’s root resides. For easy understanding, on amazon ec2 ubuntu server, we will use “/home/ubuntu/{domain_name}” structure.Besides ‘DocumentRoot’, we will have to mention this path on first ‘Directory’ tag as well.
Now save the file. Restart the apache server as below:
$ sudo service apache2 restart
And we should be fine. You should be able to start accessing your domain on the configured directory on server!
Final Words:
So, this is it. Hope this small Apache domain name management tutorial will be of some help for you. Let me know if you are having any issue while trying the above exercise. Also keep in touch to get the next tutorial on the series 🙂
Leave a Reply