Reader small image

You're reading from  Mastering Ubuntu Server - Fourth Edition

Product typeBook
Published inSep 2022
PublisherPackt
ISBN-139781803234243
Edition4th Edition
Concepts
Right arrow
Author (1)
Jay LaCroix
Jay LaCroix
author image
Jay LaCroix

Jeremy "Jay" LaCroix is a technologist and open-source enthusiast, specializing in Linux. He has a net field experience of 20 years across different firms as a Solutions Architect and holds a master's degree in Information Systems Technology Management from Capella University. In addition, Jay also has an active Linux-focused YouTube channel with over 250K followers and over 20M views, available at LearnLinuxTV, where he posts instructional tutorial videos and other Linux-related content. He has also written Linux Mint Essentials and Mastering Linux Network Administration, published by Packt Publishing.
Read more about Jay LaCroix

Right arrow

Serving Web Content

The flexible nature of Ubuntu Server makes it an amazing platform on which to host your organization’s web presence. In this chapter, we’ll take a look at Apache and NGINX, which make up the leading web server software on the internet. We’ll go through installing, configuring, and extending both, as well as securing them with Transport Layer Security (TLS). In addition, we’ll also take a look at installing Nextcloud, which is a great solution for setting up your very own cloud environment for your organization to use for collaboration and sharing files. As we work through concepts related to hosting web content on Ubuntu Server, we will cover:

  • Installing and configuring Apache
  • Installing additional Apache modules
  • Securing Apache with TLS
  • Installing and configuring NGINX
  • Setting up and configuring Nextcloud

To get us started, we’ll first look at configuring Apache, as well as some basic...

Installing and configuring Apache

The best way to become familiar with any technology is to dive right in. We’ll begin this chapter by installing Apache. But first, what exactly is Apache? For those that aren’t already aware, Apache is a popular application that is typically run on Linux and Unix servers to serve web pages to users. It runs in the background, and serves HTML pages to those that request a URL that exists on your server.

Installing Apache is very easy; it’s simply a matter of installing the apache2 package:

sudo apt install apache2 

By default, Ubuntu will immediately start and enable the apache2 daemon as soon as its package is installed. You can confirm this yourself with the following command:

systemctl status apache2

In fact, at this point, you already have (for all intents and purposes) a fully functional web server. If you were to open a web browser and enter the IP address of the server you just installed Apache on,...

Installing additional Apache modules

Apache features additional modules that can be installed that will extend its functionality. These modules can provide additional features such as adding support for things like Python or PHP. Ubuntu’s implementation of Apache includes two specific commands for enabling and disabling modules, a2enmod and a2dismod, respectively. Apache modules are generally installed via packages from Ubuntu’s repositories. To see a list of modules available for Apache, run the following command:

apt search libapache2-mod 

In the results, you’ll see various module packages available, such as libapache2-mod-python (which adds Python support) and libapache2-mod-php8.1 (which adds PHP 8.1 support), among many others. Installing an Apache module is done the same way as any other package, with the apt install command. In the case of PHP support, we can install the required package with the following command:

sudo apt install libapache2...

Securing Apache with TLS

Nowadays, it’s a great idea to ensure your organization’s website is encrypted and available over HTTPS. Encryption of web traffic has been historically achieved by utilizing Secure Sockets Layer (SSL) or, more recently, TLS, which is the successor to SSL. Both refer to a method of utilizing cryptography by installing signed certificates that protect and encrypt web traffic. The two functions are different, but the end result is the same. Going forward, it’s recommended to use TLS due to the additional security strength it offers, though it’s not uncommon to see SSL being used nowadays since it hasn’t been completely phased out.

Setting up and benefiting from TLS is not all that difficult to do, and will help protect your organization against common vulnerabilities being potentially exploited. Utilizing TLS doesn’t protect you from all exploits being used in the wild, but it does offer a layer of protection...

Installing and configuring NGINX

Apache isn’t the only technology that is capable of allowing you to host web content on your server. NGINX also serves the same purpose and is gaining popularity quite rapidly. Apache is still a great option, and even if that’s your chosen web server software, it’s a good idea to at least be familiar with NGINX and learn its basics. NGINX itself is a proxy server as well but is capable of also serving web content, which is why it competes with Apache.

Before we do so, I want to mention first that you can really only have one web server service running on a single web server. If you’ve been following along up to now, you currently have a functional Apache web server. If you were to also install NGINX, it probably wouldn’t start as the ports it wants to listen on (port 80 and/or 443) will already be in use. You can run both on a single server, but that’s outside the scope of this book. Ideally, you’...

Setting up and configuring Nextcloud

I figured we’d end this chapter with a fun activity: setting up our very own Nextcloud server. Nextcloud is a very useful web application that’s handy for any organization. Even if you’re not working on a company network, Nextcloud is a great asset for even a single user. You can use it to synchronize files between machines, store and sync contacts, keep track of tasks you’re working on, fetch email from a mail server, and more. To complete this activity, you’ll need a web server to work with. Nextcloud supports multiple different web server platforms, but in this example, we’ll be using Apache.

You’ll also need an installation of MySQL or MariaDB, as Nextcloud will need its own database. We went over installing and managing MariaDB databases in Chapter 13, Managing Databases. I’ll give you all the commands you’ll need to set up the database in this section, but refer back to Chapter...

Summary

In this action-packed chapter, we looked at serving web pages with Apache. We started out by installing and configuring Apache, and then added additional modules. We also covered the concept of virtual hosts, which allow us to serve multiple websites on a single server, even if we only have a single network interface. Then, we walked through securing our Apache server with TLS. With Apache, we can use self-signed certificates, or we can purchase TLS certificates from a vendor for a fee. We looked at both possibilities. We even set up NGINX, which is a very powerful application that is growing in popularity. Finally, we closed out the chapter with a guide to installing Nextcloud, which is an application I’m sure you’ll find incredibly useful.

In the next chapter of our journey, we’ll take a look at the process of automating server configuration with Ansible, which is a lot of fun.

Relevant videos

Further reading

Join our community on Discord

Join our community’s Discord space for discussions with the author and other readers:

https://packt.link/LWaZ0

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mastering Ubuntu Server - Fourth Edition
Published in: Sep 2022Publisher: PacktISBN-13: 9781803234243
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Author (1)

author image
Jay LaCroix

Jeremy "Jay" LaCroix is a technologist and open-source enthusiast, specializing in Linux. He has a net field experience of 20 years across different firms as a Solutions Architect and holds a master's degree in Information Systems Technology Management from Capella University. In addition, Jay also has an active Linux-focused YouTube channel with over 250K followers and over 20M views, available at LearnLinuxTV, where he posts instructional tutorial videos and other Linux-related content. He has also written Linux Mint Essentials and Mastering Linux Network Administration, published by Packt Publishing.
Read more about Jay LaCroix