AWS EC2: How To Set Up Apache Virtual Hosts on CentOS 7

Are you looking for a way to host multiple sites on your AWS EC2 instance? Well it is possible, after all it is still apache that is running on the server. Below is a quick step i used to have two of my applications running on my AWS EC2 micro server.

Before you Start!

Before you begin with this guide, there are a few steps that need to be completed first. link

You will need access to a CentOS 7 server with a non-root user that has sudo privileges.

You will also need to have Apache installed in order to configure virtual hosts for it. If you haven’t already done so, you can use yum to install Apache through CentOS’s default software repositories:

sudo yum -y install httpd
sudo systemctl enable httpd.service

After these steps are complete, log in as your non-root user account through SSH and continue with the tutorial.

Note: The example configuration in this guide will make one virtual host for and another We will be using these 2 throughout the guide, but you should substitute your own domains or values while following along or after you test that it works with this example.

Step 1: Create your new website directory

sudo mkdir -p /var/www/
sudo mkdir -p /var/www/

Step 2: Grant permissions to the logged in User

sudo chown -R $USER:$USER /var/www/
sudo chown -R $USER:$USER /var/www/
sudo chmod -R 755 /var/www

Step 3: Create pages inside your Virtual Host

vi /var/www/

Create test html content (this is just a test)

<h1>Success! The virtual host is working!</h1>

Repeat Create Step 3 for all your new Virtual Hosts

Step 4: Create New Virtual Host Config Files

sudo mkdir /etc/httpd/sites-available
sudo mkdir /etc/httpd/sites-enabled

Open /etc/httpd/conf/httpd.conf and add below to the end of the file

IncludeOptional sites-enabled/*.conf

Create the First Virtual Host File

sudo vi /etc/httpd/sites-available/

<VirtualHost *:80>
    DocumentRoot /var/www/
    ErrorLog /var/www/
    CustomLog /var/www/ combined

Copy First Virtual Host and Customize for Additional Domains

Step 5: Enable the New Virtual Host Files

Now that we have created our virtual host files, we need to enable them so that Apache knows to serve them to visitors

sudo ln -s /etc/httpd/sites-available/ /etc/httpd/sites-enabled/

Repeat same for all new virtual domains

When you are finished, restart Apache to make these changes take effect:

sudo apachectl restart

Check your domain now:, you should be good.

Note: If you have .htaccess in your applications, you can eithier use your rewrite/mod rules within each virtual host config or you can check your


Update AllowOverride None to AllowOverride All


If it works, let me know …cheers