Make Apache2 optional, and fix an issue with multiple distributions

Sorry for having these in the same pull-request - cherry-pick at will if anything looks suitable.