Apache is the most widely used web server in the world. It is free, open-source, and runs on Linux, Windows, and macOS. Apache handles HTTP and HTTPS requests and its feature set can be extended with a large library of modules for SSL termination, URL rewriting, caching, authentication, reverse proxying, and more.
This guide covers how to install Apache on Ubuntu 18.04, open the UFW firewall, verify the server is running, and understand the Apache configuration directory layout.
<strong>Prerequisite:</strong> You need sudo access.
Apache is available in the default Ubuntu repositories under the package name apache2. Install it with:
bashsudo apt updatesudo apt install apache2
Apache starts automatically after installation. Confirm it is running:
bashsudo systemctl status apache2
Look for Active: active (running) in the output. If the service is running, Apache is ready to serve traffic.
Open the firewall. Apache registers three UFW profiles during installation: Apache, Apache (v6), and Apache Full. Use Apache Full to open both HTTP port 80 and HTTPS port 443 in one command:
bashsudo ufw allow 'Apache Full'
Verify the installation. Open your browser and go to http://your_server_ip. You should see the default Ubuntu 18.04 Apache welcome page. This page also lists the locations of the key Apache configuration files, which is a useful quick reference when you are getting started.
All Apache configuration files are stored under /etc/apache2/. Understanding the layout of this directory makes it much easier to troubleshoot issues and set up new sites.
Main configuration file: /etc/apache2/apache2.conf. This is the file Apache reads at startup. It defines global settings, directory access rules, and includes all other configuration files.
Ports file: /etc/apache2/ports.conf. This file controls which ports Apache listens on. By default, port 80 is always active, and port 443 is active when the SSL module is enabled.
Virtual hosts. Each website on the server gets its own configuration file in /etc/apache2/sites-available/. Use the domain name as the filename to keep things organized, for example /etc/apache2/sites-available/mydomain.com.conf. Apache only reads virtual host files that are in /etc/apache2/sites-enabled/, not sites-available.
To activate a virtual host, use a2ensite. It creates the symlink from sites-available to sites-enabled automatically:
bashsudo a2ensite mydomain.com.conf
To deactivate a virtual host, use a2dissite. After enabling or disabling a site, reload Apache to apply the change:
bashsudo systemctl reload apache2
Modules extend what Apache can do. Module configs are stored in /etc/apache2/mods-available/. Enable a module with a2enmod and disable it with a2dismod. Common modules include mod_rewrite for URL rewriting, mod_ssl for HTTPS support, and mod_headers for adding and modifying HTTP response headers.
Global configuration fragments live in /etc/apache2/conf-available/. Enable them with a2enconf and disable with a2disconf. Active configs are symlinked into /etc/apache2/conf-enabled/.
Log files are stored in /var/log/apache2/. Apache writes two log files by default: access.log for incoming requests and error.log for server errors. On a multi-site server, define a separate CustomLog and ErrorLog path inside each virtual host config block. This keeps logs separated by domain and makes debugging much simpler.
Document root. The document root is the directory Apache serves files from for a given site. Common locations are:
/var/www/<site_name>/var/www/html/<site_name>/home/<user_name>/<site_name>Set the path in your virtual host config using the DocumentRoot directive and make sure Apache has read access to the directory.
Apache is now installed and running on your Ubuntu 18.04 server. Your next steps are to configure virtual hosts for your domains, enable HTTPS with a Let’s Encrypt SSL certificate, and start deploying web applications. Leave a comment below if you run into any issues.
Apache Cassandra is a free, open-source NoSQL database designed for high availability and linear scalability with…
Rocket.Chat is a free, open-source team communication platform built with the Meteor framework. It is a…
MySQL is the most popular open-source relational database management system. It is fast, reliable, and scales…
NetBeans is a free, open-source, cross-platform IDE developed by the Apache Software Foundation. It was one…
Pip is the official package manager for Python and the standard way to install libraries from…
R is an open-source programming language and environment built for statistical computing and data visualization. It…