09. Apache Web Server
09. Apache Web Server
Introduction
A Web server is a program that uses HTTP (Hypertext Transfer Protocol) to serve the files that
form Web pages to users, in response to their requests, which are forwarded by their
computers' HTTP clients. Dedicated computers and appliances may be referred to as Web
servers as well. Apache is the most widely-installed Web server and a major component in
LAMP stack.
Requirements
1. A machine as Web server
2. A client machine with GUI operating systems (Windows 10 or Ubuntu
Desktop)
3. DNS server is turned on
4. Privileged access to your Ubuntu system as root or via sudo command is
required
Outcomes
You will provide basic web service using apache2 on the www.dfn50303.com machine. By
the end of this activity, you will have a web server on Ubuntu Server 22.04.1 LTS. You
also manage the Apache service via systemd and create virtual hosts for setting up websites.
1. On the www machine, update system and install the Apache package (and all required
dependencies):
2. After the installation finished, check with the systemd init system to make sure the
service is running by typing:
or,
Note: Apache on Ubuntu 22.04.1 LTS has one server block enabled by default that is
configured to serve documents from the /var/www/html directory.
When you required a server hosting multiple sites, create a directory structure within
/var/www for our dfn50303.com site, leaving /var/www/html in place as the default
directory to be served if a client request does not match any other sites.
3. Create the directory for dfn50303.com as follows, using the -p flag to create any
necessary parent directories::
<html>
<head>
<title>Welcome to DFN50303.com!</title>
</head>
<body>
7. In order for Apache to serve this content, it's necessary to create a virtual host file
with the correct directives. Instead of modifying the default configuration file located
at /etc/apache2/sites-available/000-default.conf directly, let's make a new
one at /etc/apache2/sites-available/dfn50303.com.conf:
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName dfn50303.com
ServerAlias www.dfn50303.com
DocumentRoot /var/www/dfn50303.com/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Note: Notice that you are updated the DocumentRoot to a new directory and ServerAdmin
to an email that the dfn50303.com site administrator can access. You are also added two
directives: ServerName, which establishes the base domain that should match for this
virtual host definition, and ServerAlias, which defines further names that should match
as if they were the base name.
Output
Syntax OK
14. Apache should now be serving your domain name. From any machine on your
network, you can test this by navigating to http://www.dfn50303.com
(or http://dfn50303.com).