How to Install Apache On Ubuntu 24.04

Introduction

Apache webserver dominates the market and serves millions of websites. It supports Windows and Linux, hosting both static and dynamic websites, and serves web applications built with PHP, Python, and Ruby. Apache can also function as a reverse proxy, load balancer, and handle SSL/TLS encryption. Its extensive modules and configurations provide a robust and flexible web hosting solution.

This guide shows you how to install Apache on Ubuntu 24.04.

Prerequisites

Before you begin, ensure you've:

Install Apache

Apache is available on the Ubuntu software repositories. Follow the steps below to install Apache using the Ubuntu APT package manage:

  1. Update your server's package information index.

    CONSOLE
    $ sudo apt update
    
  2. Type the command below to Install Apache.

    CONSOLE
    $ sudo apt install apache2 -y
    
  3. Allow Apache ports through the firewall

    CONSOLE
    $ sudo ufw allow 80
    $ sudo ufw allow 443
    

    Output:

    Rule added
    Rule added (v6)
    
  4. Reload the firewall to effect the new changes.

    CONSOLE
    $ sudo ufw reload
    

    Output:

    Firewall reloaded
    
  5. Open a web browser, such as Chrome, Mozilla or Windows Explorer, and enter your Ubuntu server's public IP address.

    http://198.168.0.1
    
  6. Ensure your browser displays the default Apache web page.

    default-ubuntu-24-apache-web-page.png

Configure Common Apache Modules

Apache allows you to run website and web applications. In most cases, you'll integrate Apache with a scripting language like PHP and a database server like MySQL. To ensure your website and applications run smoothly, enable the following common Apache modules:

Enable Apache mod_rewrite

This module allows Apache to create pretty URLs on a website. Enable mod_rewrite.

CONSOLE
$ sudo a2enmod rewrite

Enable Apache mod_deflate

The Apache mod_deflate saves bandwidth by compressing output from your websites or web applications before sending it to browsers. Enable mod_deflate.

CONSOLE
$ sudo a2enmod deflate

Enable Apache mod_authz_host

Mod_authz_host controls access to particular files on the webserver. Enable mod_authz_host.

CONSOLE
$ sudo a2enmod authz_host

Enable Apache mod_headers

CONSOLE
$ sudo a2enmod headers

Restart Apache to enable the changes above by typing the below Linux command:

CONSOLE
$ sudo service apache2 restart

Understand Apache Configurations

You should familiarize yourself with the Apache settings and directory structure to make troubleshooting easier. Here are the most basic files and directories that configure Apache

  • /etc/apache2/apache2.conf: Contains global setting files for Apache.
  • /etc/apache2/conf-available: Stores all available configuration files for Apache.
  • /etc/apache2/conf-enabled: Stores symbolic links to all files in the /etc/apache2/conf-available directory. When you add a symbolic link in this directory, it will be automatically loaded/enabled when Apache starts.
  • /etc/apache2/envvars: Sets Apache environment variables.
  • /etc/apache2/mods-available: Stores Apache modules and their configurations. However, some modules may not have a configuration file.
  • /etc/apache2/mods-enabled: Stores symbolic links to the files in the /etc/apache2/mods-available directory. When you create a symbolic link for a module in this directory, it will be enabled when Apache starts.
  • /etc/apache2/ports.config: Contains basic settings that direct Apache on which ports to listen to.
  • /etc/apache2/sites-available: Stores all the settings for virtual hosts. Apache comes with a default virtual host named /etc/apache2/sites-available/000-default.conf. You can copy this file to create additional virtual hosts to host multiple websites on the same Apache server.
  • /etc/apache2/sites-enabled: Stores symbolic links for the /etc/apache2/sites-available directory. When you create a symbolic link in this directory, the site is enabled when Apache starts.
  • /etc/apache2/magic: Contains instructions that determine the MIME type of a file.

Conclusion

You've installed Apache on Ubuntu 24.04. You started by updating your package list and then installed Apache with the APT command. You've also enabled the necessary modules and familiarized yourself with the Apache configuration directories.

  • Databases
  • Webservers
  • PHP
  • API
  • Python
  • VPS Guides
  • Network
  • AI