Open main menu

Changes

1,980 bytes added ,  21:46, 27 October 2008
New page: == a2enmod == is a shell script provided on Debian, and Debian-based Linux systems for quickly enabling extension modules of the Apache web server. From the manual: <cite> '''a2enmod''' ...
== a2enmod ==
is a shell script provided on Debian, and Debian-based Linux systems for quickly enabling extension modules of the Apache web server.

From the manual:
<cite>
'''a2enmod''' is a script that enables the specified module within the '''apache2''' configuration. It does this by creating symlinks within <code>/etc/apache2/mods-enabled</code>. Likewise, '''a2dismod''' disables a module by removing those symlinks. It is not an error to enable a module which is already enabled, or to disable one which is already disabled.
</cite>

If you've never looked at a shell script before, and tutorials seem too basic, then here is an example of a more complete shell script:

<code>/usr/sbin/a2enmod</code>
<source lang="bash">
#!/bin/sh -e

SYSCONFDIR='/etc/apache2'

if [ -z $1 ]; then
echo "Which module would you like to enable?"
echo -n "Your choices are: "
ls /etc/apache2/mods-available/*.load | \
sed -e "s,$SYSCONFDIR/mods-available/,,g" | sed -e 's/\.load$//g;' | xargs echo
echo -n "Module name? "
read MODNAME
else
MODNAME=$1
fi

#figure out if we are on a prefork or threaded mpm
if [ -x /usr/sbin/apache2 ]; then
PREFORK=`/usr/sbin/apache2 -l | grep -E 'prefork|itk' || true`
fi

if [ "$MODNAME" = "cgi" ] && [ -z $PREFORK ]; then
MODNAME="cgid"
echo "Your MPM seems to be threaded. Selecting cgid instead of cgi."
fi

if [ -e $SYSCONFDIR/mods-enabled/$MODNAME.load ]; then
echo "This module is already enabled!"
exit 0
fi

if ! [ -e $SYSCONFDIR/mods-available/$MODNAME.load ]; then
echo "This module does not exist!" >&2
exit 1
fi

DEPENDS=`grep "# Depends:" $SYSCONFDIR/mods-available/$MODNAME.load|cut -f2 -d:`
if [ ! -z "$DEPENDS" ]; then
for i in $DEPENDS; do
echo "Enabling $i as a dependency"
/usr/sbin/a2enmod "$i";
done
fi
</source>

[[Category:Apache]]
[[Category:System Administration]]
4,558

edits