{"id":34,"date":"2020-07-20T06:23:03","date_gmt":"2020-07-20T06:23:03","guid":{"rendered":"https:\/\/iste.umldb.com\/web-server-management\/?p=34"},"modified":"2020-07-20T06:27:24","modified_gmt":"2020-07-20T06:27:24","slug":"basic-apache-installation-and-testing","status":"publish","type":"post","link":"https:\/\/iste.umldb.com\/web-server-management\/2020\/07\/20\/basic-apache-installation-and-testing\/","title":{"rendered":"Basic Apache Installation and Testing"},"content":{"rendered":"\n<p>We will start with a very simple installation of the &#8220;Apache Web Server&#8221; and show you the various locations where things are kept.<\/p>\n\n\n\n<figure class=\"wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Updating Ubuntu 20.04 Server\" width=\"960\" height=\"720\" src=\"https:\/\/www.youtube.com\/embed\/nQjy35r_Ev4?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>The simplest way to get apache installed on an Ubuntu server is to use the command &#8220;apt install apache2&#8221;.   How did we know to type this magic command?    Use the &#8220;search&#8221; feature to look for packages involving apache.   The command &#8220;apt search apache&#8221; produces a list of nearly 100 packages but luckily the server (apache2) appeared very early in the result list:<\/p>\n\n\n<div class=\"wp-block-advanced-gutenberg-blocks-code\">\n  <header class=\"wp-block-advanced-gutenberg-blocks-code__header\">\n    <div class=\"wp-block-advanced-gutenberg-blocks-code__lang is-lang-shell\">\n      Shell    <\/div>\n    <div class=\"wp-block-advanced-gutenberg-blocks-code__file\">\n          <\/div>\n  <\/header>\n  <textarea \n    class=\"wp-block-advanced-gutenberg-blocks-code__source\" \n    name=\"codemirror-1519813073\" \n    id=\"codemirror-1519813073\"\n  >robert@wsmdemo:~$ apt search apache\nSorting... Done\nFull Text Search... Done\napache2\/focal 2.4.41-4ubuntu3 amd64\n  Apache HTTP Server\n\napache2-bin\/focal 2.4.41-4ubuntu3 amd64\n  Apache HTTP Server (modules and other binary files)\n\napache2-data\/focal 2.4.41-4ubuntu3 all\n  Apache HTTP Server (common files)\n\napache2-dev\/focal 2.4.41-4ubuntu3 amd64\n  Apache HTTP Server (development headers)<\/textarea>\n  <script>\n    CodeMirror.fromTextArea( document.getElementById('codemirror-1519813073'), {\n      mode: 'shell',\n      readOnly: true,\n      theme: 'hopscotch', \n      lineNumbers: false,\n      firstLineNumber: 1,\n      matchBrackets: true,\n      indentUnit: 4,\n      tabSize: 4,\n      lineWrapping: true,\n    } ); \n  <\/script>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Is it already Installed?<\/h2>\n\n\n\n<p>If you have just acquired a server and want to know if the previous administrator already installed apache using the &#8220;&#8211;installed&#8221; option along with list.<\/p>\n\n\n\n<p>Here is a machine without apache installed:<\/p>\n\n\n<div class=\"wp-block-advanced-gutenberg-blocks-code\">\n  <header class=\"wp-block-advanced-gutenberg-blocks-code__header\">\n    <div class=\"wp-block-advanced-gutenberg-blocks-code__lang is-lang-shell\">\n      Shell    <\/div>\n    <div class=\"wp-block-advanced-gutenberg-blocks-code__file\">\n          <\/div>\n  <\/header>\n  <textarea \n    class=\"wp-block-advanced-gutenberg-blocks-code__source\" \n    name=\"codemirror-658367318\" \n    id=\"codemirror-658367318\"\n  >robert@wsmdemo:~$ apt --installed list apache2\nListing... Done<\/textarea>\n  <script>\n    CodeMirror.fromTextArea( document.getElementById('codemirror-658367318'), {\n      mode: 'shell',\n      readOnly: true,\n      theme: 'hopscotch', \n      lineNumbers: false,\n      firstLineNumber: 1,\n      matchBrackets: true,\n      indentUnit: 4,\n      tabSize: 4,\n      lineWrapping: false,\n    } ); \n  <\/script>\n<\/div>\n\n\n\n<p>Here is a machine with apache already installed (look for the word &#8220;installed&#8221;!  The listing by the way also reveals the version of the Ubuntu release. In the example below, this is &#8220;xenial&#8221; (Ubuntu 16.04).<\/p>\n\n\n<div class=\"wp-block-advanced-gutenberg-blocks-code\">\n  <header class=\"wp-block-advanced-gutenberg-blocks-code__header\">\n    <div class=\"wp-block-advanced-gutenberg-blocks-code__lang is-lang-shell\">\n      Shell    <\/div>\n    <div class=\"wp-block-advanced-gutenberg-blocks-code__file\">\n          <\/div>\n  <\/header>\n  <textarea \n    class=\"wp-block-advanced-gutenberg-blocks-code__source\" \n    name=\"codemirror-2003037106\" \n    id=\"codemirror-2003037106\"\n  >robert@gate:~$ apt --installed list apache2\nListing... Done\napache2\/xenial-updates,now 2.4.18-2ubuntu3.15 amd64 [installed]\nN: There are 2 additional versions. Please use the &#039;-a&#039; switch to see them.<\/textarea>\n  <script>\n    CodeMirror.fromTextArea( document.getElementById('codemirror-2003037106'), {\n      mode: 'shell',\n      readOnly: true,\n      theme: 'hopscotch', \n      lineNumbers: false,\n      firstLineNumber: 1,\n      matchBrackets: true,\n      indentUnit: 4,\n      tabSize: 4,\n      lineWrapping: false,\n    } ); \n  <\/script>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Standard Installation<\/h2>\n\n\n\n<p>Normally when you run the &#8220;apt install apache2&#8221;, everything will be working fine and you will be able to visit the server using your web browser and IP address and you should see the initial Ubuntu welcome page.<\/p>\n\n\n\n<p>On the server the most important locations are:<\/p>\n\n\n\n<ul><li><code>\/etc\/apache2<\/code> &#8211; the configuration files for the apache server<\/li><li><code>\/var\/www<\/code> &#8211; the location of the HTML files<\/li><li><code>\/var\/log\/apache2<\/code> &#8211; location of the log files for apache<\/li><\/ul>\n\n\n\n<p>Changing the location of the configuration files and log files is possible but not recommended.  Changing of the location of the HTML files is reasonable but I would only recommend it if is necessary.  Keeping things in *expected* places will help with maintenance of the server.  The only times that I have modified the HTML location is because some web apps install themselves in specific locations or you needed to put the HTML files into a folder that was mounted in a specific location (but there are usually other ways to still fix this).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Configuration File Structure<\/h2>\n\n\n\n<p>If you search around the internet you may find reference to the file \/etc\/apache2\/apache2.conf and suggestions to put changes into this file for things like redirects, enabling ssl, etc.  <\/p>\n\n\n\n<p>While you can make changes to this file for certain overall behavior, you would be much better of never modifying this file but instead making changes to the site-available, mods-available, and conf-available folders instead (this will be explained in other pages of this website).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Default Site<\/h2>\n\n\n\n<p>When the apache web server is installed on Ubuntu, it creates a &#8220;default site&#8221; whose HTML files are located in the \/var\/www\/html folder.<\/p>\n\n\n\n<p>The default site is the site that gets served up if no other sites are enabled (or the enabled sites are mis-configured and didn&#8217;t match the request).  I recommend modifying the index.html file in your &#8220;default&#8221; site to contain some message letting you know that this is the default site and then leaving it switched on all the time.  If you do end up with a misconfiguration in the other sites, this message will make more sense than just getting served some strange webpage from your server that you didn&#8217;t actually ask for!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Troubleshooting Apache<\/h2>\n\n\n\n<p>Did you visit your IP address with a browser and nothing came back? Unfortunately it could be one of several problems.  When troubleshooting, I usually run 2 commands to help understand the problem.  Just randomly trying to change things or googling some generic &#8220;apache not working&#8221; is not very likely to help you figure out what is wrong.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1 &#8211; Is the Service Running<\/h3>\n\n\n\n<p>The apache service is the program that listens to the network port and serves up pages. If this program is not working then there is no way that you will be able to see pages on the browser.  <\/p>\n\n\n\n<p>Using &#8220;systemctl&#8221; check the status of the apache web server by typing the command &#8220;systemctl status apache2&#8221; which will check to see if the service is actually running.<\/p>\n\n\n<div class=\"wp-block-advanced-gutenberg-blocks-code\">\n  <header class=\"wp-block-advanced-gutenberg-blocks-code__header\">\n    <div class=\"wp-block-advanced-gutenberg-blocks-code__lang is-lang-shell\">\n      Shell    <\/div>\n    <div class=\"wp-block-advanced-gutenberg-blocks-code__file\">\n          <\/div>\n  <\/header>\n  <textarea \n    class=\"wp-block-advanced-gutenberg-blocks-code__source\" \n    name=\"codemirror-1755188505\" \n    id=\"codemirror-1755188505\"\n  >robert@monitor:~$ systemctl status apache2\n\u25cf apache2.service - The Apache HTTP Server\n   Loaded: loaded (\/lib\/systemd\/system\/apache2.service; enabled; vendor preset: \n  Drop-In: \/lib\/systemd\/system\/apache2.service.d\n           \u2514\u2500apache2-systemd.conf\n   Active: active (running) since Fri 2020-07-17 10:48:16 +03; 2 days ago\n  Process: 18897 ExecReload=\/usr\/sbin\/apachectl graceful (code=exited, status=0\/\n  Process: 1660 ExecStart=\/usr\/sbin\/apachectl start (code=exited, status=0\/SUCCE\n Main PID: 1955 (apache2)\n    Tasks: 10 (limit: 1592)\n   CGroup: \/system.slice\/apache2.service\n           \u251c\u2500 1955 \/usr\/sbin\/apache2 -k start\n           \u251c\u250012860 \/usr\/sbin\/apache2 -k start\n           \u251c\u250012913 \/usr\/sbin\/apache2 -k start\n           \u251c\u250012914 \/usr\/sbin\/apache2 -k start\n           \u251c\u250012915 \/usr\/sbin\/apache2 -k start\n           \u251c\u250018922 \/usr\/sbin\/apache2 -k start\n           \u251c\u250018923 \/usr\/sbin\/apache2 -k start\n           \u251c\u250018924 \/usr\/sbin\/apache2 -k start\n           \u251c\u250018925 \/usr\/sbin\/apache2 -k start\n           \u2514\u250018926 \/usr\/sbin\/apache2 -k start\n<\/textarea>\n  <script>\n    CodeMirror.fromTextArea( document.getElementById('codemirror-1755188505'), {\n      mode: 'shell',\n      readOnly: true,\n      theme: 'hopscotch', \n      lineNumbers: false,\n      firstLineNumber: 1,\n      matchBrackets: true,\n      indentUnit: 4,\n      tabSize: 4,\n      lineWrapping: true,\n    } ); \n  <\/script>\n<\/div>\n\n\n\n<p>The phrase you are looking for is &#8220;active (running)&#8221;.  Here is what things look like if you have not even installed the apache2 package:<\/p>\n\n\n<div class=\"wp-block-advanced-gutenberg-blocks-code\">\n  <header class=\"wp-block-advanced-gutenberg-blocks-code__header\">\n    <div class=\"wp-block-advanced-gutenberg-blocks-code__lang is-lang-shell\">\n      Shell    <\/div>\n    <div class=\"wp-block-advanced-gutenberg-blocks-code__file\">\n          <\/div>\n  <\/header>\n  <textarea \n    class=\"wp-block-advanced-gutenberg-blocks-code__source\" \n    name=\"codemirror-346604322\" \n    id=\"codemirror-346604322\"\n  >robert@wsmdemo:~$ systemctl status apache2\nUnit apache2.service could not be found.<\/textarea>\n  <script>\n    CodeMirror.fromTextArea( document.getElementById('codemirror-346604322'), {\n      mode: 'shell',\n      readOnly: true,\n      theme: 'hopscotch', \n      lineNumbers: false,\n      firstLineNumber: 1,\n      matchBrackets: true,\n      indentUnit: 4,\n      tabSize: 4,\n      lineWrapping: true,\n    } ); \n  <\/script>\n<\/div>\n\n\n\n<p>You can also check the process list to see if the apache2 binary is currently running.  This usually isn&#8217;t necessary but it is one more thing that you can check.<\/p>\n\n\n<div class=\"wp-block-advanced-gutenberg-blocks-code\">\n  <header class=\"wp-block-advanced-gutenberg-blocks-code__header\">\n    <div class=\"wp-block-advanced-gutenberg-blocks-code__lang is-lang-shell\">\n      Shell    <\/div>\n    <div class=\"wp-block-advanced-gutenberg-blocks-code__file\">\n          <\/div>\n  <\/header>\n  <textarea \n    class=\"wp-block-advanced-gutenberg-blocks-code__source\" \n    name=\"codemirror-1929349551\" \n    id=\"codemirror-1929349551\"\n  >robert@monitor:~$ ps -aux | grep apache2\nroot      1955  0.0  1.4 500780 28636 ?        Ss   Jul17   0:04 \/usr\/sbin\/apache2 -k start\nwww-data  2030  0.0  0.0  19904   176 ?        Ss   Jul17   0:02 \/usr\/bin\/htcacheclean -d 120 -p \/var\/cache\/apache2\/mod_cache_disk -l 300M -n\nwww-data 12860  0.0  1.8 506096 36964 ?        S    11:12   0:00 \/usr\/sbin\/apache2 -k start\nwww-data 12913  0.0  0.7 503108 15828 ?        S    11:12   0:00 \/usr\/sbin\/apache2 -k start\nwww-data 12914  0.0  0.7 503108 15828 ?        S    11:12   0:00 \/usr\/sbin\/apache2 -k start\nwww-data 12915  0.0  0.7 503108 15828 ?        S    11:12   0:00 \/usr\/sbin\/apache2 -k start\nrobert   16541  0.0  0.0  14428  1112 pts\/1    S+   11:53   0:00 grep --color=auto apache2\nwww-data 18922  0.0  2.5 514552 51452 ?        S    06:25   0:00 \/usr\/sbin\/apache2 -k start\nwww-data 18923  0.0  2.5 510456 50044 ?        S    06:25   0:00 \/usr\/sbin\/apache2 -k start\nwww-data 18924  0.0  2.3 508368 46788 ?        S    06:25   0:00 \/usr\/sbin\/apache2 -k start\nwww-data 18925  0.0  2.1 506240 42672 ?        S    06:25   0:00 \/usr\/sbin\/apache2 -k start\nwww-data 18926  0.0  2.3 510336 46068 ?        S    06:25   0:00 \/usr\/sbin\/apache2 -k start<\/textarea>\n  <script>\n    CodeMirror.fromTextArea( document.getElementById('codemirror-1929349551'), {\n      mode: 'shell',\n      readOnly: true,\n      theme: 'hopscotch', \n      lineNumbers: false,\n      firstLineNumber: 1,\n      matchBrackets: true,\n      indentUnit: 4,\n      tabSize: 4,\n      lineWrapping: false,\n    } ); \n  <\/script>\n<\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2 &#8211; Is Apache Listening on the Correct Port?<\/h3>\n\n\n\n<p>If you have been messing around with configuring apache to run on non-standard ports then you can use the &#8220;ss&#8221; to find out if there is something running on the port.  Normally HTTP runs on port 80 so a listing using &#8220;ss -nat&#8221; will provide you with a list of all TCP ports currently being listened to.<\/p>\n\n\n<div class=\"wp-block-advanced-gutenberg-blocks-code\">\n  <header class=\"wp-block-advanced-gutenberg-blocks-code__header\">\n    <div class=\"wp-block-advanced-gutenberg-blocks-code__lang is-lang-shell\">\n      Shell    <\/div>\n    <div class=\"wp-block-advanced-gutenberg-blocks-code__file\">\n          <\/div>\n  <\/header>\n  <textarea \n    class=\"wp-block-advanced-gutenberg-blocks-code__source\" \n    name=\"codemirror-859766392\" \n    id=\"codemirror-859766392\"\n  >root@wsmdemo:~# ss -nat\nState           Recv-Q          Send-Q                   Local Address:Port                     Peer Address:Port          Process         \nLISTEN          0               4096                     127.0.0.53%lo:53                            0.0.0.0:*                             \nLISTEN          0               128                            0.0.0.0:22                            0.0.0.0:*                             \nESTAB           0               0                        192.168.68.12:22                     192.168.68.103:59490                         \nLISTEN          0               511                                  *:80                                  *:*                             \nLISTEN          0               128                               [::]:22                               [::]:*      <\/textarea>\n  <script>\n    CodeMirror.fromTextArea( document.getElementById('codemirror-859766392'), {\n      mode: 'shell',\n      readOnly: true,\n      theme: 'hopscotch', \n      lineNumbers: false,\n      firstLineNumber: 1,\n      matchBrackets: true,\n      indentUnit: 4,\n      tabSize: 4,\n      lineWrapping: false,\n    } ); \n  <\/script>\n<\/div>\n\n\n\n<p>The thing that I am looking for here is the &#8220;:80&#8221; that indicates that all interfaces are being monitored for connections on port 80.  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>We will start with a very simple installation of the &#8220;Apache Web Server&#8221; and show you the various locations where things are kept. The simplest way to get apache installed on an Ubuntu server is to use the command &#8220;apt install apache2&#8221;. How did we know to type this magic command? Use the &#8220;search&#8221; feature [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/iste.umldb.com\/web-server-management\/wp-json\/wp\/v2\/posts\/34"}],"collection":[{"href":"https:\/\/iste.umldb.com\/web-server-management\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/iste.umldb.com\/web-server-management\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/iste.umldb.com\/web-server-management\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/iste.umldb.com\/web-server-management\/wp-json\/wp\/v2\/comments?post=34"}],"version-history":[{"count":0,"href":"https:\/\/iste.umldb.com\/web-server-management\/wp-json\/wp\/v2\/posts\/34\/revisions"}],"wp:attachment":[{"href":"https:\/\/iste.umldb.com\/web-server-management\/wp-json\/wp\/v2\/media?parent=34"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/iste.umldb.com\/web-server-management\/wp-json\/wp\/v2\/categories?post=34"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/iste.umldb.com\/web-server-management\/wp-json\/wp\/v2\/tags?post=34"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}