How to Install Apache Web Server in Linux: Ubuntu, Fedora, RHEL?
Last Updated :
25 Feb, 2025
If you're looking to install Apache on Linux, this guide will walk you through the steps required for different distributions, including Ubuntu, Fedora, and RHEL. The Apache web server is a popular choice for hosting websites and applications, known for its reliability and flexibility. Whether you're new to how to install an Apache server or need specific instructions for Apache installation on Fedora or RHEL, we have you covered with step-by-step instructions for each platform.
How to Install Apache Web Server
Step 1: Check your Linux distribution
Use the following command to check which Linux distribution you are using.
Command: grep -E '^(VERSION|NAME)=' /etc/os-release
Checking Linux distribution (Fedora)Step 2: Update Your System
1. On Ubuntu/Debian-based systems:
Command: sudo apt update && sudo apt upgrade
2. On Fedora-based systems:
Command: sudo dnf update -y
3. On RHEL-based systems:
Command: sudo yum update -y
Updating system (fedora)Step 3: Install Apache Web Server
1. On Ubuntu/Debian-based systems:
Command: sudo apt install apache2 -y
2. On Fedora-based systems:
Command: sudo dnf install httpd -y
3. On RHEL-based systems:
Command: sudo yum install httpd -y
Installing Apache web serverStep 4: Enable the Services in Apache Web Server
1. On Ubuntu/Debian-based systems:
Command: sudo systemctl enable apache2
2. On Fedora-based systems:
Command: sudo systemctl enable httpd.service
3. On RHEL-based systems:
Command: sudo systemctl enable httpd.service
Starting services for the Apache Web ServerStep 5: Test the Server by Hosting a Simple Website
First, we will create a directory for our test website using the following command.
Command: sudo mkdir /var/www/html/test_website/
Now we will add index.html for our test website along with some testing code using the following command.
Command: echo '<html><head><title>Example</title></head><body><h1>GFG</h1><p>This is a test.</p></body></html>' | sudo tee /var/www/html/test_website/index.html
Now we will add the configuration file using the following command
Command:
sudo echo '<VirtualHost *:80>
ServerName web.testingserver.com
DocumentRoot /var/www/html/website
DirectoryIndex index.html
ErrorLog /var/log/httpd/example.com_error.log
CustomLog /var/log/httpd/example.com_requests.log combined
</VirtualHost>' > /etc/httpd/conf.d/web.conf
Once we create the required config file and test the website, we will need to own the Apache website directory for permissions.
We will use the chown and chmod commands as follows
Command:
sudo chown -R apache:apache /var/www/html/test_website
sudo chmod -R 755 /var/www/html/test_website
Now you can see the locally hosted website on your localhost.
Testing the website on the local serverIf the above-mentioned steps are performed correctly, Apache Web Server will run successfully! However, If it doesn't work, then you can uninstall Apache Web Server and start the installation again.
How to Uninstall Apache Web Server?
1. On Ubuntu/Debian-based systems
Command: sudo apt remove apache2
2. On Fedora-based systems
Command: sudo dnf remove httpd
3. On RHEL-based systems
Command: sudo yum remove httpd
Uninstalling Apache ServerHence we have successfully uninstalled Apache Web Server in Linux!
Conclusion
Installing the Apache Web Server on Linux systems like Ubuntu, Fedora, and RHEL is an easy task if you adhere to the proper procedures. After installing Apache, you can utilize its robust capabilities to efficiently host and control your websites. It's essential to perform routine upkeep and updates to maintain the security and efficiency of your Apache server. This article equips you with the necessary understanding to install and configure Apache on your Linux machine, making it simpler to deploy and manage web applications.
Also Read:
Similar Reads
Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co
11 min read
Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance
10 min read
Class Diagram | Unified Modeling Language (UML) A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact
12 min read
Steady State Response In this article, we are going to discuss the steady-state response. We will see what is steady state response in Time domain analysis. We will then discuss some of the standard test signals used in finding the response of a response. We also discuss the first-order response for different signals. We
9 min read
Backpropagation in Neural Network Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and
9 min read
Polymorphism in Java Polymorphism in Java is one of the core concepts in object-oriented programming (OOP) that allows objects to behave differently based on their specific class type. The word polymorphism means having many forms, and it comes from the Greek words poly (many) and morph (forms), this means one entity ca
7 min read
3-Phase Inverter An inverter is a fundamental electrical device designed primarily for the conversion of direct current into alternating current . This versatile device , also known as a variable frequency drive , plays a vital role in a wide range of applications , including variable frequency drives and high power
13 min read
What is Vacuum Circuit Breaker? A vacuum circuit breaker is a type of breaker that utilizes a vacuum as the medium to extinguish electrical arcs. Within this circuit breaker, there is a vacuum interrupter that houses the stationary and mobile contacts in a permanently sealed enclosure. When the contacts are separated in a high vac
13 min read
AVL Tree Data Structure An AVL tree defined as a self-balancing Binary Search Tree (BST) where the difference between heights of left and right subtrees for any node cannot be more than one. The absolute difference between the heights of the left subtree and the right subtree for any node is known as the balance factor of
4 min read
CTE in SQL In SQL, a Common Table Expression (CTE) is an essential tool for simplifying complex queries and making them more readable. By defining temporary result sets that can be referenced multiple times, a CTE in SQL allows developers to break down complicated logic into manageable parts. CTEs help with hi
6 min read