How to setup multiple domains on Amazon AMI EC2 instance.

Hi,
I have setup Amazon-Linux instance on Amazon micro EC2 AMI for php/mysql/apache.

I have created following folder in Apache document root folder.

/var/www/html/domain1/
/var/www/html/domain2/
/var/www/html/domain3/

Now I want to point my three domains : domain1.com, domain2.com and domain3.com to those following folders.

How can I do that? I have some idea that I have to create some DNS server (may be using Amazon 53 router) and put those dns as name server to my domain-register company, correct?

But what else I have to do on Amazon side? I think I have to update httpd.conf file for virtual host file?

Also before taking the dns, can I test that my subdomains are working using ip address for example if my elastic public ip address given by Amazon is 10.10.11.20  then can i check my sub domains using this ip address?
Also what is difference between subdomain and add-on domain?

Do I need a CPnel if I want to load 5 - 6 domains of my own?

Thanks.
student237Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

arnoldCommented:
If you are comfortable with editing the /etc/HTTPd/conf.d or /etc/apache2/cond.d by creating a file that contains the virtualhost definition with servername and document root you do not need cpanel, cpanel simplifies management of a domain/user emails if any etc to a central UI ........

No, what you could do to your virtualhost entry add a line such as
serveralias test.domain1.com
Then on domain1.com DNS zone add a host test1.domain1.com pointing to the public IP of your server. Then use a browser to access test1.domain.com.........
0
student237Author Commented:
Thanks for your reply. I understand cpanel now and I think, I don't need it.
Now to make subdomain or add-on domain are the following steps are correct:
(Note: my main objective is that if i input domain1.com then it should map to domain1.com.10.10.11.20\index.html )

1.
mkdir /var/www/html/domain1_folder
mkdir /var/www/html/domain2_folder
mkdir /var/www/html/domain3_folder

2. Add following entry into /etc/httpd/conf/httpd.conf

<VirtualHost *:80>
ServerAdmin webmaster@domain1.com
DocumentRoot "/var/www/html/domain1_folder"
ServerName domain1.com
ErrorLog "logs/domain1.com-error_log"
CustomLog "logs/domain1.com-access_log" common
</VirtualHost>

<VirtualHost *:80>
ServerAdmin webmaster@domain2.com
DocumentRoot "/var/www/html/domain2_folder"
ServerName domain2.com
ErrorLog "logs/domain2.com-error_log"
CustomLog "logs/domain2.com-access_log" common
</VirtualHost>

<VirtualHost *:80>
ServerAdmin webmaster@domain3.com
DocumentRoot "/var/www/html/domain3_folder"
ServerName domain3.com
ErrorLog "logs/domain3.com-error_log"
CustomLog "logs/domain3.com-access_log" common
</VirtualHost>

3. Now as http://10.10.11.20/ this work or accebile
So can I access
http://domain1.10.10.11.20/
http://domain2.10.10.11.20/
http://domain3.10.10.11.20/

is there any missing thing except DNS name server which I am thinking of using Amazon 53 router.
0
arnoldCommented:
One thing, you should not be editing/adding entries to HTTPd.conf

Look at the bottom of HTTPd.conf, there should be an include directive pointing to conf.d/*.conf
Add the virtualhost in individual files domain1.conf then copy the one to the others and then edit the contents to match.

<VirtualHost *:80>
ServerAdmin webmaster@domain1.com
DocumentRoot "/var/www/html/domain1_folder"
ServerName domain1.com
ServerAlias www.domain1.com
serverAlias test.domain1.com
ErrorLog "logs/domain1.com-error_log"
CustomLog "logs/domain1.com-access_log" common
</VirtualHost>

Open in new window

You may want to document reference dealing with the search index.html, index.htm, I decided.php, etc.

10.x.x.x is not a routeable ip,

If you do not want to alter domain1.com DNS revord, you can make the adjustment in your workstation's hosts file
X.x.x.x www.domain1.com
Once you save the entry www.domain1.com on this workstation will be directed to x.x.x.x.
Ps, placing the domain1-folder in the HTML folder, it means it can be accessed without the virtualhost http://x.x.x.x/domain1-folder
Note if you do not go through the virtualhost path and your site has explicit oaths for www.domain1.com some links will bounce out to the current host/site.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

student237Author Commented:
Ohh now sound complicated.. :)
Does CPanel do all things automatically? I think I need now cpanel, I am not much expert of Linux.  I am a developer and want to develop and manage Magento or wordpress/blog sites. I want to keep things as simple as possible.

Is configuration of CPanel is simple or complicated?

Regards,
0
student237Author Commented:
Can you refer me step by step type document to setup CPanel or multiple domains as subdomains/add-on domain.
0
arnoldCommented:
While something sounds complicated, the setup is a one time thing.

Setup is a one/two step deal and is not something that is ongoing.
Yes cpanel makes it simpler, I.e. It has a GUI view of your system's categories of configuration.

There is a FAQ from the vendor of cpanel.
Usually if it is installed, it would be accessible as http://www.yourdomain.com/admin or cpanel.


Different providers have different ways to deploy/provide cpanel to their customers.  I believe cpanel is a commercial product such that my advice would be to first check with Amazon on getting cpanel on your box if not available already.
0
arnoldCommented:
Cpanel info generally http://www.cpanel.com.
0
arnoldCommented:
Just copy the code I posted and place it in /etc/HTTPd/conf.d as domain1_com.conf

Oh, not sure which part of the long comment makes it complicated? The configuration of Apache on the server,
Or the two ways of accessing it prior to making the new location live.
0
student237Author Commented:
If it is one time setup then it is ok, I will try. Lets start from beginning.
I have added two config files in /etc/httpd/conf/

sudo nano domain1.conf

<VirtualHost *:80>
ServerAdmin webmaster@domain1.com
DocumentRoot "/var/www/html/domain1_folder"
ServerName domain1.com
ServerAlias www.domain1.com
serverAlias test.domain1.com
ErrorLog "logs/domain1.com-error_log"
CustomLog "logs/domain1.com-access_log" common
</VirtualHost>

sudo nano domain2.conf

<VirtualHost *:80>
ServerAdmin webmaster@domain2.com
DocumentRoot "/var/www/html/domain2_folder"
ServerName domain2.com
ServerAlias www.domain2.com
serverAlias test.domain2.com
ErrorLog "logs/domain2.com-error_log"
CustomLog "logs/domain2.com-access_log" common
</VirtualHost>


Question 1. Should I take Amazon 53 to point to my main website to server ip 10.10.11.20?
Question 2. httpd.conf has line
'IncludeOptional conf.d/*.conf'
at the bottom. Do I need to add any other line or ref. or it will automatically load all *.conf files?
Question 3: How to make index.php or index.html by default to come?
Question 4: You said that I can adjust my workstation's hosts file ? do you mean amazon ec2 server or my laptop ?
0
student237Author Commented:
I tried to http://domain1.com.10.10.11.20/index.html it is not comming:

Following error message:

The server at domain1.com.10.10.11.20 can't be found, because the DNS lookup failed. DNS is the network service that translates a website's name to its Internet address. This error is most often caused by having no connection to the Internet or a misconfigured network. It can also be caused by an unresponsive DNS server or a firewall preventing Google Chrome from accessing the network.
0
arnoldCommented:
For specifying which files the site will try to load in order of appearance following the
DirectoryIndex within the VirtualHost entry can be add below the DirectoryRoot

http://httpd.apache.org/docs/current/mod/mod_dir.html#directoryindex

Right, the includeoptional will when the apache restarts certain parameters it can load during the reload directive. So no further things in httpd.conf need to be done. Often people adjust some settings dealing with whether they want to allow .htpaccess to override certain settings, or define others....... I'll mention it to make you aware that it exists in the event you want to do something and the link says create a .htaccess and add the following lines. And after you do that, the behavior did not adjust to what you expected. httpd.conf has the initial config that by default  restricts what options .htaccess has and if I am not mistaken it limits the .htaccess to controlling access.

I think I answered three earlier, with DirectoryIndex firstfile.html second.php thirdfile.htm default.htm lastfile.php

I am unsure what you mean by Amazon 53, so not sure how to answer this question.


AS to the change in hosts file, it should be done on your laptop from which you will be testing/accessing the site and wish to have www.domain1.com actually access and open the site that is on your Amazon EC2 without impacting all your users/live site.

The URL you provided as the example is not valid. http://domain1.com.10.10.11.20/index.html
After the hosts modification, you will be accessing the site http://www.domain1.com on your laptop. The hosts file will have a public IP (10.x.x.x) is not it.

You may have to navigate to c:\windows\system32\drivers\etc\
in here, on the hosts file you would need to right click and select run as administrator or you will not be permitted to save/alter the file.

you will get the Public IP Amazon provided you for your server that will not be of the range
10.x.x.x
nor
172.16-31.x.x
nor
192.168.x.x
i.e. they gave you the Public IP as x.y.z.a
in your host file, you would add
x.y.z.a www.domain1.com domain1.com test.domain.com

After that when you go to www.domain1.com, your browser will get you to the Amazon site and not your normal one.  If you have the option to easily add an identifying mark so that you can confirm that this is the site on the new location versus the old one to put yourself at ease.


i.e. add a image in the site's template indicating it is amazon hosted.  You can always remove it when going with the amzon site live.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
AWS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.