Making my FreeBSD productive – Installing Apache httpd

 

Yet my FreeBSD VM didn’t do a lot. I installed it to run an http-server together with Foswiki on it. Today I am moving forward. I will install the apache http-server and describe the procedure here. There is no magic at all – only odds.

The previous blog related to this article was Installation and Basic Configuration of FreeBSD 10.1

Again I will install from source. It’s only a few days ago, when I downloaded a copy of httpd, but I better have another look at the web site of the apache project. In this case I look at

https://httpd.apache.org/

If you need to download the latest version of httpd, don’t forget to check the checksum. Apache provides several message digests. I usually take the sha1

    openssl dgst -sha1 httpd-2.4.16.tar.bz2
    SHA1(httpd-2.4.16.tar.bz2)= 9963e7482700dd50c53e47abfe2d1c5068875a9c

But before we really start, we need to meet a few prerequisites.

  1. “Apache Portable Runtime library” APR needs to be installed
    http://apr.apache.org
    and
  2. the related utilities apr-util
    http://apr.apache.org
    and
  3. the Perl Compatible Regular Expresssions PCRE (not PCRE2)
    http://pcre.org
  4. you’ll need lynx. It will be necessary to use the compiled httpd
    I’ll install it prior to running httpd.

Without these three installed on your system, httpd will not compile.

So go out and get the tar-balls for these three. You may download the stuff with your browser I’ll do it this way:

#
# Example
#
$ wget http://mirror.dkd.de/apache//apr/apr-1.5.2.tar.bz2
$ wget http://www.apache.org/dist/apr/apr-1.5.2.tar.gz.md5
$ wget http://mirror.dkd.de/apache//apr/apr-util-1.5.4.tar.bz2
$ wget http://www.apache.org/dist/apr/apr-util-1.5.4.tar.bz2.md5
$ cat apr-1.5.2.tar.bz2.md5
4e9769f3349fe11fc0a5e1b224c236aa *apr-1.5.2.tar.bz2
$ openssl dgst -md5 apr-1.5.2.tar.bz2
SHA1(apr-1.5.2.tar.bz2)= 6d757fcf7c687fc300c1066076f2e8380ff8cbc0
$ cat apr-util-1.5.4.tar.bz2.md5
2202b18f269ad606d70e1864857ed93c *apr-util-1.5.4.tar.bz2
$ openssl dgst -md5 apr-util-1.5.4.tar.bz2
$ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.bz2

Note:
configure requires for apr-util the parameter –with-apr=/usr/local/apr (provided you installed it at the default location, which is /usr/local/apr

Compiling the three is pretty straight forward:

  1. You extract the sources to a place of your convenience (I use /usr/local/packages)
  2. You cd to the according directory (first go to apr, then apr-util….)

This may look like this:

    cd /usr/local/packages/apr-1.5.2
    ./configure
    make; make install
    cd ../apr-util-1.5.4
    ./configure --with-apr=/usr/local/apr
    make; make install
    cd ../pcre-8.37
    ./configure
    make; make install

And then do the same with httpd:

     cd ../httpd-2.4.16
    ./configure
    make; make install

It is really simple, but it quickly becomes embarrassing, if you forget the prerequisites.

cd to /usr/local to see, what we have done

    ls -lrt
    total 8272
    -r--------   1 root  wheel     8388608 Jul 23 18:08 .sujournal
    drwxrwxr-x   2 root  operator      512 Jul 23 18:08 .snap
    drwxr-xr-x   2 root  wheel         512 Jul 24 13:31 sbin
    drwxr-xr-x   3 root  wheel         512 Jul 24 13:31 libdata
    drwxr-xr-x   5 root  wheel         512 Jul 24 13:41 etc
    drwxr-xr-x   6 root  wheel         512 Jul 24 13:41 man
    drwxr-xr-x   6 root  wheel         512 Jul 31 19:06 apr
    drwxr-xr-x   6 root  wheel         512 Jul 31 19:34 share
    drwxr-xr-x   7 root  wheel         512 Jul 31 19:39 packages
    drwxr-xr-x   4 root  wheel        1024 Jul 31 20:02 lib
    drwxr-xr-x   2 root  wheel        1024 Jul 31 20:02 bin
    drwxr-xr-x   2 root  wheel         512 Jul 31 20:02 include
    drwxr-xr-x  14 root  wheel         512 Jul 31 20:06 apache2

Of course we are not finished.

Apache is not running yet!

The fact, that the software is compiled, doesn’t mean it would run.
Let’s see.
I am on a FreeBSD. So, here I describe how I install software from the ports collection.

pkg install lynx

This will require a little user interaction – it’ll ask you for a ‘y’ or ‘N’.

Another nice thing is to get ksh installed!

pkg install pdksh

Now you can start ksh and proceed:

ksh
export MANPATH=/usr/local/apache2/man

And now such practical things like

man apachectl

will be available and you can do a

set -o vi

and subsequently such nice things like

[esc]-k

to go through the shell-history with the vi-cursor-keys.

Next we need to set the ServerName directive in the configuration file

/usr/local/apache2/conf/httpd.conf

Open this file and set the directive to a reasonable value.
My value looks like this:

ServerName light-relief.schlichting.net:80

Since we are using port 80, we need to start httpd as root

/usr/local/apache2/bin/apachectl -f /usr/local/apache2/conf/httpd.con

and the ps command shows us the following:

ps agux | grep http
root 36354 0.0 0.2 69676 4568 - Ss 10:09PM 0:00.02 /usr/local/apache2/bin/httpd -f /usr/local/apach
daemon 36355 0.0 0.3 73172 5392 - S 10:09PM 0:00.03 /usr/local/apache2/bin/httpd -f /usr/local/apach
daemon 36356 0.0 0.3 73172 5392 - S 10:09PM 0:00.02 /usr/local/apache2/bin/httpd -f /usr/local/apach
daemon 36357 0.0 0.3 73172 5392 - S 10:09PM 0:00.03 /usr/local/apache2/bin/httpd -f /usr/local/apach
root 36359 0.0 0.0 380 288 0 R+ 10:09PM 0:00.00 grep http

If you now enter in your browser an URL like this

http://192.168.10.63

you should see the two words “It works!

Apache httpd works
Apache httpd works (here in the Midori-browser)

Of course we are far from being finished, but we have accomplished an important milestone.

Now the real work begins. There are tons of directives to be set in httpd’s configuration files. You will have to dig into the documentation. Many of the directives may not be applicable for you, just as they will not be applicable for my application. I won’t go into that, because a book on Apache httpd comes close to 1000 pages and I do not intend to go so far.

Next I will install Foswiki and this was the only reason, why I installed Apache httpd.

The previous blog related to this article was Installation and Basic Configuration of FreeBSD 10.1