Difference between revisions of "A2enmod"

From Freephile Wiki
Jump to navigation Jump to search
(adds usage)
(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''' ...)
(One intermediate revision by the same user not shown)
Line 7: Line 7:
 
</cite>
 
</cite>
  
== Source ==
 
 
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:
 
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:
  
Line 17: Line 16:
  
 
if [ -z $1 ]; then
 
if [ -z $1 ]; then
echo "Which module would you like to enable?"
+
        echo "Which module would you like to enable?"
echo -n "Your choices are: "
+
        echo -n "Your choices are: "
ls /etc/apache2/mods-available/*.load | \
+
        ls /etc/apache2/mods-available/*.load | \
sed -e "s,$SYSCONFDIR/mods-available/,,g" | sed -e 's/\.load$//g;' | xargs echo
+
        sed -e "s,$SYSCONFDIR/mods-available/,,g" | sed -e 's/\.load$//g;' | xargs echo
echo -n "Module name? "
+
        echo -n "Module name? "
read MODNAME
+
        read MODNAME
 
else
 
else
MODNAME=$1
+
        MODNAME=$1
 
fi
 
fi
  
 
#figure out if we are on a prefork or threaded mpm
 
#figure out if we are on a prefork or threaded mpm
 
if [ -x /usr/sbin/apache2 ]; then
 
if [ -x /usr/sbin/apache2 ]; then
PREFORK=`/usr/sbin/apache2 -l | grep -E 'prefork|itk' || true`
+
        PREFORK=`/usr/sbin/apache2 -l | grep -E 'prefork|itk' || true`
 
fi
 
fi
  
 
if [ "$MODNAME" = "cgi" ] && [ -z $PREFORK ]; then
 
if [ "$MODNAME" = "cgi" ] && [ -z $PREFORK ]; then
MODNAME="cgid"
+
        MODNAME="cgid"
echo "Your MPM seems to be threaded. Selecting cgid instead of cgi."
+
        echo "Your MPM seems to be threaded. Selecting cgid instead of cgi."
 
fi
 
fi
  
 
if [ -e $SYSCONFDIR/mods-enabled/$MODNAME.load ]; then
 
if [ -e $SYSCONFDIR/mods-enabled/$MODNAME.load ]; then
echo "This module is already enabled!"
+
        echo "This module is already enabled!"
exit 0
+
        exit 0
 
fi
 
fi
  
 
if ! [ -e $SYSCONFDIR/mods-available/$MODNAME.load ]; then
 
if ! [ -e $SYSCONFDIR/mods-available/$MODNAME.load ]; then
echo "This module does not exist!" >&2
+
        echo "This module does not exist!" >&2
exit 1
+
        exit 1
 
fi
 
fi
  
 
DEPENDS=`grep "# Depends:" $SYSCONFDIR/mods-available/$MODNAME.load|cut -f2 -d:`
 
DEPENDS=`grep "# Depends:" $SYSCONFDIR/mods-available/$MODNAME.load|cut -f2 -d:`
 
if [ ! -z "$DEPENDS" ]; then
 
if [ ! -z "$DEPENDS" ]; then
for i in $DEPENDS; do
+
        for i in $DEPENDS; do
echo "Enabling $i as a dependency"
+
                echo "Enabling $i as a dependency"
/usr/sbin/a2enmod "$i";
+
                /usr/sbin/a2enmod "$i";
done
+
        done
 
fi
 
fi
 
</source>
 
</source>
 
== Enabling a Module ==
 
If you don't know the exact name of the module you want to enable, you can invoke a2enmod without any arguments and it will output a list of the modules available on your host.
 
<source lang="bash">
 
sudo a2enmod
 
Your choices are: actions alias asis auth_basic auth_digest authn_alias authn_anon authn_dbd authn_dbm authn_default authn_file authnz_ldap authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cern_meta cgi cgid charset_lite dav dav_fs dav_lock dav_svn dbd deflate dir disk_cache dump_io env expires ext_filter file_cache filter headers ident imagemap include info ldap log_forensic mem_cache mime mime_magic negotiation php5 proxy proxy_ajp proxy_balancer proxy_connect proxy_ftp proxy_http rewrite setenvif speling ssl status substitute suexec unique_id userdir usertrack version vhost_alias
 
Which module(s) do you want to enable (wildcards ok)?
 
</source>
 
Press 'Enter' to simply exit the script without making a selection.
 
 
If you do supply an argument (module name) to a2enmod, then the script will enable the module for you and give you some additional instructions to restart Apache
 
 
== Disabling a Module ==
 
Similarly, modules can be disabled by using '''a2dismod'''
 
  
 
[[Category:Apache]]
 
[[Category:Apache]]
 
[[Category:System Administration]]
 
[[Category:System Administration]]
[[Category:Applications]]
 

Revision as of 20:46, 27 October 2008

a2enmod[edit | edit source]

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: a2enmod is a script that enables the specified module within the apache2 configuration. It does this by creating symlinks within /etc/apache2/mods-enabled. 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.

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:

/usr/sbin/a2enmod

#!/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