Here’s how to host multiple sites on your EC2 instance running the Amazon Linux AMI. Remember to make a backup of your instance before proceeding.
Assign a Static IP Address
The first thing you should do, if you haven’t already, is assign a static IP address to your EC2 instance. You can do this in the Amazon EC2 control panel (go to Elastic IPs -> Allocate New Address). Assign the IP address to your instance, and write it down for later.
Point the URLs to Your EC2 IP Address
So, the next step is to go ahead and point your URL at your EC2 IP address. Log into your domain hosting account. In this case, I’ll describe how to do it for Go Daddy. Launch the Domains control panel and click the first domain that you want to point to your EC2 server.
- Click the tab that says “DNS Zone File”. You will be editing the A record of the zone file to point to the EC2 IP address.
- Click the Edit button
- Click on the IP address in the “@” row at the top. Write it down, just in case you need to revert back to it.
- Replace the IP address with the IP address of your EC2 instance.
- If you want to map subdomains (like “mobile.yoursite.com”), add those as well, but instead of “@” for the host, enter the subdomain name (i.e., “mobile”). Use the same EC2 IP address in the next field.
- Repeat this process for all of the domain names that you want to point to your EC2 server.
Setting Up the Server
Now, SSH into your EC2 instance using a terminal window (Mac) or Putty or Cygwin on a PC. There are many online tutorials on how to set this up. Then follow these instructions.
- Go to the html folder where your sites will reside. Usually this is located at /var/www/html
- Create separate folders for each of the sites you want to host.
- Next, go to your httpd folder. Usually this is at /etc/httpd/conf
- Open httpd.conf using your favorite editor and uncomment this line by removing the hash in front.
NameVirtualHost *.80
If your httpd.conf file does not have this line, don’t add it. Newer versions of Apache don’t need it. (If you are unsure, you can add it and you’ll just get a warning when you restart httpd).
- Add the following lines to your httpd.conf file for each domain name and subdomain that you want to add. Below I give three examples. The middle one shows a subdomain. Substitute your email address, folder names, and domain names as appropriate.
<VirtualHost *:80> ServerAdmin webmaster@yourdomain.com DocumentRoot "/var/www/html/website1_folder" ServerName yourdomain.com ErrorLog "logs/yourdomain.com-error_log" CustomLog "logs/yourdomain.com-access_log" common </VirtualHost> <VirtualHost *:80> ServerAdmin webmaster@yourdomain.com DocumentRoot "/var/www/html/website2_folder" ServerName subdomain.yourdomain.com ErrorLog "logs/yourdomain.com-error_log" CustomLog "logs/yourdomain.com-access_log" common </VirtualHost> <VirtualHost *:80> ServerAdmin webmaster@yourdomain.com DocumentRoot "/var/www/html/website3_folder" ServerName anotherdomain.com ErrorLog "logs/yourdomain.com-error_log" CustomLog "logs/yourdomain.com-access_log" common </VirtualHost>
- Restart httpd by typing this at the command line:
> sudo service httpd restart
Did it work? If not, here is one possible cause. There might be another configuration file interfering with this one. Check for another .conf file in /etc/httpd/conf.d. Often your primary httpd.conf will include another .conf file in this directory. Make sure it doesn’t have some Virtual Host settings which are interfering with yours. If so, comment them out.
If you are using this to expose something like phpMyAdmin to the world, you might want to add additional security above the native login screen. This is a great article on how to add an Apache login screen.
Let me know how it went for you. – Brian

I am a freelance web developer and consultant based in Santa Monica, CA. I’ve been designing websites using WordPress and from scratch using HTML, CSS, PHP, and JavaScript since 2010. I create websites and web applications for businesses, nonprofits, and other organizations. I have a degree in Electrical Engineering (BSEE) from California Institute of Technology and a degree in Engineering Management (MSEM) from Stanford University. If you need help with your site, you can hire me!
Hi ,
When I’m doing the above thing , my phpmyadmin not working which is on http://MY-IP/phpmyadmin, what should I do regarding this ??
Hey, Brian, this is really brilliant reading with lots of information! I have no idea about “Setting Up the Server” reading. By the way, now, I am so clear about it and got some valuable information. Thanks and keep up the good work!
Thank you. That all worked for me. It is possible to assign SSL certificates for the individual hosted domains also? Many thanks.
can i host multiple domains in one Microweber instance installed on ec2 AWS?
So basically, i want to install a microweber on one ec2 container then register multiple blogs/users on the same microweber. is it possible ?
any help and idea would be appreciated!
Great tutorial! I’m use this VirtualHost config to 2 domains on my ec2 and it’s work!!!!! thaaanks!!
this way only running one website
Single Instance, Multiple domain with indvidual ip is that possible?
Everytime i miss something i bump here ;)
Really good tutorial, thank you!
i installed php-fpm on an ec2 instance, but it seems that only works with a single domain as best i can tell ??
September 2017 on AWS EC2 Instance. It works !! Thanks
I keep having an issue where the server locks up by using this method. It gives me connection errors, and I have to reboot in order to get everything working again.
Still works like a charm in 2017. Thanks!
Great! Glad it worked for you!
Brian
Man I’ve been struggling with this for a long time now. I want to host site1.com and site2.com on the same instance. so i created 2 … however, both sites get redirected to the 1st specified…
I am using t2.micro. In my system when company signup like company1 so its url will be company1.domain.com
how can i get this with script is there any api please guide me through that
I have it all set up, but I am accessing my ec2 instance by putting its IP address in my browser. When I do that it gives me the first website in the list. How can I tell it to give me some other instance besides the first one?
how many subdomains does single ec2 instance can handle. i want to deploy an application with 300 subdomains, Is it possible with a single instance? If yes , then how which instance to choose and if not how many would be required and what size ?
Hi Brian – thanks for the write up. I’ve done everything you said, however, http://www.domain2.com always seems to resolve to www,domain1.com i.e. both domain names seem to point to the same folder. Any ideas?
Hello,
Very helpful article. If i followed this tutorial ( https://aws.amazon.com/getting-started/tutorials/launch-a-wordpress-website/?nc1=h_ls ) to host a wordpress site on my aws and i want to host another website on the same aws ec2, should i just Launch another Instance and follow the same steeps or there is something else that i need to do?
Hi ,
I created EC2 instance in aws and installed wamp server 3.0.16 configure and working well. But I want to add another one domain in same wamp server for another web site.Thans in advance
thanks for info, but having real troubles… i can get index.html or other html files to work at virtualhosts but not php. it is perhaps also complicated by wanting unique IP addresses per website, which i’ve done with elastic ip and configuring the virtual hosts at the associated private ip. i’m running php-fpm so maybe that’s the issue?
I followed these steps but cnames do not work. The root domains work fine like xxx.com yyy.com zzz.com However, the cnames show the same page. http://www.xxx.com http://www.yyy.com and http://www.zzz.com show the same thing
I need redirect three domain in single linux server. example.com to http://www.example.com it’s same for three domain. How to set redirection. please give solution for that.
Do all of these sites read from the same wp-database on the backend? Or did you setup a separate database for each site?
I was hoping to know which EC2 instance is most suitable for hosting multiple websites. I am planning to buy hosting from a managed hosting platform (this one: http://www.cloudways.com/en/amazon-cloud-hosting.php ) (since using AWS directly is a lot technical for me) and they have 6 options. The instructions you have provided to host multisite on AWS may be different for different instance types?
Hi Oliver,
The limiting factor is not so much how many websites you are hosting but the amount of traffic and what kind of sites. I am using an EC2 small instance to host a WordPress site which gets around 1.5K hits a day, and it’s fine.
The instructions I provided for hosting multiple websites should be the same regardless of the type of instance.
Best,
Brian
Hi Brian,
Thanks for the great recipe ! We still in the learning process and insides like these are very helpful to understand the processes.
Now we have a small problem dough, you may able to give us an idea in how to sort it out…
We have a single instance, 2 separate domains pointing to 2 separate wp installs for low traffic experiment sites. Now the back end works beautifully, however the first site installed (maybe alphabetic order too) takes precedent over the other one, so both domains show only one site. All our attempts to introduce the vhost lines (as proposed on step 5) on httpd.conf failed with a server error…it also fail if we introduce a new vhost.conf under conf.d… it maybe because there is a super default host in place that we are missing.
Domain1 > (WP back-end) site1 OK – (showing) http://www.site1.com – OK
Domain2 > (WP back-end) site2 OK – (showing) http://www.site1.com – Showing the 1st site instead…?
We appreciate any ideas.
Thank you
Hi E.Alen,
The only thing I can think of is that there is another .conf file interfering with the one you are modifying. Check for included .conf files…
Best,
Brian
Hi Brian,
Thank you very much for your reply!
We have checked it all… there is no other conf under the conf directory, and the other conf files on the conf.d directory also don’t seemed to have anything to do with the httpd apach…. it seems a very simple thing missing, but at the same time we can’t see what we are doing wrong.
Is there a way to see which is the active apache default directive and where is written?
Thank you
HI,
Solution to this is to put all sites in single tag.
ServerAdmin webmaster@yourdomain.com
DocumentRoot “/var/www/html/website1_folder”
ServerName yourdomain.com
ErrorLog “logs/yourdomain.com-error_log”
CustomLog “logs/yourdomain.com-access_log” common
ServerAdmin webmaster@yourdomain.com
DocumentRoot “/var/www/html/website2_folder”
ServerName subdomain.yourdomain.com
ErrorLog “logs/yourdomain.com-error_log”
CustomLog “logs/yourdomain.com-access_log” common
Hi very good tutorial and thank you for posting it. I wonder if we can apply that for 2 domains with ssl certificate
Hi Mark,
Awesome, thanks for sharing very informative it would be awesome if you can guide / write us on how to install SSL certificate for Individual domains if any wants HTTPS when we follow above approach ??
Thanks in Advance
Regards
Santhosh
Please help to create a subdomain(m.securedomain.com) of http://www.securedomain.com and host (m.securedomain.com) website content on same AWS-EC2 .
Methord which we already try:
Step: 1. Logged in my AWS Account. went to AWS Route 53–> Create Hosted Zone for “m.securedomain.com”.
Step: 2. Add New Record Set “A” with my Elastic IP(Same of the main domain http://www.securedomain.com)
Step: 3. Copy “m.securedomain.com” NS value and Paste Add New “NS” Create Record Set http://www.securedomain.com.
Step: 4. Create a separate folders “m.securedomain.com” under /var/www/; while my main website is located at /var/www/html. Add new file into “/var/www/m.securedomain.com/index.html”
Step: 5. Goto httpd folder at /etc/httpd/conf and open httpd.conf then add the following lines:
ServerName securedomain.com
DocumentRoot “/var/www/html”
ServerAdmin webmaster@localhost
ServerName m.securedomain.com
ServerAlias m.securedomain.com
DocumentRoot “/var/www/m.securedomain.com/”
Step: 6. Restart httpd services
Step: 7. Login my godaddy account–> Select Domain–> DNS Zone File–> Add A Record with(A) Record Type: A B) Host: m C) Points To: Elastic IP of securedomain.com)
Still it does not working. Please help me to resolve this issue?
Nice to see you’re still answering your comments, so I know you’re still watching them.
Just wanted to drop a thank you on this. I just needed the info on the Apache config, and this was a perfect reference for those of us that know our way around *mostly*. Turned an hour of dinking around into a 5 minute job.
Thanks so much!
Hi, i have site abc.com (wordpress) on a ip and abc.com/new (core php). and i want to transfer it on new domain on same IP . what should i do. Both are on aws server
Thank you for the help! I now bring you… infinitepizza dot com !
very interesting blog. None of these referenced files or folders exist upon first instance set up. etc/httpd/conf does not exist.
Thank you for your explanation. I have one question, should the seperate folders be put in /var/www or /var/www/html?
Nevermind, I found the answer :D
But I am not finding the httpd folder in the /etc, any idea?
It’s probably /etc/apache2/
Thanks for this Brian! Very clear.
Thanks Tom! Glad it was useful! – Brian
Is it possible to load if ABC.com point it to ip/admin
If xyz.com point it to ip/web like that
Hello,
i have a website “e.g abcd.com”.
Where we are managing blog posts of different states (e.g. newyork,california etc).
Now can it be possible in AWS server to show the links like
newyork.abcd.com
california.abcd.com
where newyork or california are not the subdomains there are a parameter based on that the posts are filterd in my website.
Can you help me by guiding what will be the best way to achieve it.
Thanks Brian, I am still playing around with ec2 free tier and this was a great walk through of the virtual host settings.
Great Post … Definitely glad that I found your blog I am hosting for a couple of clients that is use hostgator … I must say their service has gone bad … Since I just started using AWS for a enterprise client I thought how would I host my smaller clients in AWS and thanks to you I have a solution …
Good article, getting ready to try it out. Thanks.
Thanks for this Information.. Works like a charm.
Thanks for this
Thanks so much for your article. i just edit /etc/httpd/conf/httpd.conf and it works.
Hi,
I changed my dns with “A”, but… ¿what I must set in dns1 and dns2 points?
you need to have your DNS alread hosted somewhere like GoDaddy (in the example). they offer the option to use a free DNS like “ns1.godaddy.com, ns2.godaddy.com” and then you go to “advanced settings” and then set your A and CNAME entries. hope it help you..
Is there any apps that we can use to make Amazon EC2 works like user friendly hosting (something like if i buy hosting from godaddy, they give us control panel and for reseller, we have WHM).
Thanks
Very helpful article. I would like to ask if this configuration is acceptable for auto scaling instances. Will I have problems with auto scaling
you can use autoscaling for this type of deployments provided you update the ami of your instance in timely manner if you make any changes to the wordpress sites eg: blog posts etc,,