You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

340 lines
20 KiB

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My Learning Website</title>
<link href="/styles/styles.css" rel="stylesheet" type="text/css">
<link href="/webdevelopment/styles/styles.css" rel="stylesheet" type="text/css">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="banner">
<h1 class="courselink"><a href="https://www.linkedin.com/learning/apache-web-server-administration">Apache Web Server: Administration</a></h1>
<h2 class="lecturer">LinkedIn Learning : Jon Peck</h2>
<h2 class="episodetitle">Introducting Apache HTTP Server</h2>
</div>
<article>
<h2 class="sectiontitle">What is Apache?</h2>
<p>It is modular, functionality can easily be added to the core application.</p>
<p>Different versions</p>
<p>&emsp;&bull;&emsp;1.3 - Introduced 1998, discontinued 2010</p>
<p>&emsp;&bull;&emsp;2.0 - Introduced 2000, discontinued 2013</p>
<p>&emsp;&bull;&emsp;2.2 - Introduced 2005, still being maintained</p>
<p>&emsp;&bull;&emsp;2.4 - Introduced 2009, the current major version</p>
<p>For this course, we use a VirtualBox VM provided with the exercise files (which I will refer to as the Ubuntu VM/Machine etc), an old CentOS VBox for comparison, in some cases (which I will refer to as the CentOS VM/Machine etc) and my own Raspberry Pi Web Server (which I will refer to as the Raspberry Pi). The login details for the VM are</p>
<pre class="inset">
Username: user
Password: lynda.com</pre>
<p>The CentOS VBox I am using is the same one I used for the web services course so it should have Apache installed. As a reminder, the login details for this machine are</p>
<pre class="inset">
Username: philip
Password: $alvationD0wnt0n</pre>
<p>Note, it is possible to access the Ubuntu VBox via ssh using the hostname user@localhost and port number 2222. </p>
<h2 class="sectiontitle">How Is Apache Installed</h2>
<p>It is important to know what type of distro you are using, particularly whether you are using a Debian based distro (such as Ubuntu or Raspbian on which apache is referred to as apache2) or a RedHat based distro (such as CentOS on which apache is referred to as httpd). This will also dictate which package manager was used to install apache, if it was installed in that way. </p>
<p>We can get info on the distro with either</p>
<pre class="inset">
cat/etc/issue</pre>
<p>or</p>
<pre class="inset">
cat /etc/*release</pre>
<p>Let's see what happens when we run the first of these on Ubuntu.</p>
<pre class="inset">
user@apache:~$ cat /etc/issue
Ubuntu 14.04 LTS \n \l</pre>
<p>On a CentOS machine, the same command gives us</p>
<pre class="inset">
[philip@localhost ~]$ cat /etc/issue
\S
Kernel \r on an \m</pre>
<p>On a Raspberry Pi, you will most likely be running Raspbian which is Debian-based (as is Ubuntu) so we would expect similar results to those that we saw with Ubuntu.</p>
<pre class="inset">
philip@raspberrypi:/etc/apache2/sites-available $ cat /etc/issue
Raspbian GNU/Linux 10 \n \l</pre>
<p>Now we will try the second command, again on the same three platforms.</p>
<p>Ubuntu</p>
<pre class="inset">
user@apache:~$ cat /etc/*release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04 LTS"
NAME="Ubuntu"
VERSION="14.04, Trusty Tahr"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 14.04 LTS"
VERSION_ID="14.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"</pre>
<p>CentOS</p>
<pre class="inset">
[philip@localhost ~]$ cat /etc/*release
CentOS Linux release 7.8.2003 (Core)
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
CentOS Linux release 7.8.2003 (Core)
CentOS Linux release 7.8.2003 (Core)</pre>
<p>And the Raspberry Pi</p>
<pre class="inset">
philip@raspberrypi:/etc/apache2/sites-available $ cat /etc/*release
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"</pre>
<p>The results are pretty standard for all three here. One interesting point is ID_LIKE which shows the type of distro.</p>
<p>On either type of system, there are several ways to install Apache. The one we will cover in most detail is probably the most common and that is installation via a packet manager. So this would be</p>
<pre class="inset">
sudo apt install</pre>
<p>on a Debian system or</p>
<pre class="inset">
sudo yum install</pre>
<p>on a RedHat system.</p>
<p>To check if Apache was installed in this way, we can query the package manager library so</p>
<pre class="inset">
user@apache:~$ dpkg -l | grep apache
ii apache2 2.4.7-1ubuntu4 i386 Apache HTTP Server
ii apache2-bin 2.4.7-1ubuntu4 i386 Apache HTTP Server (binary files and modules)
ii apache2-data 2.4.7-1ubuntu4 all Apache HTTP Server (common files)
ii apache2-utils 2.4.7-1ubuntu4 i386 Apache HTTP Server (utility programs for web servers)</pre>
<p>or</p>
<pre class="inset">
[philip@localhost ~]$ rpm -qa | grep httpd
httpd-tools-2.4.6-93.el7.centos.x86_64
httpd-2.4.6-93.el7.centos.x86_64</pre>
<p>Installing Apache from source can be a more difficult option but depending on requirements (eg, a unique platform or the need to address specific security issues) it might be necessary. </p>
<p>The best way to tell if that is how Apache was installed is to look for the source code which would often be located in the /usr/local/src directory or the users home directory. For example, we can check the /usr/local/src directory with </p>
<pre class="inset">
ls -la /usr/local/src</pre>
<p>and similarly </p>
<pre class="inset">
ls /home/user</pre>
<p>to check the home directory of a user called user. We could also use find or locate to look for the source files. This assumes that we know the name of the source code but it is easy enough (see the Apache download page <a href="https://httpd.apache.org/download.cgi">here</a> which, at the very least, would provide some ideas for search terms.</p>
<p>The source code would likely have httpd in the name (possibly apache) so we could use locate with either term and see if anything in the results looks like source code (would likely have something like *.tar.bz2 at the end).</p>
<p>A command such as</p>
<pre class="inset">
sudo find / -name *.tar.*</pre>
<p>may be useful for this purpose. I have executed this with elevated privileges because I won’t have the appropriate permissions for many of the directories I am searching in. Note that the parameters for the find command are</p>
<p>&emsp;&bull;&emsp;the location to search in, in this case / so search everywhere</p>
<p>&emsp;&bull;&emsp;the type of search - in this case -name because we are searching based on the name of the file</p>
<p>&emsp;&bull;&emsp;the search term, in this case *.tar.* which should locate any file that includes a .tar extension with an additional extension so this should locate most source files</p>
<h2 class="sectiontitle">Common Operations such as Restarting and Reloading</h2>
<p>Note that Apache is not a monolithic service, it is a parent service with multiple child service, each of which could be serving up different web services.</p>
<p>Apache provides a script, apachectl, used for management purposes. Some distros also provide an additional layer of abstraction on top of that</p>
<p>The following figures provide some details relating to the available actions.</p>
<h3>The status and start actions</h3>
<img src="images/image1.png" alt="Apache Actions - status and start">
<h3>The stop and graceful-stop actions</h3>
<img src="images/image2.png" alt="Apache Actions - stop and graceful-stop">
<h3>The restart action</h3>
<img src="images/image3.png" alt="Apache Actions - restart">
<h3>The graceful - AKA reload action</h3>
<img src="images/image4.png" alt="Apache Actions - graceful - AKA reload">
<p>We will try the status action first. I will not do this on the Raspberry Pi because apachectl is not enabled there.</p>
<p>On Ubuntu, the output we get from running the apachectl status command is</p>
<pre class="inset">
user@apache:~$ apachectl status
Apache Server Status for localhost (via ::1)
Server Version: Apache/2.4.7 (Ubuntu)
Server MPM: event
Server Built: Apr 3 2014 12:20:25
__________________________________________________________________
Current Time: Wednesday, 30-Dec-2020 06:38:08 PST
Restart Time: Tuesday, 29-Dec-2020 15:09:45 PST
Parent Server Config. Generation: 2
Parent Server MPM Generation: 1
Server uptime: 15 hours 28 minutes 22 seconds
Server load: 0.00 0.01 0.05
Total accesses: 1 - Total Traffic: 3 kB
CPU Usage: u0 s.04 cu0 cs0 - 7.18e-5% CPU load
1.8e-5 requests/sec - 0 B/second - 3072 B/request
1 requests currently being processed, 49 idle workers
PID Connections Threads Async connections
total accepting busy idle writing keep-alive closing
1051 0 yes 1 24 0 0 0
1052 0 yes 0 25 0 0 0
Sum 0 1 49 0 0 0
_________________W________________________________..............
................................................................
......................
Scoreboard Key:
"_" Waiting for Connection, "S" Starting up, "R" Reading Request,
"W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,
"C" Closing connection, "L" Logging, "G" Gracefully finishing,
"I" Idle cleanup of worker, "." Open slot with no current process</pre>
<p>Running the same command on the CentOS machine, we get</p>
<pre class="inset">
[philip@localhost ~]$ apachectl status
* httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2020-12-30 13:31:39 GMT; 1h 7min ago
Docs: man:httpd(8)
man:apachectl(8)
Process: 1228 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE)
Main PID: 1228 (code=exited, status=1/FAILURE)
Dec 30 13:31:36 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
Dec 30 13:31:39 localhost.localdomain httpd[1228]: (99)Cannot assign requested addr...0
Dec 30 13:31:39 localhost.localdomain httpd[1228]: no listening sockets available, ...n
Dec 30 13:31:39 localhost.localdomain httpd[1228]: AH00015: Unable to open logs
Dec 30 13:31:39 localhost.localdomain systemd[1]: httpd.service: main process exite...E
Dec 30 13:31:39 localhost.localdomain systemd[1]: Failed to start The Apache HTTP S....
Dec 30 13:31:39 localhost.localdomain systemd[1]: Unit httpd.service entered failed....
Dec 30 13:31:39 localhost.localdomain systemd[1]: httpd.service failed.
Dec 30 14:16:02 localhost.localdomain systemd[1]: Unit httpd.service cannot be relo....
Hint: Some lines were ellipsized, use -l to show in full.</pre>
<p>You might notice that this shows that the service failed and I wasn't able to start it again so I reinstalled httpd and tried again. This worked and running the command again yielded the following</p>
<pre class="inset">
[philip@localhost ~]$ apachectl status
* httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2020-12-30 14:49:01 GMT; 3min 50s ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 13054 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
Tasks: 6
CGroup: /system.slice/httpd.service
|-13054 /usr/sbin/httpd -DFOREGROUND
|-13059 /usr/sbin/httpd -DFOREGROUND
|-13060 /usr/sbin/httpd -DFOREGROUND
|-13061 /usr/sbin/httpd -DFOREGROUND
|-13062 /usr/sbin/httpd -DFOREGROUND
`-13063 /usr/sbin/httpd -DFOREGROUND
Dec 30 14:49:01 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
Dec 30 14:49:01 localhost.localdomain httpd[13054]: AH00558: httpd: Could not relia...e
Dec 30 14:49:01 localhost.localdomain systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.</pre>
<p>Note that the web server on the Ubuntu machine has been set up to server a page containing the text of Alice's Adventures in Wonderland which we can access via the URL, <a href="http://localhost:8080/">http://localhost:8080/</a>.</p>
<p>Now, let's stop Apache with</p>
<pre class="inset">
sudo apachectl -k stop</pre>
<p>The command executes without providing any feedback. If we check the status again, we will see an error message</p>
<pre class="inset">
user@apache:~$ apachectl status
Looking up localhost
Making HTTP connection to localhost
Alert!: Unable to connect to remote host.
lynx: Can't access startfile http://localhost/server-status
'www-browser -dump http://localhost:80/server-status' failed.
Maybe you need to install a package providing www-browser or you
need to adjust the APACHE_LYNX variable in /etc/apache2/envvars</pre>
<p>This looks quite different from the output we saw on CentOS when Apache wasn't running. That could be because of the different distros or because on CentOS, Apache had failed rather than being stopped.</p>
<p>This can easily be tested by stopping the service and checking the status and I can see that the output is more or less the same as shown in figure 14. The most significant difference I could see was that when the service was stopped, the status showed that the httpd service was disabled whereas in figure 14, it shows as enabled.</p>
<p>In any case, it does seem likely that the difference in output is probably down to the different distros. It may also be worth noting that the Ubuntu machine is running version 2.4.7 of Apache whereas the CentOS machine is running version 2.4.6.</p>
<p>Not surprisingly, if we go back to the web page served up by the web server on the Ubuntu machine, we will see an error message like the one show here.</p>
<img src="images/image5.png" alt="The error message we see when trying to access the web page served up by the Ubuntu machine when Apache is stopped">
<p>We can start the server up again on the Ubuntu machine with</p>
<pre class="inset">
sudo apachectl start</pre>
<p>Again, we don't see any output from this command, there is nothing to confirm the service has started up but we can check it either with the status action or by reloading the page in the web browser. Either method should confirm that the service is running again. </p>
<p>We can also interact with the apache service via a standardized script provided with most distros. This is stored in the /etc/init.d file and the script is called apache2 on the Ubuntu machine. The same script is on the Raspberry Pi but there doesn't seem to be either the same script or an equivalent on the CentOS machine.</p>
<p>Below, we can see a number of commands where the script is used to interact with Apache on the Ubuntu machine.</p>
<pre class="inset">
user@apache:~$ /etc/init.d/apache2 stop
* Stopping web server apache2 *
user@apache:~$ /etc/init.d/apache2 start
* Starting web server apache2 *
user@apache:~$ /etc/init.d/apache2 status
* apache2 is running
user@apache:~$ /etc/init.d/apache2 graceful-stop
* Stopping web server apache2 *
user@apache:~$ /etc/init.d/apache2 restart
* Restarting web server apache2 [fail]
user@apache:~$ /etc/init.d/apache2 reload
* Reloading web server apache2</pre>
<p>Note that every command reports back with some sort of status message, for instance, letting us know that the service is being stopped, started and so on.</p>
<p>We can also use the status action with this script, but the output from this is as terse as the messages we saw earlier so this will tell us whether the service is running or not but nothing else.</p>
<p>Newer versions of Linux also provide an additional level of abstraction which is just service and the service name is either apache2 on the Ubuntu machine and httpd on the CentOS machine.</p>
<p>The usage is similar to the script in /etc/init.d and provides the same output on the Ubuntu machine so</p>
<pre class="inset">
user@apache:~$ service apache2 status
* apache2 is running</pre>
<p>On the CentOS machine (recall that there is no script in /etc/init.d), the output is similar to what we see with apachectl so</p>
<pre class="inset">
[philip@localhost ~]$ service httpd status
Redirecting to /bin/systemctl status httpd.service
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2020-12-30 18:59:24 GMT; 3min 41s ago
Docs: man:httpd(8)
man:apachectl(8)
Process: 13437 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=1/FAILURE)
Main PID: 16075 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
Tasks: 6
CGroup: /system.slice/httpd.service
├─16075 /usr/sbin/httpd -DFOREGROUND
├─16079 /usr/sbin/httpd -DFOREGROUND
├─16080 /usr/sbin/httpd -DFOREGROUND
├─16081 /usr/sbin/httpd -DFOREGROUND
├─16082 /usr/sbin/httpd -DFOREGROUND
└─16083 /usr/sbin/httpd -DFOREGROUND
Dec 30 18:59:24 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
Dec 30 18:59:24 localhost.localdomain httpd[16075]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' direct... this message
Dec 30 18:59:24 localhost.localdomain systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.</pre>
</article>
<div class="btngroup">
<button class="button" onclick="window.location.href='configuring.html';">
Configuring Apache
</button>
<button class="button" onclick="window.location.href='troubleshooting.html';">
Troubleshooting with Log Files
</button>
<button class="button" onclick="window.location.href='conclusion.html';">
Conclusion
</button>
<button class="button" onclick="window.location.href='/webdevelopment/apachewebserveradmin/apachewebserveradmin.html'">
Course Contents
</button>
<button class="button" onclick="window.location.href='/webdevelopment/webdevelopment.html'">
Web Development Page
</button>
<button class="button" onclick="window.location.href='/index.html'">
Home
</button>
</div>
</body>
</html>