Part 2 – Installing and Running Apache

September 25, 2024

!Series: Local Environment Apache

In this section, we will be installing Apache as our HTTP server.

Getting the Apache Download

Let’s start at the official Apache site and look at the information for Windows users.

Before we start the download, let’s look at the site a little bit. We can see that Apache 2.4 requires Windows 2000 or later—which I certainly hope won’t be a problem. It also shows us that the Apache project does not provide its own binary releases. (A binary release is a ready to install file, like an EXE.) However, it does link to some external projects that do, and we will be downloading from one of them shortly.

There’s also some information about customizing Apache for Windows, and a link to the directive index that tells us what keywords we can use to do that customization. Finally, there is some information on how to run and test Apache, which we will come back to later. For now, we want to download the version of Apache HTTP Server available through Apache Lounge, available at this link.

Apache Lounge has some additional information about its binary. It requires Windows 7 or newer to run and you need to have Visual C++ Redistributable Visual Studio 2015 to 2022 installed. In order to check whether you already have this installed, go to Add or Remove Programs / Installed Apps to see whether it is on the list of installed programs.

Screenshot of Installed apps

Installed apps with Visual C++ not installed

If you don’t have Visual C++ installed, use the link on Apache Lounge to download the correct version. For me, that’s the version marked vc_redist_x64, since I have a 64-bit version of Windows. Run the downloaded EXE. (You will need to grant administrator permissions.)

Screenshot of Apache Lounge site

Link to Visual C++ download on Apache Lounge site

Now we need to download the Apache binary file. Download the most recent binary for 64-bit Windows. Your version number and date will probably be different from the one you see in my screenshot. However, you should be aware that this tutorial covers installing Apache 2.4. If the latest version is something different (such as 2.6), is possible that some things in this tutorial may not work anymore.

Screenshot of Apache Lounge site

Link to Apache download on Apache Lounge site

Extract the folder. We will install in a moment, but before we do, we should look at the ReadMe file to get more information.

ReadMe Information

The ReadMe file is quite clear and well written, and I encourage you to read over it yourself. However, there are two key points:

  1. First, the ReadMe tells us that this binary expects the Apache 24 folder to be directly in the C Drive. If we put it somewhere else, we need to specify where it’s saved in the configuration file.
  2. Second, the ReadMe tells us what commands we will need to use in order to install and run Apache.

We could install Apache directly in the C Drive as the ReadMe file suggests. However, since we are going to have quite a few different tools installed by the end of this, I am going to put everything in its own folder called Development. I am going to move the Apache 24 file into this folder. This means that the path to my Apache 24 folder will be C:\Development\Apache24.

Setting the Initial Configuration

We will need to specify that location in our Apache configuration file. The Apache configuration file is the main configuration file that controls how Apache is installed and run. The file is named httpd.conf and it’s located in the conf folder. Let’s open that in a code editor.

We’ll be looking at the configuration file in more detail later. For now, the ReadMe file specified that if we put the Apache 24 folder in a different location, we needed to change the definition of SRVROOT. That’s near the top of the document. We need to change that to our path, which for me is C:/Development/Apache24. (Note that we must use forward-slashes, not backslashes, and we shouldn’t have a slash at the end.

Screenshot of Apache configuration file

Edited settings for httpd.conf

Save the file and close it.

Installing Apache as a Service

In order to install Apache, we will need to launch Command Prompt as an administrator. We can search for command prompt by typing CMD and we can choose the “Run as administrator” option on the right.

Screenshot of Windows start menu

Running Command Prompt as administrator

We need to move within command prompt to the bin folder within the Apache 24 folder. You can change directories with the CD command. Because I put the Apache 24 folder directly in the C Drive, I would use this command:

cd C:\Development\Apache24\bin

Before we install Apache, let’s look at all the options. We can request all the options with the command:

httpd -h

Screenshot of command prompt

Partial httpd help info

Most of these are beyond what we want to mess with, but there’s a couple of things that are handy. We can see what we’re going to use to install the service, and how we could start, restart, stop, and uninstall. For now, let’s go ahead and install the service with this command:

httpd -k install

You should get a message that says the service was installed, but it will likely say that it can’t “reliably determine the server’s fully qualified domain name”. We’ll come back to that in a while. For now, let’s try starting it and see if it runs.

Screenshot of command prompt

Successful installation with error message

There are three ways to run the Apache service. The first one is from the command line, which is what I tend to do. From the Apache bin directory (the same place where we went to run the installation), you can launch the service with the command:

httpd -k start

You’ll probably see the error about the fully qualified domain name again, but that’s okay. Let’s make sure it started. Open a browser tab and go to http://localhost/, then press enter. You should see “It works!” on the screen.

As a side note, if I simply type in localhost, every so often my browser will try to open localhost as HTTPS, which won’t work by default. If you don’t see the “It works” message, adding the http explicitly (e.g. typing http://localhost) and see if that works.

Now we know we install Apache correctly, let’s see the other ways to launch the service. Go back to the command prompt and stop the service with the command:

httpd -k stop

You should get a couple of messages, one that says the services stopping, and then after a second or two, that the service has stopped.

Options for Running Apache

Now, let’s look at the other ways to launch the Apache service. First, we can launch it from the Windows services, which you can reach by typing “services” into the search bar. Click on Apache 2.4 in the list of services, and then click the start link on the left. Once the service has started, you will have the option to stop or restart the service instead. Let’s stop the service now and see the last way to start or stop the service.

Screenshot of Services panel

Apache service on the services screen

In the bin folder, there’s a program called Apache Monitor. Double-click on it to launch it. Once it has been launched, you may need to also right-click on its icon in the system tray to open the graphical user interface. You can click on the start button to launch services; you will need to give administrator permissions. Once started, Apache Monitor will remain in the system tray and can be used to start, stop, or restart services as needed.

Screenshot from File Explorer

Apache Monitor in /bin folder

Out of all the options, I prefer to use the Command Prompt because it shows any errors and warnings right where you start the service. For the rest of the tutorials, I will be using the Command Prompt option.

Conclusion

That’s it for this section! In the next section, we’ll be configuring Apache to serve two simple local websites.

Posted In: Tutorials