How to Install Apache on Ubuntu
Learn how to update Ubuntu, install the Apache2 package, verify the service, and test the Apache default page at localhost.
What Is Apache HTTP Server?
Apache HTTP Server is open-source web-server software that receives HTTP requests and returns website pages and other HTTP content. It is commonly used on Linux systems, including Ubuntu.
A web server is software, or a machine running that software, that listens for web requests and returns website resources through HTTP or HTTPS. A browser has the opposite role: it requests content from a web server and displays the response. In this lesson, Apache provides the content and your browser requests and displays it.
Before You Install Apache
You need access to an Ubuntu installation and a terminal. Ubuntu is a Linux distribution that uses APT, its package-management toolset for obtaining, installing, updating, and removing software.
Administrative privileges are required for system updates and software installation. The sudo command prefix runs a command with elevated privileges. When you use sudo, Ubuntu may request the current user's password. Use an account authorized to administer the system.
It is recommended that you refresh Ubuntu's package information and apply available upgrades before installing Apache. APT package indexes tell Ubuntu which package versions are available, while upgrades update packages already installed on the system.
Update Ubuntu Packages
Open a terminal and run:
sudo apt-get update && sudo apt-get upgradeThe first command refreshes the local APT package indexes. The second upgrades installed packages when newer versions are available. The && operator runs the upgrade only after the package-index refresh succeeds.
Wait for both package operations to finish. APT may display a confirmation prompt before applying upgrades. Read the prompt and respond as requested. Do not close the terminal while APT is working.
Install Apache on Ubuntu
Install Apache by installing Ubuntu's apache2 package:
sudo apt-get install apache2A package is a bundled unit of software and metadata managed by Ubuntu's package system. The apache2 package contains Apache HTTP Server and its Ubuntu integration. APT may ask you to confirm that it should download and install the package. Accept the installation when prompted, then wait for the operation to complete.
Ubuntu generally starts the Apache service automatically after the package installation finishes. A service is a background process managed by the operating system. Apache's package name and service name are both commonly represented as apache2.
Apache Installation Commands on Ubuntu
| Task | Command | Purpose | Expected outcome |
|---|---|---|---|
| Refresh package lists and upgrade installed packages | sudo apt-get update && sudo apt-get upgrade | Refresh available package metadata and apply available Ubuntu package upgrades. | APT completes the update and upgrade operations, possibly after confirmation. |
| Install Apache | sudo apt-get install apache2 | Install Apache HTTP Server from Ubuntu's package repositories. | The apache2 package is installed and Apache generally starts automatically. |
| Check Apache service status | service apache2 status | Display the current state of the Apache service. | The output indicates whether Apache is active, inactive, or failed. |
Verify the Apache Service
Check the service from the terminal:
service apache2 statusLook at the reported state. An active or running state means that Apache is currently operating and can serve requests. A failed, inactive, or unavailable state means Apache is not currently serving requests and needs further investigation.
Test Apache in a Browser
Open a browser on the same Ubuntu machine and navigate to:
http://localhost/localhost is a hostname that refers to the current computer, normally through its loopback network interface. If Apache installed and started correctly, the browser displays the Apache2 Ubuntu Default Page. This standard page is supplied by a newly installed Ubuntu Apache server.
Installation Verification Checklist
| Check | How to verify | Successful result |
|---|---|---|
| Package installation | Complete sudo apt-get install apache2 without an installation error. | APT reports that the apache2 package was installed or is already installed. |
| Service status | Run service apache2 status. | The service state is active or running. |
| Local browser test | Visit http://localhost/ in a browser on the Ubuntu machine. | The Apache2 Ubuntu Default Page appears. |
What the Default Page Confirms
Seeing the default page verifies basic local web serving: Apache is installed, responding to a request, and returning its default site content. It does not mean that a custom website or application has been deployed.
After this basic installation, Apache can be configured to host website or application files. Later configuration may involve Apache configuration files, document roots, virtual hosts, and access through HTTP or HTTPS.
Troubleshooting
APT Requests Confirmation
APT may ask for approval before downloading and installing packages. Confirm the installation as instructed and allow the package operation to finish.
APT Reports Insufficient Permission
System upgrades and package installation require administrator privileges. Run the commands with sudo using an account authorized to administer Ubuntu. If sudo requests a password, enter the current user's password rather than a separate Apache password.
Apache Is Not Running
If the service status is failed or inactive, Apache did not start successfully or is not currently enabled as a running service. Check the reported state with service apache2 status, then investigate the information shown. If appropriate, start the service with administrative privileges and check its status again.
sudo service apache2 start
service apache2 statuslocalhost Does Not Show the Default Page
Confirm that you entered the exact address http://localhost/, then check the Apache service status again. Apache may not be running, the browser may be using an incorrect address, or another local service may be involved. The browser test should be performed on the same Ubuntu machine where Apache was installed.