Skip to main content

Deploying Apache Web Server on RedHat/CentOS

Hands-On Lab

 

Photo of

Training Architect

Length

00:30:00

Difficulty

Intermediate

Working with web servers is something that System Administrators should know how to do, since they are very common. In this activity, you will learn how to troubleshoot one virtual host web site which is not working, and how to create another.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Deploying Apache Web Server on RedHat/CentOS

Introduction

Working with web servers is something that System Administrators should know how to do, since they are very common. In this activity, you will learn how to troubleshoot one virtual host web site which is not working, and how to create another.

The Scenario

Our first goal is to troubleshoot why site1 is not responding. We will verify that the server httpd and client lynx software packages are installed, and install them if necessary. We will make sure the httpd.service is enabled, starting, and serving http://site1.linuxacademy.com using the lynx client.

Our second goal is to enable site2. We will use site1 as a model, copying and modifying its configuration file to create http://site2.linuxacademy.com. Until a DNS entry is added, we will update our /etc/hosts file to support the new site.

Logging In

Use the credentials provided on the hands-on lab overview page, and log in as cloud_user.

Verify That the Apache Web Server and Lynx Web Client Are Installed, and Install the Packages if Necessary

Using the yum command, list the httpd and lynx packages to see if they are installed. If they are not installed, then install them:

sudo -i
yum list httpd lynx
yum -y install lynx

Check the Status of the httpd.service, Then Enable and Start the Service if Necessary

Using the systemctl command view the status of the httpd.service:

systemctl status httpd.service

It looks like httpd is disabled, so we've got to start and enable it:

systemctl enable httpd.service --now

Now it should be running. Let's make sure we're serving out a web page:

lynx http://site1.linuxacademy.com

Create a Directory to Contain site2

We need to make a directory for the second site we're going to set up:

mkdir /var/www/site2

Configure the Virtual Host Directory and the Virtual Host

Use sed to edit the site1.conf file and create a site2.conf file:

cd /etc/httpd/conf.d
sed 's/site1/site2/g' site1.conf > site2.conf
cat site2.conf

Add Content to the site2 Page

Now we can use echo to create the /var/www/site2/index.html file containing the text site2:

echo site2 > /var/www/site2/index.html

Add Entry to /etc/hosts for site2.linuxacademy.com

Add the following line to /etc/hosts:

10.0.0.116 site2 site2.linuxacademy.com

Restart httpd.service and Verify site2 Is Running

Using the systemctl command, restart the httpd.service and use lynx to view the http:///site2.linuxacademy.com site:

systemctl restart httpd.service
lynx http://site2.linuxacademy.com

Let's make sure site1 is still working too:

lynx http://site1.linuxacademy.com

Conclusion

We're finished. We figured out why http://site1.linuxacademy.com wasn't working, and were able to set up a second virtual host to serve out http://site2.linuxacademy.com. Congratulations!