Guide: How to build standalone htdigest & htpasswd

General discussion about web technology.
Post Reply
barbaz
Senior Member
Posts: 9280
Joined: Sat Aug 03, 2013 5:45 pm

Guide: How to build standalone htdigest & htpasswd

Post by barbaz » Sat Apr 02, 2016 4:15 pm

Much searching on the Internet about this found nothing useful, so I'm going to post what I found here...

Disclaimer: Note that likely this is completely unsupported by Apache httpd project. I'm just posting what worked for me, take this as an approximate guide. Also, it may or may not work with Apache httpd source versions other than 2.4.18. I make no guarantees as to whether this will work for you and I can't provide support for this. Proceed at your own risk.
[/disclaimer]

Trying to set up the nginx on my new server like I had apache2 set up on my prior server, but discovered that the way to generate password files pretty much requires htpasswd and/or htdigest... but installing those required installing significant parts of Apache2, which I didn't want to do. So I grabbed the sources for Apache httpd 2.4.18 to see if I could build statically-linked htdigest & htpasswd standalone executables. And yes it is possible but it requires some hackery. So here is what I figured out from digging around in the Apache httpd build system code.

1) Download Apache2 httpd source code from https://httpd.apache.org/download.cgi#apache24: click "Other Files" and grab BOTH httpd-2.4.18 AND httpd-2.4.18-deps
2) extract both of them to the same place (they will write into each other)
3) Follow Apache's build instructions for the configure stage (https://httpd.apache.org/docs/current/programs/configure.html). We want these options:

Code: Select all

./configure --with-static-htpasswd --with-static-htdigest --with-included-apr

4) Build the included apr - shouldn't take too long:

Code: Select all

make -C srclib

5) If you try to build htpasswd & htdigest now you will get non-working executables... Hmm, configure didn't seem to finish, er, configuring... but digging around in the build system shows what was intended to happen, so we can just do it ourselves. Edit build/config_vars.mk and change the following two lines to add "-static". They were initially unset for me, so this is what I ended up with:

Code: Select all

htpasswd_LTFLAGS = -static
htdigest_LTFLAGS = -static

6) Finally we can build - cd to the support/ directory at the root of the sources, and run:

Code: Select all

make htpasswd htdigest


If all went well, you should now have working htdigest & htpasswd executables sitting somewhere... I forget where exactly they landed. Anyway, happy password-file-making :)
*Always* check the changelogs BEFORE updating that important software!
-

Post Reply