Cloud from A to Z

Creating a web server

Overview

Teaching: 20 min
Exercises: 10 min
Questions
  • What is Apache?

  • How do we install and configure Apache?

  • How do we check that our web server is running?

  • Where do we put our first web page?

Objectives
  • Install Apache2 web-server

  • Configure security rules to allow access to your web-site

In this episode we will install and configure an Apache Web Server. This is free, open source software that is developed and maintained by the Apache Software Foundation and is one of the most widely used web server platforms on the Internet. While most websites use Apache there are alternatives such as Nginx which can provide better performance in cases where a VM is running a single website.

Installing the Apache web server package

Lets install the Apache web server (or HTTP server) package on our VM. To do this we can use the apt command but this time with the sub command install. This command however requires a specific package name. To find a specific package name we can search through the packages with the search sub command for apt.

$ apt search apache
Sorting... Done
Full Text Search... Done
activemq/jammy 5.16.1-1 all
  Java message broker - server

alpine/jammy 2.25+dfsg1-1build1 amd64
  Text-based email client, friendly for novices but powerful

alpine-doc/jammy 2.25+dfsg1-1build1 all
  Text-based email client's documentation

ant/jammy 1.10.12-1 all
  Java based build tool like make

ant-contrib/jammy 1.0~b3+svn177-12 all
  collection of tasks, types and other tools for Apache Ant

ant-doc/jammy 1.10.12-1 all
  Java based build tool like make - API documentation and manual

ant-optional/jammy 1.10.12-1 all
  Java based build tool like make - optional libraries

apache2/jammy-updates,jammy-security 2.4.52-1ubuntu4.1 amd64
  Apache HTTP Server

apache2-bin/jammy-updates,jammy-security 2.4.52-1ubuntu4.1 amd64
  Apache HTTP Server (modules and other binary files)

apache2-data/jammy-updates,jammy-security 2.4.52-1ubuntu4.1 all
  Apache HTTP Server (common files)

apache2-dev/jammy-updates,jammy-security 2.4.52-1ubuntu4.1 amd64
  Apache HTTP Server (development headers)
.
.
.

From this we can see that the package name for the “Apache HTTP Server” is apache2 and we can use the apt install command to install the package.

$ sudo apt install apache2 -y
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
.
.
.
Scanning linux images...

Running kernel seems to be up-to-date.

No services need to be restarted.

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.

Add Security Rule for HTTP

HTTP uses port 80 so we need to add it to our default security group as we did with the SSH port 22. However, in this case we don’t need to restrict it to a specific IP address as we want anyone to be able to see our website.

Visit the default web page

The apache package installs a default web page to test the installation. This page provides basic information about your apache installation and some tips about how you might modify apache’s configuration to suite your needs. Start your web browser and enter your VM’s public IP address into the adress bar 206.12.11.12. You should see something like the image below.

Ubuntu Default Web Page

To create your own web pages you may edit the file /var/www/html/index.html which is the default web page shown above. You can use HTML, CSS, and more to create web pages (see w3schools for tutorials and references for creating web pages with these technologies).

Domain names

In this course we use the public IP address to connect to our VMs through SSH and our web browsers. It is possible to associate this public IP with a domain name using a domain name registrar. Some popular domain name registrars are rebel.ca and godaddy.com but there are many others. After you purchase a domain name, often for something like $10-20 per year, you can register your public IP with your domain name. These domain name registrars will then forward requests for your domain name to your VM having the registered public IP address.

HTTPS

HTTPS is HTTP Secure, many websites use HTTPS to encrypt data sent between a users web browser and their web-server. This is particularly important for websites which handle passwords and other private information such as credit cards. However, it is also possible for data sent from a web-server to be intercepted and modified before the website user receives it. This is true for any website and as such it is a good idea to use HTTPS rather than HTTP. To setup HTTPS however, requires your site to use a domain name rather than an IP address. To setup HTTPS on your site you must create and register a SSL (Secure Sockets Layer, or more recently updated to a TLS or Transport Layer Security) certificate with a third party signing authority. These third party signing authorities will verify that the site a user gets is indeed the site that was registered with that third party signing authority. So this provides more security than simply encrypting data sent to and from a web-server. Many third party signing authorities charge money for registering SSL certificates however letsencrypt is a free third party signing authority. There is also a program which you can download and install which will create the certificate for you, register it with letsencrypt and adjust your web server configuration to use the certificate and server HTTPS called certbot. With the ease with which you can setup HTTPS there is almost no reason not to always use it for your sites.

Key Points