I needed to compile apache2 on ubuntu but I wanted it to use the original configuration and layout. It took me a very long time to find the information to do this, so I thought I would create this question and answer to help others.

Note: I needed the latest version of apache that was not yet supported by my version of ubuntu and I did not want to upgrade my version of ubuntu.

migrated from serverfault.com Jan 3 '15 at 20:30

This question came from our site for system and network administrators.

  • Why the down vote? – Rian Jan 2 '15 at 12:58


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:

<Layout x>

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.

To hold:

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


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:

--with-pcre=/usr \
--enable-mpms-shared=all \
--enable-unixd=static \

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

./configure \
--with-pcre=/usr \
--enable-mpms-shared=all \
--enable-unixd=static \
--enable-layout=Debian --enable-so \
--with-program-name=apache2  \
--with-ldap=yes --with-ldap-include=/usr/include \
--with-ldap-lib=/usr/lib \
--with-suexec-caller=www-data \
--with-suexec-bin=/usr/lib/apache2/suexec \
--with-suexec-docroot=/var/www \
--with-suexec-userdir=public_html \
--with-suexec-logfile=/var/log/apache2/suexec.log \
--with-suexec-uidmin=100 \
--enable-suexec=shared \
--enable-log-config=static --enable-logio=static \
--enable-version=static \
--with-apr=/usr/bin/apr-1-config \
--with-apr-util=/usr/bin/apu-1-config \
--with-pcre=yes \
--enable-pie \
--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-scgi=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-status=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 \
--enable-substitute=shared  --enable-reqtimeout=shared;

Stop the current apache

/etc/init.d/apache2 stop

To build and install apache, run the following commands in the build directory

make install


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

/etc/init.d/apache2 start

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.

Good Luck!

Special thanks to jrwren for his post that was the missing piece to my puzzle:


  • If I followed this correctly, it will leave your system in a state where apt-get thinks it still manages the apache installation. Next time a new version is released to the repository it will mess up your installation. – faker Jan 1 '15 at 10:45
  • Yes, thanks for pointing that out. It was in the back of my mind but I will need to come up with a solution to this problem. If I leave it as is, I might have to repeat the process till ubuntu has caught up with the version I am using, every time I upgrade and it breaks again. Which would suck. Otherwise, I can set the --prefix=/usr/local/apache2 configure option. Copy my original config to there and switch back to using the ubuntu version when it has caught up. This is probably the better option, I will try update the post tomorrow. Do you have a suggestion? – Rian Jan 1 '15 at 15:53
  • I'm not a Debian/Ubuntu guy, but the normal way I'd do this is to obtain the (source) package and change that package to my needs and then install it via the normal package tools available. But never overwrite binaries installed by the package manager. Someone else looks at dpkg -l on that system and will be absolutely confused. Rather remove the package and then install it from source (which will bring other problems, like you need to ship the init script again). – faker Jan 1 '15 at 16:04
  • Good suggestion, I'll look into how to build a deb package and use dpkg to install. Thanks for the advice. – Rian Jan 2 '15 at 9:22
  • This did not work for me, so I am going with apt-mark hold apache2, to ensure that it is not upgraded till I choose to. – Rian Jan 2 '15 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.