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

Setting up the Apache Web Server on Linux operating systems such as Ubuntu, Fedora, and RHEL is a routine job for web developers and system managers. Apache stands out among web servers for its adaptability, robust security measures, and compatibility with different web technologies. This manual will guide you through the installation process of Apache on Ubuntu, Fedora, and RHEL, making sure your web server operates smoothly. Whether you’re a novice or a seasoned user, this instruction will assist you in installing Apache on your chosen Linux system.

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

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
image_2024-02-28_225406517

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
image_2024-02-28_225516436

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_httpd

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
image_2024-02-28_234526618

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

image_2024-02-28_232700244

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 Uninstall Apache Web Server?

On Ubuntu/Debian based systems

command: sudo apt remove apache2

On Fedora based systems

command: sudo dnf remove httpd

On RHEL based systems

command: sudo yum remove httpd
uninstalling_apache

Uninstalling Apache Server

Hence 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

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

What is Apache, and why is it used?

Apache HTTP Server, commonly referred to as Apache, is a free and open-source web server software that enables you to host websites and web applications on your Linux system. It’s widely popular due to its reliability, security, and extensive customization options.

What are virtual hosts, and when are they used?

Virtual hosts allow you to host multiple websites on a single server using the same Apache installation. Each virtual host is configured with its own document root directory and server name, enabling you to manage different websites independently.

What are some best practices for managing multiple websites with Apache?

To manage multiple websites with Apache, Following are some best practices:

  • Use descriptive names: Choose clear and informative names for your virtual hosts to improve organization.
  • Document your configuration: Maintain clear documentation of your virtual host configurations for easy reference and maintenance.
  • Utilize version control: Consider using version control systems like Git to manage your virtual host configuration files and track changes.



Reffered: https://www.geeksforgeeks.org


TechTips

Related
How to Install Software Applications in Linux? How to Install Software Applications in Linux?
How to Fix Windows 11 No Sound Issues? How to Fix Windows 11 No Sound Issues?
Ultimate Guide: Remove Screen Lock on iPhone with/without Passcode [2024] Ultimate Guide: Remove Screen Lock on iPhone with/without Passcode [2024]
How to autosum in LibreOffice? GeeksforGeeks How to autosum in LibreOffice? GeeksforGeeks
How to Free Up Space on Your Smartphone How to Free Up Space on Your Smartphone

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
15