普通视图

发现新文章,点击刷新页面。
今天 — 2026年4月28日首页

How to Install Apache on Ubuntu 26.04

Apache is one of the most popular web servers in the world. It is an open-source and cross-platform HTTP server that powers a large percentage of the Internet’s websites. Apache provides many powerful features that can be further extended through the use of additional modules, making it a good option for those looking for a customizable and flexible web server.

This tutorial will guide you through the process of installing and managing the Apache web server on Ubuntu 26.04. You will learn how to install Apache, open HTTP and HTTPS ports in the firewall, and set up virtual hosts.

Installing Apache

On Ubuntu and Debian systems, the Apache package and the service are called apache2.

Apache is included in the default Ubuntu repositories, and the installation is pretty straightforward.

Run the following commands to refresh the local package index and install Apache:

Terminal
sudo apt update
sudo apt install apache2

After the installation process is finished, the Apache service will start automatically.

You can verify that Apache is running by typing:

Terminal
sudo systemctl status apache2

The output should tell you that the service is running and enabled to start on system boot:

output
● apache2.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/apache2.service; enabled; preset: enabled)
Active: active (running) since Sat 2026-04-25 18:28:47 UTC; 5min ago
Invocation: d7369f2830cc4e29b4d03d6f2c0968ba
Docs: https://httpd.apache.org/docs/2.4/
Main PID: 9429 (apache2)
Status: "Total requests: 2; Idle/Busy workers 100/0;Requests/sec: 0.00608; Bytes served/>
Tasks: 7 (limit: 375)
Memory: 12.4M (peak: 12.7M)
CPU: 168ms
CGroup: /system.slice/apache2.service
├─9429 /usr/sbin/apache2 -k start -DFOREGROUND
├─9432 /usr/sbin/apache2 -k start -DFOREGROUND
├─9433 /usr/sbin/apache2 -k start -DFOREGROUND
...

Apache has been successfully installed on your Ubuntu 26.04 server. You can now start using it.

Opening HTTP and HTTPS Ports

Apache listens on port 80 (HTTP) and 443 (HTTPS). You need to open the necessary firewall ports to allow access to the web server from the Internet.

Assuming you are using UFW , you can do that by enabling the ‘Apache Full’ profile, which includes rules for both ports:

Terminal
sudo ufw allow 'Apache Full'

Verify the change:

Terminal
sudo ufw status

The output should look something like this:

output
Status: active
To Action From
-- ------ ----
22/tcp ALLOW Anywhere
Apache Full ALLOW Anywhere
22/tcp (v6) ALLOW Anywhere (v6)
Apache Full (v6) ALLOW Anywhere (v6)

Verifying the Apache Installation

To verify that everything works correctly, open your browser, type your server IP address http://YOUR_IP_OR_DOMAIN/, and you will see the default Ubuntu 26.04 Apache welcome page as shown below:

Apache welcome page

The page provides basic information about Apache configuration files, relevant helper scripts, and directory locations.

Setting up a Virtual Host

A virtual host allows Apache to serve more than one website from the same server. Each virtual host defines the settings for a specific domain.

Apache ships with one default virtual host. If you are hosting a single website, you can place the site files in /var/www/html and edit /etc/apache2/sites-enabled/000-default.conf. If you want to host multiple sites, create a separate virtual host file for each domain.

In this example, we will configure a site for example.com. Replace example.com with your own domain name.

First, create the document root directory:

Run the following command to create the directory :

Terminal
sudo mkdir -p /var/www/example.com

Create a simple index.html file inside the document root so you can test the configuration:

/var/www/example.com/index.htmlhtml
<!DOCTYPE html>
<html lang="en" dir="ltr">
 <head>
 <meta charset="utf-8">
 <title>Welcome to example.com</title>
 </head>
 <body>
 <h1>Success! example.com home page!</h1>
 </body>
</html>

Set the ownership to the Apache user:

Terminal
sudo chown -R www-data:www-data /var/www/example.com

Next, create the virtual host file:

/etc/apache2/sites-available/example.com.confapache
<VirtualHost *:80>
 ServerName example.com
 ServerAlias www.example.com
 ServerAdmin webmaster@example.com
 DocumentRoot /var/www/example.com

 <Directory /var/www/example.com>
 Options -Indexes +FollowSymLinks
 AllowOverride All
 Require all granted
 </Directory>

 ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
 CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined
</VirtualHost>

Enable the site:

Terminal
sudo a2ensite example.com.conf

Test the configuration:

Terminal
sudo apachectl configtest

If the syntax check passes, you will see the following output:

output
Syntax OK

Restart Apache:

Terminal
sudo systemctl restart apache2

Now open http://example.com in your browser. If everything is configured correctly, you should see the test page.

Example Apache virtual host test page on Ubuntu 26.04

Conclusion

We have shown you how to install Apache on Ubuntu 26.04, open the required firewall ports, and configure a virtual host. From here, you can deploy your site content or continue with SSL and PHP setup.

❌
❌