How to Install Apache Web Server in Linux?

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

On Ubuntu/Debian based systems

command: sudo apt update && sudo apt upgrade

On Fedora based systems

command: sudo dnf update -y

On RHEL based systems

command: sudo yum update -y

Updating system (fedora)

Step 3 – Install Apache Web Server

On Ubuntu/Debian based systems

command: sudo apt install apache2 -y

On Fedora based systems

command: sudo dnf install httpd -y

On RHEL based systems

command: sudo yum install httpd -y

installing apache web server

Step 4 – Enable the Services

On Ubuntu/Debian based systems

command: sudo systemctl enable apache2

On Fedora based systems

command: sudo systemctl enable httpd.service

On RHEL based systems

command: sudo systemctl enable httpd.service

starting services for Apache Web Server

Step 5 – Test the Server by Hosting Simple Website

First, we will create a directory for our test website using 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 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 configuration file using 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 created the required config file and test website, we will need to own the Apache website directory for permissions.
We will use chown and chmod command 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 locally hosted website on localhost.

link: http://localhost

testing website on local server

If the above mentioned steps performed correctly, Apache Web Server will run successfully! However, If it didn’t work, then you can uninstall Apache Web Sever and can start installation again.

How to Install Apache Web Server in Linux: Ubuntu, Fedora, RHEL?

Apache is an open-source web server that’s available for Linux servers free of charge. Installing an Apache web server on Linux is a straightforward process, but the specific commands might differ slightly depending on your Linux distribution.

In this article, we will install Apache Web Server on various Linux distributions like Ubuntu, Fedora, Red Hat Enterprise Linux (RHEL) etc.

Similar Reads

How to Install Apache Web Server in Linux?

Step 1 – Check your Linux distribution....

How to Uninstall Apache Web Server?

On Ubuntu/Debian based systems...

Conclusion

In this article, we have installed and configured the Apache Web Server across popular Linux distributions like Ubuntu, Fedora, and RHEL. We have outlined the fundamental steps, encompassing updating package lists, installing the software, verifying its operation, and hosting test website. So install Apache Web Server on your Linux now!...

Also Read

How to Setup Apache Web Server On Any Android Device? Most Useful Commands to Manage Apache Web Server in Linux? How to install Apache server in Ubuntu ?...

Frequently Asked Questions to Install Apache Web Server in Linux

What is Apache, and why is it used?...