This worked for me. If there is a simpler way, I am sure you will let me know.
In theory these steps should work for any linux distribution, you just need to find the original configure options that are used to compile apache for your distro. Perhaps you could add comments to this answer on where you found the options.
The important option is:
Debian can be changed to any one of the supported layouts in config.layout file in the apache build directory, the options are defined as:
Where x would be the layout option. Try googling "--enable-layout=x" where x is your distribution to find your options. Try find the original options used by your distro and not some random suggestions.
EDIT: As mentioned by faker the problem with this is that when you upgrade using apt and there is a new version of apache2, the compiled version will be overwritten. His suggestion of building a new deb is a good one. Unfortunately due to various deb dependency issues that are too much work to get around I have not been able to do so. However I would suggest that you try that route first, this should help you:
I've opted to keep it as is, however I have set a hold on apache2 so it is not upgraded till I am ready to release the hold. Alternatively you could just remove apache from the machine and add it again when you are ready.
sudo apt-mark hold apache2
To release hold:
sudo apt-mark unhold apache2
I would also suggest that you make a clone of the server you wish to change, work through the process on the clone and get it working before trying it on a production env. Breaking apache for a day or longer on a prod environment is not a stress you need in your life. This is where virtual machines are great, take a snapshot and create a new instance from the snapshot. Or replicate the environment you wish to change and make the changes there.
I use digital ocean, they rock, use this link to get $10 off your subscription. Disclaimer I get $25 off mine:
Here is how to do it on ubuntu as promised
This assumes that you already have the default apache version installed on your system by having previously run:
sudo apt-get install apache2
and you have run
sudo apt-get upgrade
To upgrade all packages to the latest, including apache.
If there have been major changes in config from your version to the latest version of apache you would need to make those changes yourself. This can take a while, hence the suggestion of trying this on a server clone as mentioned in the preamble.
You need to install the dependencies to do the build
sudo apt-get build-dep apache2
You need to download the apache source and unzip it, this will be referred to as the build directory.
Backup your current configuration: DON'T SKIP THIS STEP
sudo cp -r /etc/apache2 ~/apache2_conf_back
You need to establish what your release code name is:
sudo cat /etc/lsb-release
Mine is trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.1 LTS"
You should then be able to replace the 2 occurrences of the word "trusty" in the following url to get the options used to build your release's version of apache
I used the options defined for the variables "AP2_COMMON_CONFARGS" and "AP2_worker_CONFARGS". Additionally I added the options:
As I ended up trying a few times to get this right, I created the following file in the apache build directory which I ran each time. Call it myconfig.sh
--enable-layout=Debian --enable-so \
--with-ldap=yes --with-ldap-include=/usr/include \
--enable-log-config=static --enable-logio=static \
--enable-authn-alias=shared --enable-authnz-ldap=shared \
--enable-disk-cache=shared --enable-cache=shared \
--enable-mem-cache=shared --enable-file-cache=shared \
--enable-cern-meta=shared --enable-dumpio=shared --enable-ext-filter=shared \
--enable-charset-lite=shared --enable-cgi=shared \
--enable-dav-lock=shared --enable-log-forensic=shared \
--enable-ldap=shared --enable-proxy=shared \
--enable-proxy-connect=shared --enable-proxy-ftp=shared \
--enable-proxy-http=shared --enable-proxy-ajp=shared \
--enable-proxy-balancer=shared --enable-ssl=shared \
--enable-authn-dbm=shared --enable-authn-anon=shared \
--enable-authn-dbd=shared --enable-authn-file=shared \
--enable-authn-default=shared --enable-authz-host=shared \
--enable-authz-groupfile=shared --enable-authz-user=shared \
--enable-authz-dbm=shared --enable-authz-owner=shared \
--enable-authnz-ldap=shared --enable-authz-default=shared \
--enable-auth-basic=shared --enable-auth-digest=shared \
--enable-dbd=shared --enable-deflate=shared \
--enable-include=shared --enable-filter=shared \
--enable-env=shared --enable-mime-magic=shared \
--enable-expires=shared --enable-headers=shared \
--enable-ident=shared --enable-usertrack=shared \
--enable-unique-id=shared --enable-setenvif=shared \
--enable-autoindex=shared --enable-asis=shared \
--enable-info=shared --enable-cgid=shared \
--enable-dav=shared --enable-dav-fs=shared \
--enable-vhost-alias=shared --enable-negotiation=shared \
--enable-dir=shared --enable-imagemap=shared \
--enable-actions=shared --enable-speling=shared \
--enable-userdir=shared --enable-alias=shared \
--enable-rewrite=shared --enable-mime=shared \
Stop the current apache
To build and install apache, run the following commands in the build directory
Restore your apache config. I HOPE YOU BACKED YOUR CONFIG UP AS DESCRIBED EARLIER
sudo rm -rf /etc/apache2
sudo cp -r ~/apache2_conf_back /etc/apache2
I needed to make the include paths absolute in /etc/apache2/apache2.conf, the following commands do this in vim
:%s/^IncludeOptional /IncludeOptional \/etc\/apache2\//
:%s/^Include /Include \/etc\/apache2\// /
I also needed to change the path to the envvars in /usr/sbin/apache2ctl to /etc/apache2/envvars
Then restart apache
Hopefully that works for you, if there are any syntax errors please let me know so I can fix them. Much of them were rewritten from memory.
Special thanks to jrwren for his post that was the missing piece to my puzzle: