Richard
Note: I need to update this page to reflect the changes happening in Apache 2.4.0 and higher. Until then read the remarks in this blogpost.
I’ve documented two ways of installing Apache. One where the default Apache Lion install is overwritten with your own version (the Darwin layout). A second one, the DIYMacServer layout, where the default install is left alone completely (it uses the same directory for the webpages, but a different location for the binaries, configuration and logfiles). The difference in the configuration is decided with the '-enable-layout‘ option during configuration. If you choose the Darwin layout Apple’s updates might mess with your setup.
If you select the default Darwin layout skip the next bit until the configuration phase (please note that the rest of the instruction on this site are based on the DIYMacServer layout!) otherwise continue reading.
For the DIYMacServer layout we need to edit some configuration files in the Apache source directory before we can start. First copy the layout below and add it to the ‘config.layout’ file in source directory.
<Layout DIYMacServer>
prefix: /usr/local/apache2
exec_prefix: ${prefix}
bindir: ${exec_prefix}/bin
sbindir: ${exec_prefix}/bin
libdir: ${exec_prefix}/lib
libexecdir: ${exec_prefix}/modules
mandir: ${prefix}/man
sysconfdir: /etc/httpd
datadir: /Library/WebServer
installbuilddir: ${datadir}/build
errordir: ${datadir}/error
iconsdir: ${datadir}/icons
htdocsdir: ${datadir}/Documents
manualdir: ${datadir}/manual
cgidir: ${datadir}/CGI-Executables
includedir: ${prefix}/include
localstatedir: /var
runtimedir: ${localstatedir}/run
logfiledir: ${localstatedir}/log/httpd
proxycachedir: ${runtimedir}/proxy
</Layout>
Next you need to add the following layout to the config.layout files in these locations:
- ./srclib/apr/config.layout
- ./srclib/apr-util/config.layout
<Layout DIYMacServer>
prefix: /usr/local/apache2
exec_prefix: ${prefix}
bindir: ${exec_prefix}/bin
sbindir: ${exec_prefix}/bin
libdir: ${exec_prefix}/lib
libexecdir: ${exec_prefix}/libexec+
mandir: ${prefix}/share/man
sysconfdir: /etc/httpd
datadir: /Library/WebServer
installbuilddir: ${datadir}/build
includedir: ${prefix}/include
localstatedir: /var
runtimedir: ${localstatedir}/run
</Layout>
If you’ve edited the ‘config.layout’ file to add DIYMacServer (the Darwin layout is already in the file) you are ready to run the configuration script. Change the ‘–enable-layout’ to reflect your choice in configuration. So fill in either DIYMacServer or Darwin to choose, the example uses DIYMacServer as the layout.
./configure -enable-layout=DIYMacServer \ -enable-mods-shared=all \ -with-ssl=/usr \ -with-mpm=prefork \ -disable-unique-id \ -enable-ssl \ -enable-dav \ -enable-cache \ -enable-proxy \ -enable-logio \ -enable-deflate \ -with-included-apr \ -enable-cgi \ -enable-cgid \ -enable-suexec
You can now run:
make
and if it all goes well:
sudo make install
If you run into errors which you can’t explain, please post you questions and the error into the forum on this site.



Comments
11:37 pm
Hi Richard
Just want to ask about the layout vs the “Apache”-layout (http://www.opensource.apple.com/source/apache/apache-769/httpd/config.layout?txt)
Looks like the main 2 diff’s are these:
—
# Classical Apache path layout.
// … //
sysconfdir: ${prefix}/conf
// … //
localstatedir: ${prefix}
// … //
—
Mostly out of my own curiosity and it’s ok if I really need to keep certain files at another level/location, but since we install everything aside the bundled versions, it would be great to keep all files in there. So…
# sysconfdir:
/// –sysconfdir=DIR
Install read-only single-machine data like the server configuration files httpd.conf, mime.types, etc. in DIR. By default sysconfdir is set to PREFIX/conf. ///
(from just before http://httpd.apache.org/docs/2.2/programs/configure.html#systemtypes)
Would it break the server to keep the .conf files in “${prefix}/conf”? Or is it another use of the “/etc/httpd” path? Could you please elaborate a little over the difference between Apache standard and DYIMac/Darwin?
# localstatedir:
It’s just for the log’s, right? What happens (or maybe not happens) if another place for the “localstatedir” is chosen like “${prefix}”?
- – -
Thanks for a great website and all guides and articles!
Eric
9:40 am
@Eric,
The idea behind creating the DIYMacServer layout file was to make sure that our own install of Apache does not interfere with the existing installation and configuration and would still adhere to some of the basic OS X principles.
Although the apache layout takes care of the ${prefix} part, it does not work for the “datadir”(would like to keep that the same as Darwin) and the log files in /var as for the rest.
So it’s like taking the best of both worlds.
7:54 pm
Hi,
You should mention that apr is no longer included in the apache source. To install this, you need to go to http://apr.apache.org/download.cgi and download BOTH apr and apr-util, then untar them and copy them to {http-download-dir}/srclib/apr and {http-download-dir}/srclib/apr-util respectively. Then following the instructions on this page worked fine for me.
This is for Apache 2.4.1, APR 1.4.6, and APR-Util 1.4.1
-Mike
8:00 pm
Mike, I’m working on the new instructions for Apache 2.4 as many things have changed. Please look at the page http://diymacserver.com/what-is-the-latest-version-tested/ for everything that is tested at the moment.
8:56 pm
Having trouble installing Apache 2.4.1 on Mac OS X 10.7 Lion. The configuration fails for srclib/apr.
Downloaded and Apache 2.4.1, and placed the folder httpd-2.4.1 into the folder /usr/local/src.
Added the first code block to /usr/local/src/httpd-2.4.1/config.layout.
The files /apr/config.layout and /apr-util/config.layout did not exist in the folder /usr/local/src/httpd-2.4.1/srclib, so I created them and added the second code block above to both.
When I run the configuration script (third code block) I got:
Ripper:httpd-2.4.1 frank$ ./configure -enable-layout=DIYMacServer \
> -enable-mods-shared=all \
> -with-ssl=/usr \
> -with-mpm=prefork \
> -disable-unique-id \
> -enable-ssl \
> -enable-dav \
> -enable-cache \
> -enable-proxy \
> -enable-logio \
> -enable-deflate \
> -with-included-apr \
> -enable-cgi \
> -enable-cgid \
> -enable-suexec
checking for chosen layout… DIYMacServer
checking for working mkdir -p… yes
checking for grep that handles long lines and -e… /usr/bin/grep
checking for egrep… /usr/bin/grep -E
checking build system type… i386-apple-darwin11.3.0
checking host system type… i386-apple-darwin11.3.0
checking target system type… i386-apple-darwin11.3.0
Configuring Apache Portable Runtime library …
configuring package in srclib/apr now
/bin/sh: /usr/local/src/httpd-2.4.1/srclib/apr/configure: No such file or directory
configure failed for srclib/apr
Now that we’ve confirmed I don’t know what the hell I’m doing, what should I do now?
BTW, I’m having trouble registering with your fine website, but that’s another matter.
9:45 pm
@Francis, please take a look at http://diymacserver.com/2012/03/05/apache-update-to-2-4-1/ where all your problems will be explained. I’m late with updating all the other instructions. My apologies…
9:46 pm
Downloaded, expanded and relocated apr and apr-util per Mike’s comments. Now I get a little further, but still get the following configuration error:
checking for gcc… no
checking for cc… no
checking for cl.exe… no
configure: error: in `/usr/local/src/httpd-2.4.1/srclib/apr’:
configure: error: no acceptable C compiler found in $PATH
See `config.log’ for more details
configure failed for srclib/apr
BTW, I previously downloaded and installed XTools 4.3.1, then upgraded to XTools 4.3.2 via the App Store. I thought the whole reason to install XTools was to install a usable compiler. What am I missing?
10:26 pm
No need to apologize, this site is fantastic!
When I find out why I’m getting the “no accpetable C compiler found in $PATH” error I’ll be sure to report back!
Thanks for all the great instructions.
4:21 pm
Xcode (not XTools) 4.3.2 requires you to download the command line tools separately. Launch Xcode4, open preferences, go to the Downloads tab, then install “Command Line Tools.” You’ll need your AppleID and password.
I had to completely uninstall Xcode3:
sudo /Developer/Library/uninstall-devtools –mode=all
Download PCRE from http://www.pcre.org/, then expand, configure make and install:
cd /usr/local/src
tar xvzf pcre-8.13.tar.gz
cd pcre-8.13
./configure –prefix=/usr/local
make
sudo make install
cd ..
Apache 2.4.1 now configures, makes and installs nicely.
7:08 pm
@Francis, thanks for this! I had not noticed the new version and the new method of installing Xcode and the separation of the command line tools. I’m doing it myself at the moment and will blog and update the documentation for this as well!
10:34 pm
Something is amiss with this installation.
The Apache 2.4.1 executable is /usr/local/apache2/bin/httpd.
The OS’s Apache 2.2.21 executable is /usr/sbin/httpd.
Unless you disable /usr/sbin/httpd, /usr/local/apache2/bin/httpd won’t run.
What’s up with that?
11:09 pm
I needed to update my $PATH in .bash_profile. And now I use apacheDIY- and apacheMac- aliases to distinguish between the two installations.
Thanks to you, it took only a weekend to install the latest stable releases of Apache, PHP, MySQL and phpMyAdmin on my machine.
Now it’s time to finally create that Zend Framework project!