> ## Content Index
> Fetch the complete content index at: https://www.binarysludge.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# BASH script to remove superfluous Apache/httpd modules
- URL: https://www.binarysludge.com/2012/04/13/bash-script-to-remove-superfluous-apachehttpd-modules/
- Published: 2012-04-13T10:00:16.000Z
- Updated: 2012-04-12T22:39:51.000Z
- Author: Andrew Martin
- Tags: Apache, bash, linux, Memory, system adminstration, #Import 2026-10-22 12:56

`httpd` comes with a lot of modules enabled by default. Run this simple `BASH` script to remove them all, re-instate those required for a default install (`configtest` will reveal the errors without loading the broken config) and salt to taste:

CONFIG=/etc/httpd/conf/httpd.conf
sed 's/^LoadModule/#LoadModule/g' -ie $CONFIG 

ALLOWED_MODULES="mime_module dir_module log_config_module authz_host_module alias_module autoindex_module negotiation_module setenvif_module rewrite_module" 

for MODULE in $ALLOWED_MODULES; do
  sed "s/^#\(LoadModule $MODULE.*\)/\1/g" $CONFIG | grep $MODULE
  sed "s/^#\(LoadModule $MODULE.*\)/\1/g" -i $CONFIG
done  

/etc/init.d/httpd configtest && /etc/init.d/httpd graceful