This blogpost covers compiling & debugging Apache. It is not suggesting to replace the existing documentation, but rather give a practical examples and other useful tips if you’re interested in starting a small lab for analysis/research purposes.
Download
You can use git, svn, or just use one of the Apache httpd mirror sites: http://archive.apache.org/dist/httpd/
APR Utils
Before starting the building process, you’ll need APR (Apache Portable Runtime)
https://publib.boulder.ibm.com/httpserv/manual24/install.html
Make sure you have APR and APR-Util already installed on your system. If you don’t, or prefer to not use the system-provided versions, download the latest versions of both APR and APR-Util from Apache APR, unpack them into /httpd_source_tree_root/srclib/apr and /httpd_source_tree_root/srclib/apr-util (be sure the directory names do not have version numbers; for example, the APR distribution must be under /httpd_source_tree_root/srclib/apr/) and use ./configure’s —with-included-apr option. On some platforms, you may have to install the corresponding -dev packages to allow httpd to build against your installed copy of APR and APR-Util
You can get APR and APR-Utils from here: https://apr.apache.org/download.cgi
Compiling
If you want to start a build with debug symbols / common modules, use the following options when running ./configure
:
./configure --enable-maintainer-mode \
--enable-debugger-mode \
--with-mpm=prefork
We’re use the prefork
MPM since this MPM uses multiple child processes with one thread each and each process handles one connection at a time. This will be useful for debugging as we’ll see soon.
After the configure
command is done, just compile it with make
& go grab a coffee because that’s gonna take awhile.
Debugging
By its nature, Apache spawns new processes when incoming requests arrives. This can be very painful to do analysis/debug stuff because every time a new process starts, the debugger will switch contexts & your breakpoints might not hit. To overcome that, run the httpd
binary with an -X
argument:
-X : debug mode (only one worker, do not detach)
You can also add to the httpd.conf
the following line, to ensure Apache will proccess just one request at a time:
MaxClients 1
Other Useful Reading
- Compiling: https://httpd.apache.org/docs/2.4/install.html#compile
- More options to
configure
: https://httpd.apache.org/docs/2.4/programs/configure.html - Type of MPMs: https://www.datadoghq.com/blog/monitoring-apache-web-server-performance/#mpms-for-unix-like-systems
- Apache docs about debugging: https://httpd.apache.org/dev/debugging.html
- The Apache Modules Book: https://www.amazon.com/Apache-Modules-Book-Application-Development/dp/B01N8Y05IL