Odynia.org blog
  • Home
  • Apple / Mac / iOS
    • iOS
    • iTransit
  • General
    • Dukan Diet
  • Web Development
    • Microsoft CRM
    • Xnyo
    • PHP
  • Unix / BSD
    • Server Build

Installing Apache and its Ecosystem: Part 1

Jul10th
2012
avatar Written by Rob

I guess it is time for the big boy. Apache can be one of the most complicated things you install, mostly for the additional languages and modules. Like many, I have my own way of configuring it.

I’ll lay this out up front: I don’t like the FreeBSD layout for Apache. Everything is scattered throughout /usr/local and buried deep in the system. I got used to using the OpenBSD layout during my stint with that OS, and so I continue to use that on FreeBSD. It puts everything in /var/www/ and keeps it nice and clean together.

That said, the binaries and other bits and pieces should remain in /usr/local/.

Building from Scratch

For once we’re not going to install Apache from ports. Why? Because it’s too damn hard to adjust the layout without building a completely custom port. What we can do though is use the ports tree to do a big chunk of the work for us.

Configure your options

Run make config in the port and select the options you want installed. I go with the defaults here usually.

Shell
1
2
[root@shana /]$ cd /usr/ports/www/apache22
[root@shana /usr/ports/www/apache22]$ make config

Install the dependencies

Now that we’ve selected our options, we can also use it to build and install the dependencies, much the same as we would do if we were installing Apache through ports.

Shell
1
2
3
4
5
6
7
8
9
10
11
[root@shana /usr/ports/www/apache22]$ make depends
# ===>   apache-2.2.22_5 depends on file: /usr/local/bin/perl5.12.4 - found
# ===>   apache-2.2.22_5 depends on file: /usr/local/bin/perl5.12.4 - found
# ===>   apache-2.2.22_5 depends on shared library: expat - found
# ===>   apache-2.2.22_5 depends on shared library: apr-1 - found
# ===>   apache-2.2.22_5 depends on shared library: pcre - found
# ===>   apache-2.2.22_5 depends on shared library: iconv.3 - found
# ===>   apache-2.2.22_5 depends on file: /usr/local/bin/perl5.12.4 - found
# ===>   apache-2.2.22_5 depends on file: /usr/local/bin/autoconf-2.69 - found
# ===>   apache-2.2.22_5 depends on package: libtool>=2.4 - found
# ===>   apache-2.2.22_5 depends on file: /usr/local/bin/perl5.12.4 - found

So that is everything we should need.

Generating the configure command

Now we let the port install get as far as configuring the build, that will generate the configure command that was used, and we can copy that command and use it to build our own setup.

Shell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@shana /usr/ports/www/apache22]$ make configure
#
#  To enable a module category: WITH_<CATEGORY>_MODULES
#  To disable a module category: WITHOUT_<CATEGORY>_MODULES
#
#  Per default categories are:
#   AUTH AUTHN AUTHZ DAV CACHE MISC
#  Categories available:
#   AUTH AUTHN AUTHZ CACHE DAV EXPERIMENTAL LDAP  MISC PROXY SSL SUEXEC THREADS
#
#   To see all available knobs, type make show-options
#   To see all modules in different categories, type make show-categories
#   You can check your modules configuration by using make show-modules
#
# ===>  Found saved configuration for apache-2.2.22_5
# ===>  Extracting for apache-2.2.22_5
# <snip>
# config.status: creating include/ap_config_auto.h
# config.status: executing default commands

Setting up our own build environment

Now we’ve had our fun with ports it is time to build our own copy of Apache. I do my compilation in a directory called /archive/compile, but you can do it anywhere you like.

Grab the source

Ports will have also downloaded the source for you, so you can just extract it directly.

Shell
1
2
3
[root@shana /archive/compile]$ tar -zxf /usr/ports/distfiles/apache22/httpd-2.2.22.tar.bz2
[root@shana /archive/compile]$ cd httpd-2.2.22/
[root@shana /archive/compile/httpd-2.2.22]$

Create our custom layout

Now we also need to add the layout to the config.layout file. Just add this to the bottom of /archive/compile/httpd-2.2.22/config.layout.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#   iTransit Layout
<Layout iTransit>
    prefix:        /var/www
    exec_prefix:   /usr/local
    bindir:        ${exec_prefix}/bin
    sbindir:       ${exec_prefix}/sbin
    libdir:        ${exec_prefix}/lib
    libexecdir:    ${exec_prefix}/libexec/apache22
    mandir:        ${exec_prefix}/man      
    sysconfdir:    ${prefix}/conf
    datadir:       ${prefix}
    installbuilddir: ${exec_prefix}/share/apache22/build
    errordir:      ${prefix}/error
    iconsdir:      ${prefix}/icons
    htdocsdir:     ${prefix}/htdocs
    manualdir:     ${exec_prefix}/share/doc/apache22
    cgidir:        ${prefix}/cgi-bin
    includedir:    ${exec_prefix}/include/apache22  
    localstatedir: ${prefix}
    runtimedir:    ${prefix}/logs
    logfiledir:    ${prefix}/logs
    proxycachedir: ${prefix}/proxy
</Layout>

This layout is a mixture of the FreeBSD and OpenBSD layouts.

Obtain the configure script

When you run configure it will create a file called config.nice that has the command used to call configure. Copy it to your current directory under a different name. This would work for most people:

Shell
1
[root@shana /archive/compile/httpd-2.2.22]$ cp /usr/ports/www/apache22/work/httpd-2.2.22/config.nice t.sh

It would create a file called t.sh in your local directory. If, like me, you’ve moved your ports working directory, check under that.

Shell
1
[root@shana /archive/compile/httpd-2.2.22]$ cp /usr/obj/usr/ports/www/apache22/work/httpd-2.2.22/config.nice t.sh

Customise the configure script

You can now modify your t.sh file to make whatever adjustments you need to configure. In my case we want to use the custom layout we added above. Open up t.sh and change line 9 from:

9
"--enable-layout=FreeBSD" \

to

9
"--enable-layout=iTransit" \

Then head on down to line 59 and delete the prefix line, otherwise it will overwrite the prefix specified in the layout.

59
"--prefix=/usr/local" \

Applying Patches

There are a couple of FreeBSD-specific patches that we should really apply before we start compiling it. Without these, your custom build of Apache won’t build at all.

Patches can be found in /usr/ports/www/apache22/files/, we’ll take what we need and apply them directly.

1
2
3
4
5
6
7
8
9
10
[root@shana /archive/compile/httpd-2.2.22]$ patch </usr/ports/www/apache22/files/patch-server__util_pcre.c
# Hmm...  Looks like a unified diff to me...
# The text leading up to this was:
# --------------------------
# |--- server/util_pcre.c.orig    2005-11-10 16:20:05.000000000 +0100
# |+++ server/util_pcre.c    2012-02-13 23:11:17.898984171 +0100
# --------------------------
# Patching file server/util_pcre.c using Plan A...
# Hunk #1 succeeded at 137.
# done

So that’s one done, lets do the rest.

Shell
1
2
3
4
5
6
7
[root@shana /archive/compile/httpd-2.2.22]$ patch </usr/ports/www/apache22/files/patch-configure.in
[root@shana /archive/compile/httpd-2.2.22]$ patch </usr/ports/www/apache22/files/patch-modules__proxy__mod_proxy_connect.c
[root@shana /archive/compile/httpd-2.2.22]$ patch </usr/ports/www/apache22/files/patch-server__core.c
[root@shana /archive/compile/httpd-2.2.22]$ patch </usr/ports/www/apache22/files/patch-support__Makefile.in
[root@shana /archive/compile/httpd-2.2.22]$ patch </usr/ports/www/apache22/files/patch-support__ab.c
[root@shana /archive/compile/httpd-2.2.22]$ patch </usr/ports/www/apache22/files/patch-support__apachectl.in
[root@shana /archive/compile/httpd-2.2.22]$ patch </usr/ports/www/apache22/files/patch-support__apxs.in

Installing Apache

Now we can build and install Apache the same way we would for anything else we’re building from source.

Running configure

To configure the source directory with all the pre-requisites, just run the t.sh command from earlier.

Shell
1
2
3
4
5
6
[root@shana /archive/compile/httpd-2.2.22]$ ./t.sh
# checking for chosen layout... iTransit
# checking for working mkdir -p... yes
# <snip>
# config.status: creating include/ap_config_auto.h
# config.status: executing default commands

Building the Source

So the configure completed successfully, now we just run make.

Shell
1
2
3
4
5
6
[root@shana /archive/compile/httpd-2.2.22]$ make
# Making all in srclib
# Making all in os
# Making all in unix
<snip>
# /usr/local/share/apr/build-1/libtool --silent --mode=link cc -g -I/usr/local/include  -O2 -pipe -I/usr/include -fno-strict-aliasing  -rpath=/usr/lib:/usr/local/lib -L/usr/lib -L/usr/local/lib -L/usr/local/lib/db42  -rpath=/usr/lib:/usr/local/lib -L/usr/lib    -o mod_rewrite.la -rpath /usr/local/libexec/apache22 -module -avoid-version  mod_rewrite.lo

Creating the users

If you haven’t already, we’ll need to create the users. The port normally does this for you but it is a requirement that it is done. Run the following commands:

Shell
1
2
[root@shana /archive/compile/httpd-2.2.22]$ pw groupadd -n www -g 80
[root@shana /archive/compile/httpd-2.2.22]$ pw useradd -n www -u 80 -d /nonexistent -g www -s /usr/sbin/nologin

Installing Apache

Now that that is all done, lets install this beast.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[root@shana /archive/compile/httpd-2.2.22]$ make install
# Making install in srclib
# Making install in os
# Making install in unix
# <snip>
# Installing configuration files
# mkdir /var/www/conf
# mkdir /var/www/conf/extra
# mkdir /var/www/conf/original
# mkdir /var/www/conf/original/extra
# Installing HTML documents
# mkdir /var/www/htdocs
# Installing error documents
# mkdir /var/www/error
# Installing icons
# mkdir /var/www/icons
# Installing CGIs
# mkdir /var/www/cgi-bin
# Installing header files
# Installing build system files
# Installing man pages and online manual

All installed! And in the correct places too.

Creating the rc scripts

Now we just need to create the necessary rc files to control starting/stopping Apache. Fortunately ports has us covered there too. We just need some minor modifications to the ones supplied with ports in order to get our very on /usr/local/etc/rc.d/apache22 and /usr/local/etc/rc.d/htcacheclean files.

1
2
[root@shana /archive/compile/httpd-2.2.22]$ cat /usr/ports/www/apache22/files/apache22.in | sed 's/%%PREFIX%%/\/usr\/local/g' > /usr/local/etc/rc.d/apache22
[root@shana /archive/compile/httpd-2.2.22]$ cat /usr/ports/www/apache22/files/htcacheclean.in | sed 's/%%PREFIX%%/\/usr\/local/g' > /usr/local/etc/rc.d/htcacheclean

Preventing the port from installing

The other thing we will want to do is prevent the port from installing. In some cases another port will have Apache listed as a dependency. Ports, being the clever thing it is, will attempt to install those missing dependencies for you, which will blow away your custom Apache install.

Lets mark the port as forbidden, add this to the top of /usr/ports/www/apache22/Makefile:

FORBIDDEN=       Do not install. This was installed manually.

And that’s it. We’re finished.

In the next part, I’ll setup some test virtual hosts, install PHP and Subversion.

Server Build    apache, freebsd, http, ports, server build, shana
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail
← Firewalling: The OpenBSD Packet Filter
Installing Apache and Its Ecosystem: Part 2 →
Avatars by Sterling Adventures

EvoLve theme by Theme4Press  •  Powered by WordPress Odynia.org blog
I write about things.