Use Apache on Linux to transform your server into a reliable, fast, and versatile web host. Apache is the world’s most widely used open-source web server, powering millions of websites worldwide due to its flexibility and stability.

This guide will lead you step-by-step through installing Apache on Linux, configuring your firewall, testing the server, and managing Apache with basic configurations — all explained in clear, straightforward language.
Prerequisites
- Supported Linux distributions: Ubuntu, Debian, CentOS, Red Hat, Oracle Linux.
- Access permissions: You need to have root or sudo privileges to install and manage software.
- Terminal access: Ability to run commands on your Linux server’s terminal or command line.
Use Apache on a Linux Server
Apache HTTP Server is one of the most widely used and reliable open-source web servers, especially on Linux systems. It is known for its flexibility, extensive module support, and robust community. Running Apache on a Linux server enables you to serve dynamic websites, host multiple domains, implement strong security protocols, and fine-tune performance with ease. Whether you’re managing a personal blog or enterprise-level applications, Apache delivers the control and scalability required for stable web hosting on Linux.
Install Apache on Linux
Apache is included in the default package repositories of most Linux distros, so installation is simple using package managers.
Using Package Managers
- For Ubuntu/Debian systems:
Update the package list to ensure you get the latest versions:
sudo apt update
- Install Apache:
sudo apt install apache2
For CentOS/Red Hat-based systems:
- Update your package repository cache:
sudo yum update
- Install Apache (called httpd in CentOS/RHEL):
sudo yum install httpd
Start and Enable Apache Service
Once Apache is installed, you need to start the service so it runs and enable it to automatically start on system boot.
Checking Apache Service Status
- For Ubuntu/Debian:
sudo systemctl status apache2
- For CentOS/Red Hat:
sudo systemctl status httpd
Starting Apache Service
To start Apache manually:
- Ubuntu/Debian:
sudo systemctl start apache2
- CentOS/Red Hat:
sudo systemctl start httpd
Enabling Apache to Start at Boot Time
To ensure Apache runs every time your server boots up:
- Ubuntu/Debian:
sudo systemctl enable apache2
- CentOS/Red Hat:
sudo systemctl enable httpd
Configure Firewall for Apache
Your Linux server’s firewall may block incoming HTTP/HTTPS traffic by default. Configure it to allow Apache traffic.
Allowing HTTP and HTTPS Traffic
- On Ubuntu/Debian with UFW firewall:
sudo ufw allow 'Apache' sudo ufw reload
Opens ports 80 (HTTP) and 443 (HTTPS) in the firewall using predefined UFW profiles, then reloads firewall rules.
- On CentOS/Red Hat with firewalld:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
Adds HTTP and HTTPS services to the permanent firewall configuration and reloads the firewall to apply changes.
Test Apache Installation
Verify Apache is running correctly and serving web pages.
Check Apache Version
- For Ubuntu/Debian:
apache2 -v
- For CentOS/Red Hat:
httpd -v
Access Default Web Page
- Open a web browser and type:
http://your_server_ip
Replace your_server_ip with your actual server IP address. You should see the Apache default page, typically saying “It works!”, indicating Apache is working fine.
Basic Configuration and Management
Apache has flexible configuration files and commands for managing and customizing your server.
Where Apache Configuration Files Are Located
- Ubuntu/Debian:
/etc/apache2/
- CentOS/Red Hat:
/etc/httpd/
Key files:
apache2.conf
(Ubuntu/Debian)httpd.conf
(CentOS/Red Hat)
Setting Up Virtual Hosts
Virtual hosts allow you to serve multiple domains/websites from one Apache server.
Ubuntu/Debian Example:
- Create a virtual host configuration file:
sudo nano /etc/apache2/sites-available/example.com.conf
Opens a text editor (nano
) to create a config file for your site.
- Add this configuration inside the file:
<VirtualHost *:80> ServerName example.com ServerAlias www.example.com DocumentRoot /var/www/example.com ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
Defines the domain, its root directory for files, and log file locations.
- Enable the site and reload Apache:
sudo a2ensite example.com sudo systemctl reload apache2
Activates your virtual host config and reloads Apache to apply it.
Common Apache Commands for Managing Services
Restart Apache:
- Ubuntu/Debian:
sudo systemctl restart apache2
- CentOS/Red Hat:
sudo systemctl restart httpd
Stops and starts Apache service again, useful after config changes.
Check configuration syntax:
- Ubuntu/Debian:
apache2ctl -t
- CentOS/Red Hat:
httpd -t
Checks Apache configurations for syntax errors without restarting.
View logs for troubleshooting:
- Ubuntu/Debian:
/var/log/apache2/error.log
- CentOS/Red Hat:
/var/log/httpd/error_log
These files record Apache errors; checking them helps find issues.
Conclusion
To use Apache on Linux effectively, you begin by installing the Apache package via your distro’s package manager, starting and enabling the service for automatic boot, configuring your firewall to allow web traffic, and verifying the installation by accessing the default web page. You’ve also learned basic management tasks such as editing configuration files and setting up virtual hosts for hosting multiple websites.
Mastering these steps means you are well on your way to deploying fast, secure, and scalable web servers using Apache on your Linux system. Whether for personal projects or professional use, Apache on Linux offers a powerful and trusted platform for web hosting. For more information, visit the Apache Official documentation.