Apache HTTP Server, commonly referred to as Apache, is a popular web server application. It is notably having a key role in initial growth of World Wide Web. Originally based on the NCSA HTTPd server, development of Apache began in early 1995 after work on the NCSA code stalled. Apache quickly overtook NCSA HTTPd as the dominant HTTP server, and has remained the most popular HTTP server in use since April 1996.
In this article we will bring ourselves to build Apache HTTP Server for Windows. Some material used here are:
- Windows 8, 64-bit
- Apache HTTPD 2.4.7 (latest per November 28th, 2013)
- Windows 8 Platform SDK, February 2003 or later
- Microsoft Visual Studio 2010
- Perl 5.16.3
- nasm 2.11.rc1
Also for material building the Apache
- apr, apr-util, apr-iconv
- PCRE (Perl Compatible Regular Expressions)
- zlib library (optional)
- OpenSSL libraries (optional)
You should also provide free disk space at least 200MB when compiling. After installation, Apache needs approximately 80 MB of disk space.
In this article, we will use Visual Studio Command Prompt instead of common Command Prompt.
Instead of compiling to x64 code, we will target the x86 architecture.
Opening Visual Studio Command Prompt
As stated before, we use Visual Studio Command Prompt instead of common Command Prompt. I use Visual Studio 2010 (Visual Studio 10) on Windows 8 64-bit. To activate Visual Studio Command Prompt, there are two methods: search & run Visual Studio Command Prompt from Start Screen, run Command Prompt then execute script to set environment variable.
If you want to use first method, make sure you use Visual Studio Command Prompt for amd64 or 64-bit instead of 32-bit.
If you want to do second method, you can do:
"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" amd64
Here we execute vcvarsall.bat and set the argument to amd64 to obtain necessary environment variables for the toolchain basically.
Grab the Materials
Source code of Apache HTTPD can be downloaded freely from here. Choose the closest mirror for you.
There are two Perl implementation for Windows: Strawberry Perl and ActiveState perl. I leave you to choose which one. Both can be downloaded from here.
Windows Software Developer Kit (SDK) for Windows 8 can be downloaded freely from here. Download the sdksetup.exe then run it. Choose Windows SDK from options available.
AWK is standard feature of most Unix-like operating system. For Windows, there is an alternative: Brian Kernighan’s http://www.cs.princeton.edu/~bwk/btl.mirror/ site has a compiled native Win32 binary, http://www.cs.princeton.edu/~bwk/btl.mirror/awk95.exe which you must save with the name
awk.exe (rather than
awk95.exe). It should be installed in environment path or known by Visual Studio.
NASM or Netwide Assembler is the assembler targeting x86 family processor. We can download nasm from it’s official site. The latest (version 2.11rc1 per November 28th, 2013) can be downloaded here. The one I use here is nasm-2.11rc1-installer.exe. Make sure nasm can be executed (the path is in the environment path).
APR (Apache Project Runtime) is used for building Apache. The project is a separated project from Apache HTTPD therefore we need to download it manually. Download it here http://apr.apache.org/download.cgi, select the appropriate mirror for you. The three we should download are: apr 1.5, apr-util 1.5.3, apr-iconv 1.2.1. Download the win32 version source code.
Perl Compatible Regular Expressions is regular expression pattern matching using the same syntax and semantics as Perl 5. It can be downloaded from www.pcre.org. The latest version is 8.33 which can be downloaded from ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/.
The zlib library is optional, used for mod_deflate. The current version is 1.2.8 and can be download from http://www.zlib.net/. In this case, the filename is zlib-1.2.8.tar.xz.
OpenSSL libraries is optional, used for mod_ssl and ab.exe with ssl support. You can obtain the OpenSSL for Windows from http://www.openssl.org/source/. Assuming we have downloaded it. In this case, the file name is openssl-1.0.1e.tar.gz.
In this article, I assume awk is installed as C:\Windows\awk.exe which should on the environment path.
Extract the Apache source code. Once it’s extracted we have “httpd-2.4.7” directory (for example: D:\httpd-2.4.7).
Extract the apr package to Apache’s srclib and rename them to apr, apr-iconv, apr-util respectively. Therefore we have three subdirectories apr, apr-iconv, and apr-util inside of “httpd-2.4.7/srclib”.
Extract the PCRE package to Apache’s srclib and rename it to pcre. Therefore we have “httpd-2.4.7/srclib/pcre”.
If you want to include zlib support, extract zlib source code inside Apache’s srclib sub directory and rename the directory to zlib. Therefore, we have “httpd-2.4.7/srclib/zlib”.
If you want to include openssl support, extract openssl source code inside Apache’s srclib sub directory and rename the directory to openssl. Therefore, we have “httpd-2.4.7/srclib/openssl”.
The makefile script for Windows is defined as Makefile.win. In this article, we will build all the optional package first, manually.
To compile & build zlib, enter the Apache’s srclib for zlib and invoke the Makefile. Assuming Apache source code is in D:\httpd-2.4.7
cd D:\httpd-2.4.7\srclib\zlib nmake -f win32\Makefile.msc AS=ml64 LOC="-DASMV -DASMINF -I." OBJA="inffasx64.obj gvmat64.obj inffas8664.obj" nmake -f win32\Makefile.msc test copy zlib.lib zlib1.lib
The last command is used to copy zlib.lib as zlib1.lib. We do this because when we compile OpenSSL we need library with this name.
To compile & build openssl, enter the Apache’s srclib for zlib and invoke the Makefile. Assuming Apache source code is in D:\httpd-2.4.7. To prepareOpenSSL to be linked to Apache mod_ssl or the abs.exe project, we can use following commands:
cd D:\httpd-2.4.7\srclib\openssl perl Configure disable-idea enable-camellia enable-mdc2 enable-zlib VC-WIN64A -ID:\httpd-2.4.7\srclib\zlib -LD:\httpd-2.4.7\srclib\zlib ms\do_win64a.bat nmake -f ms\ntdll.mak
The above command configures OpenSSL with Visual C++ Win64 AMD. We disable the IDEA algorithm since this is by default disabled in the pre-distributions and really shouldn’t be missed. If you do however require this then go ahead and remove disable-idea.
Because we use OpenSSL 1.0.1e, we should invoke following command:
echo. > inc32\openssl\store.h
Now go to the top level directory of our Apache HTTPD source code. We will invoke the makefile to build Apache HTTPD.
nmake /f Makefile.win installr
Finally compile and install HTTPd, you can specify INSTDIR= to specify a path of where to install HTTPd as well. You can also specify database bindings by adding DBD_LIST=”mysql sqlite” etc. Also as it points out, don’t forget to add the libraries and includes from the databases to the INCLUDE and LIBweb, windows