RHEL7: Configure an Apache virtual host.

Share this link

Note: This is a RHCE 7 exam objective.


First, follow the instructions to install an Apache web server.

Configuration Procedure

Let’s assume your website is called dummy-host.example.com.

Create the /var/www/html/dummy-host.example.com directory:

# cd /var/www/html
# mkdir dummy-host.example.com

Create an index.html file and assign the correct SELinux context:

# echo "This is a test." > dummy-host.example.com/index.html
# restorecon -R dummy-host.example.com

Create the /etc/httpd/conf.d/vhosts.conf file and paste the following lines:

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

Optionaly, rename the /etc/httpd/conf.d/ssl.conf file, otherwise you get an additional non-working https virtual host displayed in the configuration.

# cd /etc/httpd/conf.d; mv ssl.conf ssl.conf2

Check the validity of the configuration:

# apachectl configtest
Syntax OK

Note: You can also type: # httpd -t

Restart the httpd service:

# apachectl restart

Note1: You can also type: # systemctl restart httpd
Note2: For minor configuration changes, it is also possible to restart the Apache daemon without losing the current connections: # apachectl graceful

Check the virtual host(s) configuration:

# httpd -D DUMP_VHOSTS
VirtualHost configuration:
*:80                   is a NameVirtualHost
         default server dummy-host.example.com (/etc/httpd/conf.d/vhosts.conf:1)
         port 80 namevhost dummy-host.example.com (/etc/httpd/conf.d/vhosts.conf:1)
         port 80 namevhost dummy-host.example.com (/etc/httpd/conf.d/vhosts.conf:1)

Testing Time

Check the configuration:

# yum install -y elinks
# elinks http://dummy-host.example.com
1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 4.00 out of 5)

Leave a Reply

9 Comments on "RHEL7: Configure an Apache virtual host."

Notify of

Sort by:   newest | oldest
1 year 3 months ago
Thank you for your awesome RHCE notes, I really appreciate your time and effort to help others. Just in case few people might wonder, I like to add few notes here: – Time is gold during the exam, it seems to me, the fastest and shortest command that you can run to install everything you need for httpd\apache questions is : # yum groupinstall -y “Web server” – Just to make sure you don’t get any read permission issues, perform below command when you are done creating directories and files under /var/www – # chmod -R 755 /var/www – Don’t… Read more »
6 months 24 days ago

your vitual host config for the second website should be enclosed inside

and one should obviously open port 8080 on the firewall

1 month 16 days ago

Also use:https://www.certdepot.net/rhel7-use-selinux-port-labelling/

As you do not use one of the standard ports

5 months 10 days ago

I was wondering, can we install httpd-manual and use it during exam?

1 month 10 days ago

For people who do not want to remember the syntax (it is worth to know also to other applications):
1. Let’s find mem and doc files:
rpm -qd httpd
2. Let’s check the file from above list:
3. Copy, paste and modify 🙂

16 days 4 hours ago

Hello All, is it normal to see 2 records for each vhost with the following command?
# httpd -D DUMP_VHOSTS


RHCSA7: Task of the day

Allowed time: 10 minutes.
Create a XFS file system of 100MB. Mount it under /mnt. Then, increase its size by 50MB.

RHCE7: Task of the day

Allowed time: 15 minutes.
Configure a Samba server called MYSERVER, belonging to the MYGROUP group, sharing the /shared directory with the name "shared".

Poll for favorite RHEL 7 book

What is your favorite RHEL 7 book to prepare RHCSA & RHCE exams?

View Results

Loading ... Loading ...

Poll for most difficult RHCSA 7 topic

What do you think is the most difficult RHCSA 7 topic?

View Results

Loading ... Loading ...

Poll for most difficult RHCE 7 topic

What do you think is the most difficult RHCE 7 topic?

View Results

Loading ... Loading ...