# C. Sean Burns: Notebook

### Site Tools

linux:apache2-intro

# Differences

This shows you the differences between two versions of the page.

 — linux:apache2-intro [2019/01/21 11:24] (current)seanburns created 2019/01/21 11:24 seanburns created 2019/01/21 11:24 seanburns created Line 1: Line 1: + + # Installing Apache2 + ## Date: Thu Nov  1 2018 + Let's install our first web server. First, make sure your machine is up to date + before installing Apache2. In the following examples, I'm already logged in as + root. + + ## Update system first + + bash + # dnf check-update + # dnf update +  + + ## Install httpd + + Now, that the machine is updated. Let's install Apache2. On distributions that + use a package management system, such as dnf on Fedora and apt on + Ubuntu, we can use those systems to install the relevant software. However, + different distributions use different names for the packages. Fedora refers to + the Apache2 software as httpd while Ubuntu refers to it as Apache2. + + Apache2 is not the only web server available. Later on we'll install nginx. + Before we install Apache2, though, let's get some basic info on the package: + + bash + # dnf info httpd +  + + Based on the output, and at the time of this writing, it looks like the + httpd package refers to the Apache HTTP Server, version 2.4.34. I wanted to + highlight this because it's important to know what version of things we're + installing, for a couple of reasons at least. First, although Apache2 has its + own dependencies, other packages will also depend on it. For example, say we + wanted to install Drupal or WordPress, we would first have to install a web + server, like Apache2, and it might be the case that Drupal or WordPress require + a certain minimum version of Apache2. Second, package management systems are + generally conservative, some more or less so. The [current version of + Apache][1] is 2.4.37. But it's not likely that Fedora will use that or some + newer version until the next Fedora upgrade, for example, from Fedora 28 to + Fedora 29. For now, however, this is fine, and we can proceed with the install: + + bash + # dnf -y install httpd +  + + ## Basic checks + + As our book describes, one of the things that makes Apache2, and some other web + servers, so powerful is the library of modules that extend Apache's + functionality. We'll come back to modules next week. For now, we're going to + make sure the server is up and running, configure some basic things, and then + create a basic web site. + + To start, let's make sure that Apache2 is *enabled* and *running* (note that I + truncate some output below using ...: + + bash + # systemctl list-unit-files httpd.service + UNIT FILE       STATE + httpd.service   disabled + + 1 unit files listed. + # systemctl enable httpd.service + # systemctl list-unit-files httpd.service + UNIT FILE       STATE + httpd.service   enabled + + 1 unit files listed. + # systemctl status httpd.service + ... + Active: inactive (dead) + ... + # systemctl start httpd.service + # systemctl status httpd.service + ... + Active: active (running) + ... +  + + ## Creating a web page + + Now that we have it up and running, let's look at the default web page: + + bash + # w3m http://127.0.0.1 +  + + The w3m text-mode browser shows the **Fedora Test Page**. That's a sign + that the default install was successful. Let's now create our first web page. + To do so, we need to know what directory that Apache2 is using to serve + websites. If we read through that **Fedora Test Page** document, it'll tell us + that the default directory is /var/www/html/. Let's go there and create a + webpage with out text editor of choice (I'll use vi, but feel free to use + nano): + + bash + # cd /var/www/html/ + # vi index.html +  + + Then write something like this. Of course, modify the content to suit your own + interests: + + html + + + My first web page using Apache2 + + + +

Welcome

+ +

Welcome to my web site. This is the first web page I have ever created using + Apache2 and Fedora Linux. If you have any questiosn, please email me at sean.burns@uky.edu.

+ +

Thanks!
+ Dr. Burns

+ + + +  + + After you're done, save and close the document. Let's visit our website again + with w3m to see if it works: + + bash + # w3m http://127.0.0.1 +  + + ## Tasks + + Our book has a section titled *Common Configuration Options* on page 490. After + you've completed the above steps, do the following: + + 1. Open /etc/hosts and map a hostname of your choice the IP address for + your main network device, not the lo device. (What command do you need + to issue to locate that IP address?) + 2. Change the default port number from 80 to 8080. (You'll need to locate the + right config file to do this. Hint: it's located somewhere under + /etc/httpd/.) + 3. Restart httpd.service and connect to your website with the new port number. + + **Questions:** + + Let's say you map your IP address to the hostname mywebsite. Then: + + 1. What happens if you do w3m http://mywebsite? + 2. What modification to the URL (*http://mywebsite*) do you need to make to + connect to your web server? + + [1]:https://httpd.apache.org/ + [2]:https://www.amazon.com/Linux-Administration-Beginners-Guide-Seventh/dp/0071845364 +