Compiling Apache httpd from Sources
This is yet another post on Apache httpd server installation and configuration. I say another because I’ve already written about how to install the packaged version of Apache for two specific linux distros. This time I’ll quickly jot down how I configured and compiled Apache for my needs. There are a few reasons to do this. One of the more important ones being to have a newer version of Apache. It seems that prepackaged Apache versions for some linux distributions can be quite out of date. This in turn means that you don’t get the benefits of the improved newer version and more importantly leave your server vulnerable to know exploits. While having the newest version of Apache is not a guarantee that your server is well secured it sure helps. Download the unix source file httpd-2.2.15.tar.gz from the Apache httpd page to your linux server where you’ll be compiling it. Explode the downloaded file and change the directory using the commands
tar zxvf httpd-2.2.15.tar.gz cd httpd-2.2.15
There are various parameters that can be configured before compiling the server which are documented here. The number of options can be overwhelming when doing it for the first time. Though if you just want to quickly compile everything you could issue the following
./configure --prefix=/usr/local/apache2 make make install
Assuming that no errors occured you would have already installed Apache. But for my needs which include HTTPS, caching and proxying to Tomcat I would recommend the following configuration line.
./configure --prefix=/usr/local/apache2 \ --enable-mods-shared="all ssl cache proxy authn_alias mem_cache file_cache" \ --with-included-apr
This will make sure that all the useful Apache features are not compiled directly into the server but are compiled as modules which can be later turned on or off according to your needs. According to some forum (can’t find the link) it says that issuing –enable-mods-share=”all” doesn’t really compile all the modules so you have to specify some of them by hand. And the parameter –with-included-apr is recommended to make sure that Apache will use its own APR (Apache Portable Runtime) libraries and not the ones it might accidentally find installed on your system. Follow this line with the make and make install commands. One problem that I ran into when compiling Apache on different servers is that sometimes you get a similar message when running the configure line:
checking for SSL-C version... checking sslc.h usability... no checking sslc.h presence... no checking for sslc.h... no no SSL-C headers found configure: error: ...No recognized SSL/TLS toolkit detected
This means that you don’t have the development libraries installed that are needed for the SSL support in Apache. Check your distribution and install if needed the package openssl-devel (it’s called libssl-dev on debian). Thanks to this forum for the information.
Another caveat to look out for is if the configure line prints the following:
Checking whether to enable mod_deflate..... Configure: error: mod_deflate has been requested but can not be built due to prerequistie failures..
This one means that you don’t have the zlib development package installed on your distro. If using Ubuntu or Debian issue
apt-get install zlib1g-dev
If on RedHat or CentOS try this
yum install zlib-devel
After you install Apache notice that it is placed in the directory that you specified with the –prefix parameter. And the structure of the directory is different than that of the prepackaged version. But if you’ll be using the compiled version across different distros you’ll have the same directory layout which really helps in managing configurations. The /usr/local/apache/conf directory layout looks like this
. |-- extra | |-- httpd-autoindex.conf | |-- httpd-dav.conf | |-- httpd-default.conf | |-- httpd-info.conf | |-- httpd-languages.conf | |-- httpd-manual.conf | |-- httpd-mpm.conf | |-- httpd-multilang-errordoc.conf | |-- httpd-ssl.conf | |-- httpd-userdir.conf | `-- httpd-vhosts.conf |-- httpd.conf |-- magic `-- mime.types
Take note that the
.conf files in the
extra directory are not used in the configuration by default. What this means is that when starting Apache the
/usr/local/apache/conf/httpd.conf file will be read and used. Files in the extra directory will be used only if you uncomment the include lines at the end of
httpd.conf file. From here on you can configure the server as you see fit. One thing I do immediately after installing Apache is create a link to
apachectl in the
/etc/init.d directory to allow the automatic starting of the server on each boot.
ln -s /usr/local/apache/bin/apachectl /etc/init.d/httpd
Now you can start/stop Apache as any other linux server.