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
- 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: sudo 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/apache.conf - you can use less to simply view them, or the vim editor to view and edit as you wish
- The location of the default webpage is defined by the DocumentRoot parameter in the file /etc/apache2/sites-available/default
- Use vim to edit the default page - normally at /var/www/index.html - even if you've never seen HTML before you should see how to change the displayed body text, and then reload your the webpage in your browser to see the result.
- Notice the directory /etc/apache2/conf.d - the settings in the files in this folder are merged in with those from /etc/apache2/apache2.conf at load. This approach of lots of small specific config files is common. The ".d" extension has no special meaning to the operating system, but is a common convention to denote a directory.
- If you're familiar with configuring web servers, then go crazy, setup some virtual hosts, or add in some mods etc.
- As with the vast majority of Linux software, 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, and later you'll see we'll see how to filter out what we want. Notice the error.log file too - hopefully this one will be empty!
Practice your text-editing skills, and allow your "classmates" to judge your progress by editing /var/www/index.html 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 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. 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: