Day 7 - The server and its services
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
- 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/apache2.conf- you can use
lessto simply view them, or the
vimeditor to view and edit as you wish.
/etc/apache2/apache2.confthere’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.confat 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
vimto 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://18.104.22.168/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.htmlto 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/logdirectory - look at the logs in
/var/log/apache2- in the
access.logfile 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.logfile too - hopefully this one will be empty!
Posting your progress
Practice your text-editing skills, and allow your “classmates” to judge your progress by editing
vim and posting the URL to access it to the forum. (It doesn’t have to be pretty!)
- 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.
Read up on:
Some rights reserved. Check the license terms here