How to Install and Configure Apache on Ubuntu
Learn how to install and configure the Apache web server on Ubuntu. Follow our step-by-step guide to manage firewalls, processes and main files.

Apache HTTP server is one of the most widely 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, refer to the official documentation of Apache.
Step 1: Install Apache on Ubuntu #
Apache is available directly within the Ubuntu Server predefined software repository, 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 to download the latest available version:
sudo apt update
Then proceed with the installation of the apache package2:
sudo apt install apache2
After confirming the operation, the apt package manager will automatically install Apache along with all necessary system dependencies.
Step 2: Adjusting 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, you generally use UFW (Uncomplicated Firewall) to limit server access.
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 ufw application, please command:
sudo ufw app list
A typical terminal output will be similar to the following:
Applicazioni disponibili:
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 port 80 (destinated to standard and unencrypted web traffic).
- Apache Full: simultaneously opens port 80 and port 443 (necessary for protected and encrypted web traffic via certificate TLS/SSL).
- Apache Secure opens only door 443. 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 port 80:
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 don’t have to upload the page, try the other addresses indicated.
Once you have identified 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 page Ubuntu 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 services systemd via systemctl.
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 to 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 Virtual Host configuration files.
FILE OF SERVER CONFIGURATION
- /etc/apache2: The container directory for configurations. All key documents of Apache reside within it.
- /etc/apache2/apache2.conf: It 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 doors on which Apache will be listening. Typically points on port 80 and, if combined with modules for SSL functionality, extends listening to port 443.
SERVER REGISTRIES (LOGS)
- /var/log/apache2/access.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 hub for tracking errors. Any operational anomaly is filed in this document. The level of analytical detail is established by the LogLevel Directive configured 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) will have to be uploaded, except for several virtual configurations, within the root /var/www/html/.
OPERATIONAL PROCEDURE
- Delete or rename the index file. Pre-existing html in that directory (the use of the
sudoprefix by terminal may be required, or you will first need to set the correct read/write permissions on the folder files). - Upload your custom HTML file which will act as “Homepage” or landing page. Make sure he was named exactly
index.html. - Enter the IP in your browser (or reload the web page) to see 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. Apache is based on a process-oriented approach/thread, offering high flexibility and the use of the famous .htaccess file for local configurations. Nginx uses an event-driven infrastructure, which is often more efficient in serving heavy static assets and managing high volumes of simultaneous traffic.
2. How can I enable HTTPS (SSL) on Apache? #
To provide your website with a free SSL certificate, you should rely on a certified and automated Authority like Let’s Encrypt using 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? #
Virtual Hosts (Virtual Hosts) are configuration directives that allow a single machine or web server (via a single IP) to simultaneously host multiple websites or domains (e.g. site-a.com and site-b.com). You can define separate files for each Virtual Host in the /etc/apache2/sites-available/ directory to differentiate logs, root folders and permissions for each uploaded domain.

