[APACHE SERVER]

Apache 2.2 module mod_macro 1.1.10

Contents


Summary

mod_macro is a third-party module to the Apache Http Server, distributed with a BSD-style license like Apache.
It allows the definition and use of macros within apache runtime configuration files.
The syntax is a natural extension to apache html-like configuration style.


Examples

Here is a sample use of mod_macro within a configuration file:
## Define a VHost Macro.

<Macro VHost $host $port $dir>
  Listen $port
  <VirtualHost $host:$port>

    DocumentRoot $dir

    <Directory $dir>
      # do something here...
    </Directory>

    # limit access to intranet subdir.
    <Directory $dir/intranet>
      order deny,allow
      deny from all
      allow from 10.0.0.0/8
    </Directory>
  </VirtualHost>
</Macro>

## Use of VHost with different arguments.

Use VHost www.apache.org 80 /projects/apache/web
Use VHost www.perl.com 8080 /projects/perl/web
Use VHost www.ensmp.fr 1234 /projects/mines/web

## Done.

A simple example is presented in issue 144 of Apache Week.

Another example shows how to simplify mod_perl configuration with mod_macro.

Some promotion by Jim Jagielski at ApacheCon reported on Trouble Shooters by Steve Litt.


Benefits

You may have several benefits from using macros in configuration files.

Download

The current version for Apache 2.2 is 1.1.10. For Apache 2.0, use 1.1.6. It won't work with Apache 1.3 for which you should use version 1.1.2. If you have version 1.0.13 or earlier, consider upgrading.
It is available is several formats, signed with

Standard SHA1 and MD5 digests are also available.

You can also browse the source directory:


License

This software is made available as a third-party apache module, under the terms of a BSD-style license, just like Apache. The license is included in the distribution. See http://www.opensource.org/ for a discussion about open source licenses.

Versions prior to 1.1.0 were distributed under the terms of the GNU General Public License version 2 or later. However it does not allow commercial version of the software to be derived, hence the switch.


Install

Installing the mod_macro module with apache is rather simple, especially with apxs. Here is a sample direct installation with apache 2.2.0:


History of versions


Motivation

I hate copy-paste.

When configuring the apache server I often have to copy-paste some parts, especially with virtual hosts to enable similar features or options. In order to avoid this, I would need some kind of macro capabilities in the server runtime configuration files.

Apache already includes preprocessor features such as <IfDefine> and Include. This is not enough for me.

There are several existing processors with macro capabilities such as cpp and m4. However, they need assumptions about the lexical structure of the files, that we cannot have with apache. Moreover they cannot be integrated with the apache html-like configuration style.

The apache-perl integration allows <Perl> sections within the configuration file. These sections could be of some use with subroutines and so, but it requires mod_perl and to change my habits a lot. Furthermore, I do not like perl.

So I end up with deciding to implement a macro extension module to apache.

In my opinion, this stuff MUST NOT grow to a full language.

It should just grow to what is needed to manage configuration files simply and elegantly, and to avoid unnecessary copy-pastes. I may consider adding a foreach repetition section, if proven useful. I may also consider reimplementing a working Include since the current one does not work properly (bug #3169/#3578).

But no while, no arithmetics, no variables, no recursion, no goto, no sql, no extended regexpr... Never: I'll stick to the KISS Principle. (Keep It Simple, Stupid!)

My purpose is easier apache configuration file maintenance, not general purpose programming. If you want actual programming, consider perl sections (or embed another programming language like tcl or python).


Specification

I gave myself the following requirements:

Author

The author and maintainer of this module is: Fabien Coelho
mod_macro: http://www.coelho.net/mod_macro/
E-mail: mod.macro@coelho.net
URL: http://www.coelho.net/
PGP: signature

CRI, École des mines de Paris,
35, rue Saint-Honoré,
77305 Fontainebleau cedex,
FRANCE.