Background

Sometimes insane problems lead to insane measures. This is one of those times. I have a problem to solve and one step in the process appears to be recompiling Apache HTTPD2 (aka apache2) for Debian 9 with the --enable-exception-hook configure argument.

If you need to recompile a Debian package, this seven step guide might help you out.

Overview

In order to recompile Debian’s apache2 package we need to obtain the source code, install the build dependencies, make our change, build the apache2 package and then install it.

Breakdown

Prerequisites

We need the fakeroot package so that we can run dpkg-buildpackage as a non-root user:

sudo apt install -y fakeroot

We also need to satisfy some Apache2 dependencies:

sudo apt install -y libaprutil1-dbd-sqlite3 libaprutil1-ldap

Process

Step 1

Create a directory, something like ~/httpd2 and change into that directory

Step 2

Install the Debian apache2 build dependencies with:

sudo apt build-dep apache2

Step 3

Obtain the Debian apache2 source:

apt source apache2

Step 4

Change to the ~/httpd2/apache2-2.4.25 directory (version number will vary). Open the ‘debian/rules’ file in your editor of choice, e.g. vi debian/rules. Within the open file, find the string override_dh_auto_configure.

Step 5

On the lines that follow, you will see one command which is running ./configure with a set of parameters. Within that block, we add the line:

--enable-exception-hook \

Save and close the file.

Step 6

Build the apache2 package by executing dpkg-buildpackage -rfakeroot -uc -b. If all goes well, no errors are generated and after a few minutes, the build will finish with:

dpkg-deb: building package 'apache2-bin' in '../apache2-bin_2.4.25-3+deb9u10_amd64.deb'.                                                                                                                                                                                                                                     
dpkg-deb: building package 'apache2' in '../apache2_2.4.25-3+deb9u10_amd64.deb'.                                                                                                                                                                                                                                             
dpkg-deb: building package 'apache2-utils' in '../apache2-utils_2.4.25-3+deb9u10_amd64.deb'.                                                                                                                                                                                                                                 
dpkg-deb: building package 'apache2-suexec-pristine' in '../apache2-suexec-pristine_2.4.25-3+deb9u10_amd64.deb'.                                                                                                                                                                                                             
dpkg-deb: building package 'apache2-suexec-custom' in '../apache2-suexec-custom_2.4.25-3+deb9u10_amd64.deb'.                                                                                                                                                                                                                 
dpkg-deb: building package 'apache2-dev' in '../apache2-dev_2.4.25-3+deb9u10_amd64.deb'.     
dpkg-deb: building package 'apache2-ssl-dev' in '../apache2-ssl-dev_2.4.25-3+deb9u10_amd64.deb'.                                                                                  
dpkg-deb: building package 'apache2-dbg' in '../apache2-dbg_2.4.25-3+deb9u10_amd64.deb'.                       
make[2]: Leaving directory '/home/biscuitninja/httpd/apache2-2.4.25'                                                                                                                    
make[1]: Leaving directory '/home/biscuitninja/httpd/apache2-2.4.25'                                 
   debian/rules binary-indep                                                                                                                                                             
make[1]: Entering directory '/home/biscuitninja/httpd/apache2-2.4.25'                                
dh binary-indep --parallel --with autotools_dev,systemd      
   dh_installdeb -i -O--parallel
   dh_gencontrol -i -O--parallel                                                        
   dh_md5sums -i -O--parallel                                                         
   debian/rules override_dh_builddeb                        
make[2]: Entering directory '/home/biscuitninja/httpd/apache2-2.4.25'
dh_builddeb -- -Zxz
dpkg-deb: building package 'apache2-data' in '../apache2-data_2.4.25-3+deb9u10_all.deb'.
dpkg-deb: building package 'apache2-doc' in '../apache2-doc_2.4.25-3+deb9u10_all.deb'.
make[2]: Leaving directory '/home/biscuitninja/httpd/apache2-2.4.25'
make[1]: Leaving directory '/home/biscuitninja/httpd/apache2-2.4.25'
 dpkg-genbuildinfo --build=binary
 dpkg-genchanges --build=binary >../apache2_2.4.25-3+deb9u10_amd64.changes
dpkg-genchanges: info: binary-only upload (no source code included)
 dpkg-source --after-build apache2-2.4.25
dpkg-buildpackage: info: binary-only upload (no source included)

Step 7

Change back to the ~/httpd2 directory, install the apache2 package and any related packages you need. At a minimum, the command you run will be:

sudo dpkg -i ./apache2_2.4.25-3+deb9u12_amd64.deb ./apache2-utils_2.4.25-3+deb9u12_amd64.deb ./apache2-bin_2.4.25-3+deb9u12_amd64.deb ./apache2-data_2.4.25-3+deb9u12_all.deb

The final output from the above should look something like:

(Reading database ... 41141 files and directories currently installed.)                                                                                                                                                                                                                                                      
Preparing to unpack .../apache2_2.4.25-3+deb9u12_amd64.deb ...                                                                                                                                                                                                                                                               
Unpacking apache2 (2.4.25-3+deb9u12) over (2.4.25-3+deb9u12) ...                                                                                                                                                                                                                                                             
Preparing to unpack .../apache2-utils_2.4.25-3+deb9u12_amd64.deb ...                                                                                                                                                                                                                                                         
Unpacking apache2-utils (2.4.25-3+deb9u12) over (2.4.25-3+deb9u12) ...                                                                                                                                                                                                                                                       
Preparing to unpack .../apache2-dev_2.4.25-3+deb9u12_amd64.deb ...                                                                                                                                          
Unpacking apache2-dev (2.4.25-3+deb9u12) over (2.4.25-3+deb9u12) ...
Preparing to unpack .../apache2-bin_2.4.25-3+deb9u12_amd64.deb ...  
Unpacking apache2-bin (2.4.25-3+deb9u12) over (2.4.25-3+deb9u12) ...
Preparing to unpack .../apache2-bin_2.4.25-3+deb9u12_amd64.deb ...   
Unpacking apache2-bin (2.4.25-3+deb9u12) over (2.4.25-3+deb9u12) ...
Preparing to unpack .../apache2-dbg_2.4.25-3+deb9u12_amd64.deb ...
Unpacking apache2-dbg (2.4.25-3+deb9u12) over (2.4.25-3+deb9u12) ...
Preparing to unpack .../apache2-data_2.4.25-3+deb9u12_all.deb ...
Unpacking apache2-data (2.4.25-3+deb9u12) over (2.4.25-3+deb9u12) ...
More than one copy of package apache2-bin has been unpacked
 in this run !  Only configuring it once.
Setting up apache2-utils (2.4.25-3+deb9u12) ...
Setting up apache2-dev (2.4.25-3+deb9u12) ...
Setting up apache2-bin (2.4.25-3+deb9u12) ...
Setting up apache2-data (2.4.25-3+deb9u12) ...
Setting up apache2 (2.4.25-3+deb9u12) ...
Setting up apache2-dbg (2.4.25-3+deb9u12) ...
Processing triggers for systemd (232-25+deb9u13) ...
Processing triggers for man-db (2.7.6.1-2) ..

Victory?

Rebuilding apache2 qualifies as a niche activity. I was investigating Jeff Trawick’s mod_backtrace and mod_whatkilledus to try and obtain something approaching a stack trace from httpd in certain conditions. That is still an ongoing project.

If in the meantime you find yourself wanting to recompile any Debian package, in order to test a change or bug fix, this hopefully serves as a gentle introduction.