Skip to content

Day 7 - The server and its services

INTRO

Today you’ll install a common server application - the Apache2 web server - also known as httpd - the “Hyper Text Transport Protocol Daemon”!

If you’re a website professional then you might do things slightly differently, but our focus with this is not on Apache itself, or the website content, but to get a better understanding of:

  • application installation
  • configuration files
  • services
  • logs

YOUR TASKS TODAY

  • Install and run apache, transforming your server into a web server

INSTRUCTIONS

  • Refresh your list of available packages (apps) by: sudo apt update - this takes a moment or two, but ensures that you’ll be getting the latest versions.
  • Install Apache from the repository with a simple: sudo apt install apache2
  • Confirm that it’s running by browsing to http://[external IP of your server] - where you should see a confirmation page.
  • Apache is installed as a “service” - a program that starts automatically when the server starts and keeps running whether anyone is logged in or not. Try stopping it with the command: sudo systemctl stop apache2 - check that the webpage goes dead - then re-start it with sudo systemctl start apache2 - and check its status with: systemctl status apache2.
  • As with the vast majority of Linux software, configuration is controlled by files under the /etc directory - check the configuration files under /etc/apache2 especially /etc/apache2/apache2.conf - you can use less to simply view them, or the vim editor to view and edit as you wish.
  • In /etc/apache2/apache2.conf there’s the line with the text: “IncludeOptional conf-enabled/*.conf”. This tells Apache that the *.conf files in the subdirectory conf-enabled should be merged in with those from /etc/apache2/apache2.conf at load. This approach of lots of small specific config files is common.
  • If you’re familiar with configuring web servers, then go crazy, setup some virtual hosts, or add in some mods etc.
  • The location of the default webpage is defined by the DocumentRoot parameter in the file /etc/apache2/sites-enabled/000-default.conf.
  • Use less or vim to view the code of the default page - normally at /var/www/html/index.html. This uses fairly complex modern web design - so you might like to browse to http://165.227.92.20/sample where you’ll see a much simpler page. Use View Source in your browser to see the code of this, copy it, and then, in your ssh session sudo vim /var/www/html/index.html to first delete the existing content, then paste in this simple example - and then edit to your own taste. View the result with your workstation browser by again going to http://[external IP of your server]
  • As with most Linux services, Apache keeps its logs under the /var/log directory - look at the logs in /var/log/apache2 - in the access.log file you should be able to see your session from when you browsed to the test page. Notice that there’s an overwhelming amount of detail - this is typical, but in a later lesson you’ll learn how to filter out just what you want. Notice the error.log file too - hopefully this one will be empty!

Note for AWS/Azure/GCP users

Don’t forget to add port 80 to your instance security group to allow inbound traffic to your server.

POSTING YOUR PROGRESS

Practice your text-editing skills, and allow your “classmates” to judge your progress by editing /var/www/html/index.html with vim and posting the URL to access it to the forum. (It doesn’t have to be pretty!)

SECURITY

  • As the sysadmin of this server, responsible for its security, you need to be very aware that you’ve now increased the “attack surface” of your server. In addition to ssh on port 22, you are now also exposing the apache2 code on port 80. Over time the logs may reveal access from a wide range of visiting search engines, and attackers - and that’s perfectly normal.
  • If you run the commands: sudo apt update, then sudo apt upgrade, and accept the suggested upgrades, then you’ll have all the latest security updates, and be secure enough for a test environment - but you should re-run this regularly.

EXTENSION

Read up on:

RESOURCES

TROUBLESHOOT AND MAKE A SAD SERVER HAPPY!

Practice what you’ve learned with some challenges at SadServers.com:

Some rights reserved. Check the license terms here