How to install Apache2
The Apache HTTP Server (“httpd”) is the most commonly used web server on Linux systems, and is often used as part of the LAMP configuration. In this guide, we will show you how to install and configure Apache2, which is the current release of “httpd”.
To install Apache2, enter the following command at the terminal prompt:
sudo apt install apache2
Apache2 is configured by placing directives in plain text configuration files in
/etc/apache2/. These directives are separated between the following files and directories:
The main Apache2 configuration file. Contains settings that are global to Apache2.
Note: Historically, the main Apache2 configuration file was
httpd.conf, named after the “httpd” daemon. In other distributions (or older versions of Ubuntu), the file might be present. In modern releases of Ubuntu, all configuration options have been moved to
apache2.confand the below referenced directories and
httpd.confno longer exists.
File where Apache2 environment variables are set.
Instructions for determining MIME type based on the first few bytes of a file.
Houses the directives that determine which TCP ports Apache2 is listening on.
In addition, other configuration files may be added using the Include directive, and wildcards can be used to include many configuration files. Any directive may be placed in any of these configuration files. Changes to the main configuration files are only recognized by Apache2 when it is started or restarted.
The server also reads a file containing MIME document types; the filename is set by the TypesConfig directive, typically via
/etc/apache2/mods-available/mime.conf, which might also include additions and overrides, and is
/etc/mime.types by default.
This directory contains available configuration files. All files that were previously in
/etc/apache2/conf.dshould be moved to
Holds symlinks to the files in
/etc/apache2/conf-available. When a configuration file is symlinked, it will be enabled the next time Apache2 is restarted.
This directory contains configuration files to both load modules and configure them. Not all modules will have specific configuration files, however.
Holds symlinks to the files in
/etc/apache2/mods-available. When a module configuration file is symlinked it will be enabled the next time Apache2 is restarted.
This directory has configuration files for Apache2 Virtual Hosts. Virtual Hosts allow Apache2 to be configured for multiple sites that have separate configurations.
sites-enabledcontains symlinks to the
/etc/apache2/sites-availabledirectory. Similarly, when a configuration file in
sites-availableis symlinked, the site configured by it will be active once Apache2 is restarted.
For more detailed information on configuring Apache2, check out our follow-up guides.
Apache2 Documentation contains in depth information on Apache2 configuration directives. Also, see the
apache2-docpackage for the official Apache2 docs.
O’Reilly’s Apache Cookbook is a good resource for accomplishing specific Apache2 configurations.
For Ubuntu-specific Apache2 questions, ask in the #ubuntu-server IRC channel on libera.chat.