42

How do I enable apache modules from the command line in RedHat?

On Debian/Ubuntu systems I use a2enmod to enable modules from the command line.

Is there an equivalent for RedHat/CentOS type systems?

5 Answers 5

33

There is no equivalent.

Debian/Ubuntu butcher the apache configuration into a large number of files, where directories of mods and sites enabled are symlinked to other snippets of configuration files. The a2enmod/a2ensite scripts just manipulate these symlinks.

debian$ ls /etc/apache2/mods-enabled 
lrwxrwxrwx 1 root root 28 2009-03-12 18:02 alias.conf -> ../mods-available/alias.conf
lrwxrwxrwx 1 root root 28 2009-03-12 18:02 alias.load -> ../mods-available/alias.load
lrwxrwxrwx 1 root root 33 2009-03-12 18:02 auth_basic.load -> ../mods-available/auth_basic.load
lrwxrwxrwx 1 root root 33 2009-03-12 18:02 authn_file.load -> ../mods-available/authn_file.load
lrwxrwxrwx 1 root root 36 2009-03-12 18:02 authz_default.load -> ../mods-available/autoindex.load
lrwxrwxrwx 1 root root 26 2009-03-12 18:02 env.load -> ../mods-available/env.load
lrwxrwxrwx 1 root root 27 2009-03-12 18:02 mime.conf -> ../mods-available/mime.conf
lrwxrwxrwx 1 root root 27 2009-03-12 18:02 mime.load -> ../mods-available/mime.load
lrwxrwxrwx 1 root root 34 2009-03-12 18:02 negotiation.conf -> ../mods-available/negotiation.conf
lrwxrwxrwx 1 root root 34 2009-03-12 18:02 negotiation.load -> ../mods-available/negotiation.load
lrwxrwxrwx 1 root root 27 2009-06-16 21:47 php5.conf -> ../mods-available/php5.conf
lrwxrwxrwx 1 root root 27 2009-06-16 21:47 php5.load -> ../mods-available/php5.load

On redhat systems the apache configuration is by default held in one file /etc/httpd/conf/httpd.conf. All modules are loaded from this file, and can be disabled by commenting out the appropiate LoadModule statement.

...
LoadModule authz_default_module modules/mod_authz_default.so
LoadModule ldap_module modules/mod_ldap.so
LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
LoadModule include_module modules/mod_include.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule logio_module modules/mod_logio.so
LoadModule env_module modules/mod_env.so
LoadModule mime_module modules/mod_mime.so
LoadModule dav_module modules/mod_dav.so
...

What RedHat/CentOS are doing is giving you a pretty stock apache setup, while debian are adding their own "improvements". You could of course use the debian split config system as a template to make your own, and copy the scripts. However, the main argument for the debian setup is so that apache module packages can install their own config files, so without that it's significantly less useful


Edit: If you're looking for an equivalent way of scripting this then i suggest you use /etc/httpd/conf.d directory, any config files in here will be included. Depending on how complicated the script is it might make sense to directly write one line files into conf.d, or use symlinks for more complicated bits.

4
  • So what do i do in my new server build scripts? awk/sed craziness? Create my own config files and copy them in to place? None of these options sound appealing.
    – MarshallY
    Aug 20, 2009 at 1:19
  • 1
    I'm not sure why everyone is harshing on your answer; it correctly describes why one will not find the a2enmod scripts in Red Hat-alikes. Personally, my plan is to use puppet to manage a similar layout on my RHEL boxes. Aug 20, 2009 at 2:09
  • 1
    @womble - I think debian have taken the tiny files stuff too far, having an entire file for just setting what ports apache should listen on for example, and I think that shell scripts just to make a symlink are also a step too far - to the point where they confuse users who don't understand how their config files actually work. I wouldn't call that bitter. Aug 20, 2009 at 2:58
  • 2
    Ten years later comment, on RHEL/CentOS 7 at least, you need to check in /etc/httpd/conf.modules.d
    – cdmo
    Aug 2, 2019 at 12:38
7

Command to enable multiple modules

sudo a2enmod headers http2 proxy_fcgi rewrite setenvif ssl ...

and command to disable multiple modules

sudo a2dismod headers http2 proxy_fcgi rewrite setenvif ssl ...
1
  • 3
    a2enmod and a2dismod commands are for Debian/Ubuntu systems.
    – katronai
    Dec 22, 2022 at 8:07
4
yum list mod\*

install modules that you want

for example mod_perl

rpm -ql mod_perl.x86_64 | grep /etc/

/etc/httpd/conf.d/perl.conf
/etc/httpd/conf.modules.d/02-perl.conf

edit /etc/httpd/conf.d/perl.conf to enable it

By default, all mods are loaded when are installed, if you want not load someone

edit file in /etc/httpd/conf.modules.d/02-perl.confand comment Load line with hash sign (#)

1
  • This is the perfect answer to the Question. 'Enable' is different from 'LoadModule'. Feb 5, 2019 at 21:51
3

Typically, on a Redhat system, you'll find a line that looks like this inside /etc/httpd/conf/httpd.conf:

Include conf.d/*.conf

When you copy a configuration file into /etc/httpd/conf.d, and it has a .conf file extension, then it'll be picked up and processed as apache starts. You'll typically find configuration files for extensions like mod_php and mod_svn, and applications that are integrated with the webserver like trac, inside this folder.

Side note: for apache modules like mod_php or mod_auth_mysql on other systems that use RPM, like OpenSuSE, there may be other configuration files (like /etc/sysconfig/apache2) that need to get edited in order for apache to pick up a new module. Some of this is dependent on the system management tool that is being used, i.e. yast2. Some of it's dependent on aftermarket products that can be installed, like plesk/cpanel. However, the above folder is the best place to start.

2
  • 1
    For anyone working with Fedora 21 (and possibly other versions or other RH family distros) the module loading has been moved to a new directory called /etc/httpd/conf.modules.d/. You will see the following line in your httpd.conf Include conf.modules.d/*.conf if that is the case.
    – Night Owl
    Mar 10, 2015 at 17:48
  • And how do we enable modules here? For example for mod_socache_shmcb would I create a file in /etc/httpd/conf.modules.d like 00-socache_shmcb.so and in that file write LoadModule socache_shmcb_module modules/mod_ssl.so??
    – Vasiliki
    Oct 13, 2020 at 15:05
2

'Enable' Modules is different from "LoadModules" and Install

  • If already Installed and is offline, root user can service enable httpd
  • If modules and their conf files are not available then, root user can yum install -y <mod_name>
  • check the availability with yum list mod\*
  • If already enabled and installed, to load them to use draft it httpd.conf or *.conf files, as
    LoadModule ldap_module modules/mod_ldap.so

  • To Verify, if Loaded correctly and ready in use, apachectl -M

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .