cover installation apache on ubuntu
5–8 minutes

How to Install and Configure Apache on Ubuntu

Theapache HTTP serveris one of the most used and reliable web servers in the world. This open-source solution provides advanced features, including dynamically loadable modules, excellent multimedia support and perfect integration with other popular software. For technical details, please refer toofficial documentation of Apache.

Step 1: Installation of Apache on Ubuntu

Apache is available directly within predefined software repositoryUbuntu Server, making installation quick and secure through the classic package management tools.

To begin with, it is essential to update the local package index to make sure you download the latest available version:

sudo apt update

Next, proceed with the installation of the packageapache2:

sudo apt install apache2

After confirming the operation, the package manageraptwill automatically install Apache along with all necessary system dependencies.

Step 2: Adjust the UFW firewall

Before testing Apache’s proper functioning, it is essential to configure firewall settings to allow external access to predefined web ports. On Ubuntu, it is generally usedUFW (Uncomplicated Firewall)to limit access to the server.

During the installation phase, Apache automatically records some application profiles within UFW. These profiles simplify the ability or disabling of web traffic through the firewall.

To view the list of profiles configured in the applicationufw, run the command:

sudo ufw app list

A typical terminal output will be similar to the following:

Available applications: Apache Apache Full Apache Secure

Configuration of Apache Profiles

As highlighted by the output, the system provides three main profiles for Apache management:

  • Apache: this profile only opens the door80(destinated to standard and unencrypted web traffic).
  • Apache Full: simultaneously opens the door80and the door443(necessary for protected and encrypted web traffic viacertificate TLS/SSL).
  • Apache Secure: only opens the door443. Until you have correctly configured an SSL certificate for your server, it is advisable to enable only the basic profile to allow HTTP traffic on the port80:
sudo ufw allow 'Apache'

You can instantly check the change by checking the firewall status with this command:

sudo ufw status

Web traffic now enabled for Apache.

Step 3: Web server status verification

At the end of the installation procedure, the Apache demon starts automatically. As a result, your new web server will be active and working in the background.

To be sure that the service is running, use the appropriate state command:

sudo systemctl status apache2

The output of the terminal will confirm that the service is properly started. However, the best practical method to validate the installation is to request the rendering of a page directly to Apache.

You can access the default landing page to confirm that the software responds to HTTP calls by entering your public IP address. If you don’t know your server’s IP address, you can get it quickly by typing:

hostname -I

IP Address Recovery

As a result, you will get a sequence of network addresses separated from spaces. Generally the first is the correct one; if you do not upload the page, try the other addresses indicated.

Once you locate your server’s IP address, simply enter it in the address bar of your favorite browser in this format:

http://{il_tuo_indirizzo_ip}

At this point, you should see the default web pageUbuntu 22.04 Apache Default Page.

This graphical interface indicates that Apache works without errors. It also includes valuable basic information about operating directories and essential configuration files to know.

Step 4: Apache Process Management

Now that your web environment is running, it is essential to master some basic management commands using theservices systemdviasystemctl.

To securely stop the web server:

sudo systemctl stop apache2

To start the web server when the service is currently inactive:

sudo systemctl start apache2

To stop and restart the service forcefully:

sudo systemctl restart apache2

If you are simply updating the configuration, Apache can be recharged fluidly without dropping active user connections:

sudo systemctl reload apache2

By default, Apache is programmed to automatically start each server ignition. If you want to disable this automatic rule:

sudo systemctl disable apache2

To restore the original behavior and reactivate the auto boot:

sudo systemctl enable apache2

Step 5: Directory and crucial Apache Files

WEB CONTENT ROOT

/var/www/html: It is the main directory dedicated to web content. By default, it only keeps Apache's default welcome document. You can change the path of origin by intervening on the configuration files ofVirtual Host.

FILE OF SERVER CONFIGURATION

  • /etc/apache2: The container directory for configurations. All key documents of Apache reside within it.
  • /etc/apache2/apache2.conf: Represents the global server configuration file. Each alteration affects the Apache environment in tote. This file orchestrates the modular loading of many other crucial documents.
  • /etc/apache2/ports.conf: Adjust the network ports on which Apache will keep listening. Typically points on the door80and, if combined with modules for SSL functionality, extends listening to the door443.

SERVER REGISTRIES (LOGS)

  • /var/log/apache2/access. log log: By default, it stores every single incoming request addressed to the web server in detail, unless you personalize a different directive.
  • /var/log/apache2/error.log: The error tracking hub. Any operational anomalousness is given in this document. The level of analytical detail is established by the DirectiveLogLevelconfigured in Apache.

Step 6: Customize and Host Your Website

To publish your pages and replace the default screen you have previously visited, you will need to run some simple steps. The native files of your site (HTML documents, CSS style sheets, images) must be uploaded, except for several virtual configurations, within the root/var/www/html/.

OPERATIONAL PROCEDURE

  • Delete or rename the index file. Pre-existing htmlpresent in that directory (the use of the prefix may be requiredsudovia terminal, or you must first set the correct read/write permissions on the folder files).
  • Upload your custom HTML filethat will act as “Homepage” or landing page. Make sure he was appointed exactlyindex.html.
  • Enter the IPin the browser (or reload the web page) to admire your new website online.

FAQ: Frequently Asked Questions about Apache

1. What is the main difference between Apache and Nginx?

Both are very powerful and widespread web servers, but they have substantial differences in architecture.Apacheis based on a process-oriented approach/thread, offering high flexibility and the use of the famous file. htaccessfor local configurations.Nginxinstead uses an event-driven infrastructure, often more efficient in serving heavy static assets and managing high volumes of simultaneous traffic.

2. How can I enable the HTTPS (SSL) on Apache?

To provide your website with a free SSL certificate, you should rely on a certified and automated authority asLet’s Encryptusing Certbot. Alternatively, you can manually generate a certificate, activate the native SSL module (sudo a2enmod ssl), configure a Virtual Host to sort port traffic 443 and restart the Apache service.

3. What are Virtual Hosts and how do I use them?

IVirtual Host(Host Virtuali) are configuration directives that allow a single machine or web server (through a single IP) to simultaneously host multiple websites or domains (e.g.site-a. communityandwebsite-b.com). You can define separate files for each Virtual Host in the directory/etc/apache2/sites-available/to differentiate logs, root folders and permissions for each domain loaded.

EnglishenEnglishEnglish