Apache is one of the most widely used open-source web servers in the world. It is cross-platform, highly flexible, and can be extended with modules to handle SSL, caching, authentication, URL rewriting, and more. A large share of the internet runs on Apache.
This guide shows you how to install Apache on Ubuntu 20.04, open the firewall, verify the setup, and configure a virtual host for your domain.
<strong>Prerequisite:</strong> You need a user account with sudo access to follow these steps.
Apache is available in the default Ubuntu repositories. On Ubuntu and Debian systems, the package and service are both called apache2. Install it with:
bashsudo apt updatesudo apt install apache2
The service starts automatically after install. Confirm it is running:
bashsudo systemctl status apache2
Look for active (running) in the output. The default web root directory is /var/www/html — this is where Apache serves files from by default.
To start, stop, or restart Apache at any time:
bashsudo systemctl start apache2sudo systemctl stop apache2sudo systemctl restart apache2
Apache listens on port 80 for HTTP and port 443 for HTTPS. Use the Apache Full UFW profile to open both ports at once:
bashsudo ufw allow 'Apache Full'
Verify the rule is active:
bashsudo ufw status
You should see Apache Full listed as allowed. The Apache Full profile covers both plain HTTP traffic and encrypted HTTPS traffic.
Open your browser and go to:
http://your_server_ip_or_domain/
You should see the default Apache welcome page. It confirms the web server is installed and working. The page also shows key paths — where config files, log files, and the web root are located on your system.
A virtual host lets you run more than one website on a single server. Each site gets its own configuration file, which tells Apache:
ServerName)DocumentRoot)Apache includes one virtual host by default. If you only host one site, place your files in /var/www/html and you are done.
For multiple sites, set up a separate virtual host for each domain. This example uses example.com. Replace it with your actual domain name.
Create the document root directory:
bashsudo mkdir -p /var/www/example.com
Set ownership to the Apache user so the server can read the files:
bashsudo chown -R www-data: /var/www/example.com
Create the virtual host config file:
bashsudo nano /etc/apache2/sites-available/example.com.conf
Paste this configuration:
apache<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 </Directory> ErrorLog ${APACHE_LOG_DIR}/example.com-error.log CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined</VirtualHost> Enable the site with a2ensite:
bashsudo a2ensite example.com
Check the config for syntax errors:
bashsudo apachectl configtest
If you see Syntax OK, restart Apache to apply the changes:
bashsudo systemctl restart apache2
Visit http://example.com in your browser. Your site should load from the document root you set.
<strong>Tip:</strong> To add HTTPS to your site, use <strong>Let's Encrypt</strong> with Certbot. It is free and works well with Apache on Ubuntu.
Apache is now installed and serving your site on Ubuntu. From here, you can deploy web applications, add virtual hosts for more domains, or enable modules to extend what Apache can do. Got questions? Leave a comment below.
Swap space is an area on disk that Linux uses when it runs out of physical…
Zoom is one of the most widely used video conferencing platforms. Zoom works on Windows, macOS,…
Webmin is an open-source web-based control panel for Linux servers. It gives you a browser interface…
MariaDB is an open-source relational database management system. It was created by the original MySQL developers…
Corruption investigations need accuracy, patience, and strong evidence. In 2026, OSINT tools can help researchers,…
Private investigators use OSINT to collect public information, verify identities, review business connections, check public…