LinuxUbuntu

How to Install Apache2 on Ubuntu

Apache2 is one of the most popular web servers available. This tutorial will guide you through the process of installing and configuring Apache2 on an Ubuntu system.


Before installing any software, ensure your system is up-to-date by running the following commands:

sudo apt update
sudo apt upgrade

Install the Apache2 package by entering the following command:

sudo apt install apache2

Press Y when prompted to confirm the installation.


If you have a firewall enabled, you’ll need to allow Apache through it. Use the following commands to allow traffic:

sudo ufw allow 'Apache'
sudo ufw enable
sudo ufw status

You should see a rule allowing Apache traffic.


To check if Apache is running, use the following command:

sudo systemctl status apache2

You should see a message indicating that Apache is active and running.

Alternatively, open a web browser and visit:

http://your_server_IP

You should see the default Apache2 Ubuntu page, which confirms the server is working.


You can use the following commands to manage the Apache service:

  • Start Apache: sudo systemctl start apache2
  • Stop Apache: sudo systemctl stop apache2
  • Restart Apache: sudo systemctl restart apache2
  • Reload Configuration: sudo systemctl reload apache2
  • Enable Apache on Boot: sudo systemctl enable apache2

Apache configuration files are located in /etc/apache2/. Here are some key files and directories:

  • Main Configuration File: /etc/apache2/apache2.conf
  • Virtual Hosts: /etc/apache2/sites-available/
  • Modules: /etc/apache2/mods-available/

You can edit these files to customize your Apache setup. Restart the service after making changes:

sudo systemctl restart apache2

Create a test HTML file to ensure Apache serves content correctly. For example:

echo "<h1>Apache is working!</h1>" | sudo tee /var/www/html/index.html

Visit your server’s IP address in a browser, and you should see “Apache is working!”.


Your Apache2 server is now installed and running on Ubuntu! You can proceed to configure it further or deploy your web applications.

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top button