12

I've just installed the httpd package in RHEL 6.1 (which provides Apache 2.2.15). The default httpd.conf contains no fewer than 50 instances of the LoadModule directive.

However, all I want to do is serve up static content, a Google map or two and some CSS.

Trial-and-error, along with apachectl configtest, leads me to believe that I can get away with only the following modules enabled (given no other changes to the default config file):

mod_authz_host
mod_log_config
mod_mime_magic
mod_setenvif
mod_mime
mod_autoindex
mod_negotiation
mod_dir
mod_alias

Are there modules that should be included in this list for better/safer operation of the server? The official docs seem to indicate that nothing more than mod_dir and mod_mime are absolutely necessary for a barebones site.

Note: I'm not soliciting advice on which HTTP server to use for the indicated task. I'm aware of the existence of "lighter" servers. This question is about Apache modules.

5 Answers 5

9

The answer is alluded to in the official 2.2 docs, in the section on performance tuning.

An associated question that arises here is, of course, what modules you need, and which ones you don't. The answer here will, of course, vary from one web site to another. However, the minimal list > of modules which you can get by with tends to include mod_mime, mod_dir, and mod_log_config. mod_log_config is, of course, optional, as you can run a web site without log files. This is, however, not recommended.

6

Just noticed this question as I was setting up a new PC with Apache 2.2. Here's the absolute minimum httpd.conf I managed to come up with:

    ServerName 127.0.0.1
    Listen 8080
    LoadModule dir_module modules/mod_dir.so
    LoadModule mime_module modules/mod_mime.so
    DirectoryIndex index.html 
    DocumentRoot "C:/http_root"
    ErrorLog "logs/error.log"
    LogLevel warn                

You don't need the ErrorLog of course, but I was experimenting so obviously needed some feedback if my httpd.conf file was causing problems. You need ServerName to avoid a warning during startup about not being able to reliably determine the server address. I can certainly confirm that you do need dir_module and mime_module so that you can deliver a default file from a directory URL and also display the file as HTML rather than plain text.

I'm posting this because I find the default httpd.conf file overwhelmingly complicated and I remembered that when I was learning Tomcat, everything became a lot clearer when I discovered the absolute minimum server configuration file.

If you want to server php pages, you just need the following 2 lines (adjusted to suit your environment:

PHPIniDir "C:/php/"
LoadModule php5_module "C:/php/php5apache2_2.dll"
1
  • it would be useful to see this for Linux, Red hat in my case. Am trying above but it's taking quite a bit of modification and still won't redirect to the html file I'm interested in.
    – alimack
    May 20, 2016 at 12:54
1

This took a morning to work out by trial and error but on Red hat 6 (ish) this works, note I've had to override an existing .htaccess file that I can't change. This will point to offline.html in your root directory

ServerName 127.0.0.1
Listen 80
TypesConfig /etc/mime.types
LoadModule dir_module modules/mod_dir.so
LoadModule mime_module modules/mod_mime.so
LoadModule rewrite_module modules/mod_rewrite.so

User apache
Group apache
DocumentRoot "/homedir/"
DirectoryIndex offline.html
ErrorLog "/homedir/error.log"
LogLevel warn  

<Directory />
AllowOverride None
</Directory>

If you don't need to override htaccess file you could probably get away with this (assuming you want error logging):

ServerName 127.0.0.1
Listen 80
TypesConfig /etc/mime.types
LoadModule dir_module modules/mod_dir.so
LoadModule mime_module modules/mod_mime.so

User apache
Group apache
DocumentRoot "/homedir/"
DirectoryIndex offline.html
ErrorLog "/homedir/error.log"
LogLevel warn  
0

There is a standard minimal configuration here

https://cwiki.apache.org/confluence/display/HTTPD/Minimal+Config

You might have to make some amendments for your distro.

So this one is apache 2.4 linux

# Apache httpd v2.4 minimal configuration
# This can be reduced further if you remove the accees log and mod_log_config
ServerRoot "/usr/httpd"

# Minimum modules needed
LoadModule mpm_event_module modules/mod_mpm_event.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule mime_module modules/mod_mime.so
LoadModule dir_module modules/mod_dir.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule unixd_module modules/mod_unixd.so

TypesConfig conf/mime.types

PidFile logs/httpd.pid

# Comment this out if running httpd as a non root user
User nobody

# Port to Listen on
Listen *:8080

# In a basic setup httpd can only serve files from its document root
DocumentRoot "/usr/httpd/htdocs"

# Default file to serve
DirectoryIndex index.html

# Errors go to their own log
ErrorLog logs/error_log

# Access log
LogFormat "%h %l %u %t \"%r\" %>s %b" common
CustomLog logs/access_log common

# Never change this block
<Directory />
  AllowOverride None
  Require all denied
</Directory>

# Allow documents to be served from the DocumentRoot
<Directory "/usr/httpd/htdocs">
  Require all granted
</Directory>

I'm no expert, but I did one for debian a long time back, that looks like below.

# Apache httpd v2.4 minimal configuration
# This can be reduced further if you remove the accees log and mod_log_config


#ServerRoot "/usr/httpd"
ServerRoot "/etc/apache2"

# LoadModule..........


IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf



DefaultRuntimeDir ${APACHE_RUN_DIR}
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn


# Port to Listen on
Listen *:80

# In a basic setup httpd can only serve files from its document root
#DocumentRoot "/usr/httpd/htdocs"
#DocumentRoot "/usr/apache2/"


#this line is in the 000 conf in sites-available.. so i've included it here. It was in virtualhost.. 
# I haven't included that file..
#
DocumentRoot "/var/www/html"



<Directory />
        Options FollowSymLinks
        AllowOverride None
        Require all denied
</Directory>


<Directory /usr/share>
        AllowOverride None
        Require all granted
</Directory>

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

<Directory /var/www/html>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>



# ---------

Note- They move the URL sometimes e.g. it used to be https://wiki.apache.org/confluence/display/HTTPD/Minimal+Config https://web.archive.org/web/20140701114754/https://wiki.apache.org/httpd/Minimal_Config

0

I am researching and testing and I found that this works in Amazon Linux 2023 OS with Apache/2.4.56. You can even minimize it further by remove the Removable sections.

# ********** #
# Operating System: Amazon Linux 2023
# Apache Server version: Apache/2.4.56 (Amazon Linux)
# Apache Server built:   Mar 15 2023 00:00:00
# ********** #

Listen 80
DocumentRoot "/var/www/html"
DirectoryIndex index.html

# Required modules
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule dir_module modules/mod_dir.so
LoadModule unixd_module modules/mod_unixd.so
LoadModule mpm_event_module modules/mod_mpm_event.so
LoadModule systemd_module modules/mod_systemd.so

# Removable
# This is to suppress warning message AH00558: httpd: Could not reliably determine the server's fully qualified domain name
ServerName 127.0.0.1

# Removable
# Just to suppress warning message in logs/error_log
User nobody
Group nobody

# Removable if you don't need logs
ErrorLog "logs/error_log"
LogLevel warn

# Strangely I don't need the mime modules to work. The file is displayed in HTML just fine

Comments are welcome. I have not tried this in Debian or other Fedora/CentOS based distribution. Amazon Linux 2023 itself is based on a mix of Fedora and CentOS 9 Stream distribution.

You must log in to answer this question.

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