Apache is one of the most used HTTP server worldwide. It is known for is configurability and modularity. a very popular HTTP server. This guide helps you deploy an Apache 2 HTTP server on Debian GNU / Linux.

This howto is tested with:

  • Debian 10.0 Buster

This howto is tested with these versions of the software:

  • 2.4.38

Installation

Detect if sudo is available (“command” is used if not):

cmdProxy='command'
command type -f 'sudo' &>'/dev/null' && cmdProxy='sudo'

Install the HTTP server:

${cmdProxy} apt-get install 'apache2'

Start the server at boot:

${cmdProxy} systemctl enable 'apache2'

Enable the URL rewriting, SSL and HTTP2 modules:

${cmdProxy} a2enmod 'rewrite' 'ssl' 'http2'

Reload the server configuration:

${cmdProxy} systemctl force-reload 'apache2'

Redirect ‘www-data’ system user’s e-mails to the ‘root’ account:

[[ -e '/etc/aliases' && -z "$(command grep '^www-data:' '/etc/aliases' )" ]] \
    && ${cmdProxy} sed -i -e '/^root:/i\
www-data: root' \
      '/etc/aliases'

Reload the aliases configuration:

command type -f 'newaliases' &>'/dev/null' && ${cmdProxy} newaliases

Next steps

This howto recommends:

PHP

This howto recommends the installation of PHP by following:

If using PHP-FPM is not convenient, install PHP as an Apache 2 module:

${cmdProxy} apt-get -y install libapache2-mod-php
# enable the installed module
command find '/etc/apache2/mods-available/' -name 'php*.conf' \
   | command sort \
   | command tail -n 1 \
   | command sed -e 's|^.*/\(.*\).conf$|\1|' \
   | ${cmdProxy} xargs a2enmod
# Reload the server configuration
${cmdProxy} systemctl force-reload 'apache2'

Administration

These commands are used to manage the Apache 2 server :

  • a2enmod: Enable a module (the available modules configurations are in ‘/etc/apache2/mods-available’).
  • a2dismod: Disable an active module (the enabled modules configurations are in ‘/etc/apache2/mods-enabled’)
  • a2ensite: Enable a site (the available sites configurations are in ‘/etc/apache2/sites-available’)
  • a2dissite: Disable a site (the enabled sites configurations are in ‘/etc/apache2/sites-enabled’)
  • apache2ctl: Advanced administration tool for Apache 2.

Test Apache 2 configuration (allow to detect configuration errors without applying the new configuration) :

sudo apache2ctl -t

Reload server configuration without interrupting the service :

sudo systemctl 'reload' 'apache2'

Reload the server configuration by restarting the server without closing existing connections (no HTTP error) :

sudo systemctl 'force-reload' 'apache2'

Reload the server configuration by closing existing connections (a HTTP error is displayed to the user) :

sudo systemctl 'restart' 'apache2'

List enabled Apache 2 modules :

sudo apache2ctl -t -D 'DUMP_MODULES'

Bibliography

Thanks

Categories: Apache 2

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.