Compiling Apache HTTPD on Mac (Tech Tip #45)

One of my blogs needed Apache HTTPD 2.4.x on Mac but quickly realized that the binaries are available only for Netware and Win32. Even the build instructions were only for RPM-based systems. So I downloaded the source code and started building it.

Complete compile instructions are explained here. However there were some issues on Mavericks and so decided to document it.

Let’s go!

  1. Download the source bundle and unzip:
    tar xzvf ~/Downloads/httpd-2.4.10.tar.bz2
  2. Source code comes with INSTALL instructions and per that the following should’ve worked:
    ./configure --prefix=PREFIX
    make
    make install
    PREFIX/bin/apachectl start

    So gave the command

    ./configure --prefix=/usr/local/apache2

    and got the first error:

    httpd-2.4.10> ./configure --prefix=/usr/local/apache2
    checking for chosen layout... Apache
    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... x86_64-apple-darwin13.3.0
    checking host system type... x86_64-apple-darwin13.3.0
    checking target system type... x86_64-apple-darwin13.3.0
    configure: 
    configure: Configuring Apache Portable Runtime library...
    configure: 
    checking for APR... yes
      setting CC to "/Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.9.xctoolchain/usr/bin/cc"
      setting CPP to "/Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.9.xctoolchain/usr/bin/cc -E"
      setting CFLAGS to " "
      setting CPPFLAGS to " -DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK"
      setting LDFLAGS to " "
    configure: 
    configure: Configuring Apache Portable Runtime Utility library...
    configure: 
    checking for APR-util... yes
    checking for gcc... /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.9.xctoolchain/usr/bin/cc
    checking whether the C compiler works... no
    configure: error: in `/Users/arungupta/workspaces/httpd-2.4.10':
    configure: error: C compiler cannot create executables
    See `config.log' for more details
    
  3. Moved past “checking whether the C compiler works… no” error by following instructions on stackoverflow #13587001.In short, do the following for Mavericks
    sudo ln -s /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.9.xctoolchain
  4. Issued the command to compile the server again and got the error as shown:
    httpd-2.4.10> ./configure --prefix=/usr/local/apache2 
    checking for chosen layout... Apache
    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... x86_64-apple-darwin13.3.0
    checking host system type... x86_64-apple-darwin13.3.0
    checking target system type... x86_64-apple-darwin13.3.0
    configure: 
    configure: Configuring Apache Portable Runtime library...
    configure: 
    checking for APR... yes
      setting CC to "/Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.9.xctoolchain/usr/bin/cc"
      setting CPP to "/Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.9.xctoolchain/usr/bin/cc -E"
      setting CFLAGS to " "
      setting CPPFLAGS to " -DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK"
      setting LDFLAGS to " "
    configure: 
    configure: Configuring Apache Portable Runtime Utility library...
    configure: 
    checking for APR-util... yes
    checking for gcc... /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.9.xctoolchain/usr/bin/cc
    checking whether the C compiler works... yes
    checking for C compiler default output file name... a.out
    checking for suffix of executables... 
    checking whether we are cross compiling... no
    checking for suffix of object files... o
    checking whether we are using the GNU C compiler... yes
    checking whether /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.9.xctoolchain/usr/bin/cc accepts -g... yes
    checking for /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.9.xctoolchain/usr/bin/cc option to accept ISO C89... none needed
    checking how to run the C preprocessor... /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.9.xctoolchain/usr/bin/cc -E
    checking for /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.9.xctoolchain/usr/bin/cc option to accept ISO C99... none needed
    checking for pcre-config... false
    configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

    This was resolved using stackoverflow #10663180. In short:

    1. Download PCRE as:
      curl -O ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.33.zip
    2. Compile and install as:
      ./configure --prefix=/usr/local/pcre
      make
      sudo make install

    The compilation output is shown here.

  5. Compile HTTPD source again as:
    httpd-2.4.10> ./configure --prefix=/usr/local/apache2 --with-pcre=/usr/local/pcre
    checking for chosen layout... Apache
    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... x86_64-apple-darwin13.3.0
    checking host system type... x86_64-apple-darwin13.3.0
    checking target system type... x86_64-apple-darwin13.3.0
    configure: 
    . . .
    creating server/Makefile
    creating support/Makefile
    creating test/Makefile
    config.status: creating docs/conf/httpd.conf
    config.status: creating docs/conf/extra/httpd-autoindex.conf
    config.status: creating docs/conf/extra/httpd-dav.conf
    config.status: creating docs/conf/extra/httpd-default.conf
    config.status: creating docs/conf/extra/httpd-info.conf
    config.status: creating docs/conf/extra/httpd-languages.conf
    config.status: creating docs/conf/extra/httpd-manual.conf
    config.status: creating docs/conf/extra/httpd-mpm.conf
    config.status: creating docs/conf/extra/httpd-multilang-errordoc.conf
    config.status: creating docs/conf/extra/httpd-ssl.conf
    config.status: creating docs/conf/extra/httpd-userdir.conf
    config.status: creating docs/conf/extra/httpd-vhosts.conf
    config.status: creating docs/conf/extra/proxy-html.conf
    config.status: creating include/ap_config_layout.h
    config.status: creating support/apxs
    config.status: creating support/apachectl
    config.status: creating support/dbmmanage
    config.status: creating support/envvars-std
    config.status: creating support/log_server_status
    config.status: creating support/logresolve.pl
    config.status: creating support/phf_abuse_log.cgi
    config.status: creating support/split-logfile
    config.status: creating build/rules.mk
    config.status: creating build/pkg/pkginfo
    config.status: creating build/config_vars.sh
    config.status: creating include/ap_config_auto.h
    config.status: executing default commands

    Complete output of this configuration is here.

  6. Now issue the command make:
    httpd-2.4.10> make
    Making all in srclib
    Making all in os
    Making all in unix
    /usr/share/apr-1/build-1/libtool --silent --mode=compile /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.9.xctoolchain/usr/bin/cc        -DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK     -I. -I/Users/arungupta/workspaces/httpd-2.4.10/os/unix -I/Users/arungupta/workspaces/httpd-2.4.10/include -I/usr/include/apr-1 -I/usr/local/pcre/include -I/Users/arungupta/workspaces/httpd-2.4.10/modules/aaa -I/Users/arungupta/workspaces/httpd-2.4.10/modules/cache -I/Users/arungupta/workspaces/httpd-2.4.10/modules/core -I/Users/arungupta/workspaces/httpd-2.4.10/modules/database -I/Users/arungupta/workspaces/httpd-2.4.10/modules/filters -I/Users/arungupta/workspaces/httpd-2.4.10/modules/ldap -I/Users/arungupta/workspaces/httpd-2.4.10/modules/loggers -I/Users/arungupta/workspaces/httpd-2.4.10/modules/lua -I/Users/arungupta/workspaces/httpd-2.4.10/modules/proxy -I/Users/arungupta/workspaces/httpd-2.4.10/modules/session -I/Users/arungupta/workspaces/httpd-2.4.10/modules/ssl -I/Users/arungupta/workspaces/httpd-2.4.10/modules/test -I/Users/arungupta/workspaces/httpd-2.4.10/server -I/Users/arungupta/workspaces/httpd-2.4.10/modules/arch/unix -I/Users/arungupta/workspaces/httpd-2.4.10/modules/dav/main -I/Users/arungupta/workspaces/httpd-2.4.10/modules/generators -I/Users/arungupta/workspaces/httpd-2.4.10/modules/mappers  -prefer-non-pic -static -c unixd.c && touch unixd.lo
    /usr/share/apr-1/build-1/libtool --silent --mode=link /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.9.xctoolchain/usr/bin/cc           -o libos.la -static  unixd.lo  
    Making all in server
    Making all in mpm
    Making all in worker
    . . .
    warning: no debug symbols in executable (-arch x86_64)
    /usr/share/apr-1/build-1/libtool --silent --mode=compile /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.9.xctoolchain/usr/bin/cc        -DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK     -I. -I/Users/arungupta/workspaces/httpd-2.4.10/os/unix -I/Users/arungupta/workspaces/httpd-2.4.10/include -I/usr/include/apr-1 -I/usr/local/pcre/include -I/Users/arungupta/workspaces/httpd-2.4.10/modules/aaa -I/Users/arungupta/workspaces/httpd-2.4.10/modules/cache -I/Users/arungupta/workspaces/httpd-2.4.10/modules/core -I/Users/arungupta/workspaces/httpd-2.4.10/modules/database -I/Users/arungupta/workspaces/httpd-2.4.10/modules/filters -I/Users/arungupta/workspaces/httpd-2.4.10/modules/ldap -I/Users/arungupta/workspaces/httpd-2.4.10/modules/loggers -I/Users/arungupta/workspaces/httpd-2.4.10/modules/lua -I/Users/arungupta/workspaces/httpd-2.4.10/modules/proxy -I/Users/arungupta/workspaces/httpd-2.4.10/modules/session -I/Users/arungupta/workspaces/httpd-2.4.10/modules/ssl -I/Users/arungupta/workspaces/httpd-2.4.10/modules/test -I/Users/arungupta/workspaces/httpd-2.4.10/server -I/Users/arungupta/workspaces/httpd-2.4.10/modules/arch/unix -I/Users/arungupta/workspaces/httpd-2.4.10/modules/dav/main -I/Users/arungupta/workspaces/httpd-2.4.10/modules/generators -I/Users/arungupta/workspaces/httpd-2.4.10/modules/mappers -prefer-pic -c mod_rewrite.c && touch mod_rewrite.slo
    /usr/share/apr-1/build-1/libtool --silent --mode=link /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.9.xctoolchain/usr/bin/cc             -o mod_rewrite.la -rpath /usr/local/apache2/modules -module -avoid-version  mod_rewrite.lo 
    warning: no debug symbols in executable (-arch x86_64)
    

    Complete output of the command is shown here.

  7. Finally install Apache2 as:
    httpd-2.4.10> sudo make install
    Password:
    Making install in srclib
    Making install in os
    Making install in unix
    Making install in server
    Making install in mpm
    Making install in worker
    mkdir /usr/local/apache2
    mkdir /usr/local/apache2/modules
    Making install in modules
    . . .
    Installing man pages and online manual
    mkdir /usr/local/apache2/man
    mkdir /usr/local/apache2/man/man1
    mkdir /usr/local/apache2/man/man8
    mkdir /usr/local/apache2/manual

    Complete output of this command is shown here.

Version for HTTPD can be checked as:

httpd-2.4.10> /usr/local/apache2/bin/httpd -v
Server version: Apache/2.4.10 (Unix)
Server built:   Aug 22 2014 16:00:19

Server can be started as:

sudo /usr/local/apache2/bin/apachectl start

Stopped as:

sudo /usr/local/apache2/bin/apachectl stop

Restarted as:

sudo /usr/local/apache2/bin/apachectl restart

Enjoy!

Be Sociable, Share!
  • Tweet
  1. Alexis Hassler says:

    I’m certainly lazier than you. When I need httpd 2.4, I’m downloading XAMMP. It’s easy to install. The drawback is the size (120 MB to download), as it includes MySQL and PHP.

Leave a Reply

Your email address will not be published. Required fields are marked *


× 6 = thirty

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>