Welcome

Basic Apache Installation and Testing

We will start with a very simple installation of the “Apache Web Server” 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 “apt install apache2”. How did we know to type this magic command? Use the “search” feature to look for packages involving apache. The command “apt search apache” produces a list of nearly 100 packages but luckily the server (apache2) appeared very early in the result list:

Shell

Is it already Installed?

If you have just acquired a server and want to know if the previous administrator already installed apache using the “–installed” option along with list.

Here is a machine without apache installed:

Shell

Here is a machine with apache already installed (look for the word “installed”! The listing by the way also reveals the version of the Ubuntu release. In the example below, this is “xenial” (Ubuntu 16.04).

Shell

Standard Installation

Normally when you run the “apt install apache2”, 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.

On the server the most important locations are:

  • /etc/apache2 – the configuration files for the apache server
  • /var/www – the location of the HTML files
  • /var/log/apache2 – location of the log files for apache

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).

Configuration File Structure

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.

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).

Default Site

When the apache web server is installed on Ubuntu, it creates a “default site” whose HTML files are located in the /var/www/html folder.

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’t match the request). I recommend modifying the index.html file in your “default” 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’t actually ask for!

Troubleshooting Apache

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 “apache not working” is not very likely to help you figure out what is wrong.

Step 1 – Is the Service Running

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.

Using “systemctl” check the status of the apache web server by typing the command “systemctl status apache2” which will check to see if the service is actually running.

Shell

The phrase you are looking for is “active (running)”. Here is what things look like if you have not even installed the apache2 package:

Shell

You can also check the process list to see if the apache2 binary is currently running. This usually isn’t necessary but it is one more thing that you can check.

Shell

Step 2 – Is Apache Listening on the Correct Port?

If you have been messing around with configuring apache to run on non-standard ports then you can use the “ss” to find out if there is something running on the port. Normally HTTP runs on port 80 so a listing using “ss -nat” will provide you with a list of all TCP ports currently being listened to.

Shell

The thing that I am looking for here is the “:80” that indicates that all interfaces are being monitored for connections on port 80.

Leave a Reply

Your email address will not be published. Required fields are marked *