Serving Information Simply

Time to Read

8 minutes

How to install Apache on Ubuntu

Apache web server is the most extensively used open-source web server supported on most of the OS including Linux, Windows, MacOS, Solaris, etc. It is highly customizable and can be integrated with other modules. Installing and configuring Apache for basic setup is quite easy. This article will explain how to install and configure the Apache web server on Ubuntu operating system.

  • Login to Ubuntu Machine

First login to Ubuntu CLI access via SSH

  • Elevate the access to root user

Type “sudo – i” and type root password to get root level access. This step is necessary otherwise you cannot be able to install the patches and Apache.

    sudo –i
  • Upgrade the Ubuntu

Type “apt update” and “apt upgrade” to allow Ubuntu to fetch new patch and update it.

    apt update
apt upgrade
  • Install the latest Apache packages

Type “apt install apache2” and “apt install apache2-utils” to install Apache packages including the Apache utilities tools.

    apt install apache2
apt install apache2-utils
  • Check Apache status and version

Type “systemctl is-active apache2” to activate Apache

    systemctl is-active apache2

Type “systemctl status apache2” – to see Apache’s services are ruining or not

    systemctl status apache2

Type “apache2 -version” to see the Apache version

    apache2 -version

Type “apache2ctl configtest” to check syntax of config file is ok or not.

    apache2ctl configtest
  • Allow Apache for Ubuntu firewall

First check if Ubuntu Firewall is enabled or not using below command:

    ufw status

If Ubuntu firewall is enabled, then you need to allow Apache application otherwise no need to allow it.

Enable Ubuntu Firewall

    ufw enable

“ufw reload” to reload firewall services

    ufw reload
    ufw app list

Here you can see different Apache profiles.

You can use below command to allow Apache from Ubuntu firewall:

    ufw allow “apache full”
ufw allow “apache”
ufw allow “apache secure”

Check status

    ufw status
  • Edit FQDN name to resolve warning message

When you see Apache status you can see one waring as well for FQDN name to resolve issue you can enter FQDN name for your web server.

You can edit “nano /etc/apache2/apache2.conf” file and add server name as below

    nano /etc/apache2/apache2.conf

Save and close this file and run “systemctl status apache2” again but this time you will not see warning message. If it is still showing same error please restart Apache services.

    systemctl status apache2
  • Restart/Reload Apache services

To restart Apache services “systemctl restart apache2”

    systemctl restart apache2

To reload Apache services “systemctl reload apache2”

    systemctl reload apache2

  • Check Apache files

To check Apache files, you can navigate to “cd /etc/apache2”

    cd /etc/apache2


“ls -lah /etc/apache2”

    ls -lah /etc/apache2
  • Access Apache default website

Check the Ubuntu assigned IP type “hostname -I”

    hostname -I

Access using http://<FQDN> or IP-addr

You will be able to see the website

  • Detailed information about Apache file system

Apache is configured by placing directives in plain text configuration files. These directives are separated between the following files and directories:

apache2.conf: the main Apache2 configuration file. Contains settings that are global to Apache2.

httpd.conf: historically the main Apache2 configuration file, named after the httpd daemon. In other distributions (or older versions of Ubuntu), the file might be present. In Ubuntu, all configuration options have been moved to apache2.conf and the below referenced directories, and this file no longer exists.

conf-available: this directory contains available configuration files. All files that were previously in /etc/apache2/conf.d should be moved to /etc/apache2/conf-available.

conf-enabled: 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.

envvars: file where Apache2 environment variables are set.

mods-available: this directory contains configuration files to both load modules and configure them. Not all modules will have specific configuration files, however.

mods-enabled: 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.

ports.conf: houses the directives that determine which TCP ports Apache2 is listening on.

sites-available: this directory has configuration files for Apache2 Virtual Hosts. Virtual Hosts allow Apache2 to be configured for multiple sites that have separate configurations.

sites-enabled: like mods-enabled, sites-enabled contains symlinks to the /etc/apache2/sites-available directory. Similarly, when a configuration file in sites-available is symlinked, the site configured by it will be active once Apache2 is restarted.

magic: instructions for determining MIME type based on the first few bytes of a file.

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.


Leave a Reply

Sanchit Agrawal

Blog Author


Discover more from Sanchit Gurukul

Subscribe now to keep reading and get access to the full archive.

Continue Reading

%d bloggers like this: