main.append(addSyntax(" • 2.2 - Introduced 2005, still being maintained"))
main.append(addSyntax(" • 2.4 - Introduced 2009, the current major version"))
main.append(addParagraph("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"))
main.append(addParagraph("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"))
main.append(addParagraph("Note, it is possible to access the Ubuntu VBox via ssh using the hostname user@localhost and port number 2222. "))
main.append(addParagraph("How Is Apache Installed"))
main.append(addParagraph("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. "))
main.append(addParagraph("We can get info on the distro with either"))
main.append(addInset("cat/etc/issue"))
main.append(addParagraph("or"))
main.append(addInset("cat /etc/*release"))
main.append(addParagraph("Let's see what happens when we run the first of these on Ubuntu."))
main.append(addParagraph("On a CentOS machine, the same command gives us"))
main.append(addInsetList(["[philip@localhost ~]$ cat /etc/issue","\S","Kernel \r on an m"]))
main.append(addParagraph("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."))
main.append(addParagraph("The results are pretty standard for all three here. One interesting point is ID_LIKE which shows the type of distro."))
main.append(addParagraph("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"))
main.append(addSyntax("sudo apt install"))
main.append(addParagraph("on a Debian system or"))
main.append(addSyntax("sudo yum install"))
main.append(addParagraph("on a RedHat system."))
main.append(addParagraph("To check if Apache was installed in this way, we can query the package manager library so"))
main.append(addInsetList(["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)"]))
main.append(addParagraph("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."))
main.append(addParagraph("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"))
main.append(addSyntax("ls -la /usr/local/src"))
main.append(addParagraph("and similarly "))
main.append(addSyntax("ls /home/user"))
main.append(addParagraph("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."))
main.append(addParagraph("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)."))
main.append(addParagraph("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"))
main.append(addInsetBulletList(["emsp;• the location to search in, in this case / so search everywhere "," • the type of search - in this case -name because we are searching based on the name of the file"," • 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"]))
main.append(addParagraph("Common Operations such as Restarting and Reloading"))
main.append(addParagraph("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."))
main.append(addParagraph("Apache provides a script, apachectl, used for management purposes. Some distros also provide an additional layer of abstraction on top of that"))
main.append(addParagraph("The following figures provide some details relating to the available actions."))
main.append(addSubHeader("The status and start actions"))
main.append(addImageWithCaption("images/image1.png","Apache Actions - status and start"))
main.append(addSubHeader("The stop and graceful-stop actions"))
main.append(addImageWithCaption("images/image2.png","Apache Actions - stop and graceful-stop "))
main.append(addParagraph("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"))
main.append(addParagraph("Note that the web server on the Ubuntu machine has been set up to serve 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>.\""))
main.append(addParagraph("The command executes without providing any feedback. If we check the status again, we will see an error message"))
main.append(addInsetList(["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"]))
main.append(addParagraph("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."))
main.append(addParagraph("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."))
main.append(addParagraph("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."))
main.append(addParagraph("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."))
main.append(addImageWithCaption("images/image5.png","The error message we see when trying to access the web page served up by the Ubuntu machine when Apache is stopped."))
main.append(addParagraph("We can start the server up again on the Ubuntu machine with"))
main.append(addSyntax("sudo apachectl start"))
main.append(addParagraph("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. "))
main.append(addParagraph("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."))
main.append(addParagraph("Below, we can see a number of commands where the script is used to interact with Apache on the Ubuntu machine."))
main.append(addParagraph("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."))
main.append(addParagraph("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."))
main.append(addParagraph("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."))
main.append(addParagraph("The usage is similar to the script in /etc/init.d and provides the same output on the Ubuntu machine so"))