1. |
Apache webserver. |
|
1.1. |
Apache distributions. |
|
|
"The Number One HTTP Server On The Internet.
The Apache HTTP Server Project is an effort to develop and maintain an open-source HTTP server for modern operating systems
including UNIX and Windows. The goal of this project is to provide a secure, efficient and extensible server that provides HTTP
services in sync with the current HTTP standards.
The Apache HTTP Server ("httpd") was launched in 1995 and it has been the most popular web server on the Internet since April 1996.
It has celebrated its 20th birthday as a project in February 2015.
The Apache HTTP Server is a project of The Apache Software Foundation".
|
The paragraph above is how The Apache Software Foundation themselves describe the Apache httpd server
on their website. The Apache tutorial on my site explains how to install Apache on MS Windows. Linux users normally don't need to install Apache, as it is
included with most distributions (with some of them, you have to select Apache, when you choose the packages to install). For installation on macOS, please,
have a look at Web/Database environment on macOS: Apache webserver basics.
|
Building software packages like Apache from the source on MS Windows is mostly complicated and frustrating. And in most cases, it's
not necessary, as binaries do exist. "The Apache Software Foundation" itself does not provide Apache binaries for Windows, there are
however several Apache distributions for Windows available on the Internet. One of them is XAMPP, a complete web development environment including Apache, MariaDB, PHP and Perl, plus an FTP and a Mail server,
phpMyAdmin, Webalizer and more. I used it for several years until, on Windows 8.1, I experienced problems to run it smoothly. I then
decided to install the different components separately, what has the evident advantage to exactly install what you need and what you want.
|
I decided to use the distribution provided by Apache Lounge. It ran properly on
Windows 8 (32bit as well as 64bit), just as it does on my actual Windows 10 Pro and Home.
|
Note: The Apache webserver, that I used, when writing this tutorial, was version 2.4.32 (x64). For some
considerations, concerning the actual (January 2021) version 2.4.46 (x64), cf. Actual Apache Lounge distribution.
|
|
|
1.2. |
Installing Apache Lounge. |
|
|
Apache Lounge binaries are provided for both Windows 32bit and 64bit. These binaries have been build with Windows
Visual Studio C++, what means that the proper C++ Redistributable must be installed on your machine. I currently use Apache
2.4.32 Win 64, build with Visual Studio C++ 2017 (VC15). The link to the Microsoft site to download vc_redist_x64 may be found on
the Apache Lounge download site.
|
Installing the C++ Redistributable.
|
Double-click the VC_redist.x64.exe file, confirm to accept the license agreement and wait setup to finish. If all went well, you get a "successful" message.
Normally, the only "error" condition, you may encounter, is that the redistributable is already installed. After installation, your computer has to be restarted.
|
|
Installing Apache Lounge.
|
Installing isn't the correct word, as Apache Lounge is distributed as a .zip file, containing the entire directory structure of the
application. Unzip the archive and move the "Apache24" ("24" meaning version 2.4) folder to "some program directory". To avoid all problems, you
should not use "C:\Program Files". The default expected by Apache is "C:\", I normally use "C:\Programs". Major subdirectories of "C:\Programs\Apache24":
- bin: Apache program files
- cgi-bin: your website scripts
- conf: Apache configuration files
- htdocs: your website files
The term server root designates the Apache top-level directory, in our case "C:\Programs\Apache24"; the term document root is used to designate the top level directory of the website, in our case "C:\Programs\Apache24\htdocs".
|
|
Apache has to run as a service. Install the Apache2.4 service as follows:
- Open Command prompt (in the Windows System start-folder) as administrator (right-click it to get the admin option)
- Use the "cd" command to navigate to the Apache bin directory
- Run the httpd.exe program: httpd -k install
|
|
What is important here is that the service has been successfully installed. The error, reported at the end of the Apache output,
is due to the fact that Apache does not find its files (and because of that it will NOT be possible to start the service) because
I choose a server root different from the default expected (see above).
|
|
|
1.3. |
Basic Apache configuration. |
|
|
The main Apache configuration file is called "httpd.conf" and is located in the [Server-root]\conf directory.
Before edititing it, make sure to make a copy of the original file. Also, do not use an application like MS Word to edit configuration
files, but a pure text editor; you may use Windows Notepad or try the amazing Notepad++.
|
If you have "installed" Apache in a directory other than the default one (C:\Apache24), as I did (C:\Programs\Apache24), it is mandatory
to change all references to the server-root, document-root and cgi-bin directories in the httpd.conf file. It is
outside the scope of this document to describe the structure of this file and the meaning of the directives it includes. For all information,
have a look at the Apache manual (see below). Here the modifications, that I have to do in my httpd.conf file, due to the custom installation
directory; note the usage of the slash (/) instead of the Windows usual backslash (\)!
Change the server root (originally: "c:/Apache24"):
ServerRoot "c:/Programs/Apache24"
Change the document root (originally: "c:/Apache24/htdocs"):
DocumentRoot "c:/Programs/Apache24/htdocs"
<Directory "c:/Programs/Apache24/htdocs">
Change the cgi-bin directory (originally: "c:/Apache24/cgi-bin/"):
ScriptAlias /cgi-bin/ "c:/Programs/Apache24/cgi-bin/"
<Directory "c:/Programs/Apache24/cgi-bin">
|
There are some other directives that you may want to change, such as making Apache listen on your loopback interface only (instead on all
network interfaces), or entering a valid email address for the server administrator. Setting the server name is recommended by Apache.
Change on which interfaces Apache is listening (originally: Listen 80):
Listen 127.0.0.1:80
Change admin email address (originally: ServerAdmin admin@example.com):
ServerAdmin allu@streetinfo.lu
Set the server name (originally: -commented out-):
ServerName localhost:80
|
|
|
|
1.4. |
Running the Apache webserver. |
|
|
Apache provides a GUI application to start, restart, stop and monitor one or more Apache services. You can find this application, called
ApacheMonitor in the Apache24\bin folder. For your convenience, you should create a shortcut of the program on
your desktop; it's a good idea, to copy the shortcut to your start menu, too.
|
As Apache runs as a service, you need administrator privileges to start or stop it. To automatically run the monitor application as admin,
right-click the shortcut, choose Properties, on the Shortcut tab, click Advanced and then check the Run as administrator option.
|
The service installed, httpd.conf adapted to the chosen installation directory, it's now time to try-out the Apache webserver. Double-click
the Apache Monitor icon on your desktop; if you don't see the application (that starts in the system tray rather than in a window), use the
Show hidden icons button (up arrow) in the bottom-right area of the desktop (system tray area, containing date
and time, battery...), right-click Apache Monitor and choose Open Apache Monitor. When the GUI shows up, push the
Start button. If the server can't start, it displays an error message (and the state-indicator in the monitor remains
red instead of becoming green); the nearly always reason is that there's an error in the httpd.conf file.
|
|
Now, we can try to access the website hosted on our local Apache webserver. Running on standard port 80 on 127.0.0.1 (localhost), the address
to access it (i.e. to display the content of the index.html file located in the document-root = folder C:\Programs\Apache24\htdocs), is:
http://localhost/ (or simply localhost).
|
|
And finally re-publishing my In the street with my laptop site: Just replacing the original index.html file by my
index.html and moving all my other website files to the Apache document-root. Here its actual content and the index page displayed in Firefox browser:
|
|
|
|
1.5. |
Managing the Apache service on MS Windows. |
|
|
On Windows, you can use the Services feature of Administrative Tools, located in
Control Panel (Services can also be opened from within the ApacheMonitor GUI) to
manage the Apache service. Beside the possibility to start, restart and stop Apache, you can set the service's
properties, in particular if it should start automatically when Windows starts up or if you want to start it manually each time,
you need it. By default, the service starts automatically; the screenshot below shows how I set it to manual startup.
|
|
Services seems not to provide a possibility to uninstall the Apache2.4 service. You may do this by using the
httpd.exe program located in the Apache24\bin folder:
httpd -k uninstall
|
Note: To completely remove the Apache application from your computer, uninstall the
Apache service as described above and then simply delete the Apache24 folder. But, don't forget to save your website data before doing so: Just
make a copy of the htdocs and cgi-bin folders; keeping a copy of
the conf folder may be helpful if you reinstall your website later.
|
|
|
1.6. |
Accessing the Apache manual. |
|
|
Most Apache distributions (as does Apache Lounge) include a complete copy of the Apache httpd server manual. But normally, you can't
access it. Some modifications have to be done in the Apache configuration files first. The file httpd.conf only contains the primary
server configuration settings; secondary settings may be found in specific files, located in the
[Server-root]\conf\extra directory. The content of these files is included into the server configuration by using Include
directives. To include the configuration for the Apache manual, uncomment the following in httpd.conf:
Include conf/extra/httpd-manual.conf
If you didn't "install" Apache to its default location, you will also have to adapt references to the directory containing the manual in
the Apache24\conf\extra\httpd-manual.conf file. Modify the following directives:
AliasMatch ^/manual(?:/(?:da|de|en|es|fr|ja|ko|pt-br|ru|tr|zh-cn))?(/.*)?$ "c:/Programs/Apache24/manual$1"
<Directory "c:/Programs/Apache24/manual">
|
You may also want to do modifications concerning the preferred display language in this file; have a look at the manual for details.
Address to access the Apache manual on your local server: localhost/manual/
|
|
Note: After changing Apache configuration files, you must restart the server
to make them take effect!
|
|
|
1.7. |
Advanced Apache configuration. |
|
|
Creating virtual hosts.
|
To do...
|
Installing HTTPS.
|
The simplest way to install HTTPS on a local Apache server on Windows is to install OpenSSL, and to create a
self-signed certificate, then configure Apache to use this certificate for secure HTTPS access. For details, please, have a look at
my tutorial Secure web server access using HTTPS.
|
Creating password protected realms.
|
To do...
|
URL and HTTPS redirection.
|
To do...
|
|
|
1.8. |
My Apache installation application. |
|
|
Not yet available, even not yet started to write it, just planed to do it some day: A Lazarus/Free Pascal GUI application, that
gives the user the possibility to do all the Apache installation and configuration steps, described on this page, with the minimal
effort of some mouse clicks...
|
|
|
1.9. |
Actual Apache Lounge distribution. |
|
|
The actual (January 2021) version is Apache Lounge 2.4.46. It is build with Visual Studio C++ 2019 (VS16).
You may download vc_redist_x64 from the Microsoft site, directly or using the link on the Apache Lounge download site.
|
Configuration:
If you changed the Apache default installation directory, you have to modify the definition of the server root variable; in my case
(originally: "c:/Apache24"):
Define SRVROOT "c:/Programs/Apache24"
Doing this, ServerRoot, DocumentRoot and ScriptAlias will have the correct values, without that you have to make any further changes.
|
Apache manual:
The Apache manual is NOT included with the actual Apache Lounge distribution. I searched the Internet to find an offline version download
of the manual. The most recent one, that I found, was for Apache 2.4.33. Here, the download link on the Apache Software Foundation website. Trying to access the manual results in an internal server error. No idea, why. I found a simple way to make the manual correctly accessible: Just comment out
the following lines in the httpd-manual.conf file (the directory settings don't need to be changed as described
above, as here, too, the variable SRVROOT is used):
#<Files *.html>
#SetHandler type-map
#</Files>
|
|