How to Set Up Apache or Nginx Web Server on Rocky Linux in VirtualBox

Set up Apache or Nginx Web Server on Rocky Linux to host websites or applications seamlessly. In this guide, we’ll walk you through configuring these popular web servers on a Rocky Linux virtual machine running inside VirtualBox. Whether you’re a beginner or an advanced user, this tutorial will help you get started.

Watch the detailed process in this step-by-step video.


Steps to Set Up Apache or Nginx Web Server on Rocky Linux

Prerequisites

Before we begin, ensure the following requirements are met:

  1. VirtualBox installed on your system.
  2. A Rocky Linux virtual machine set up. If you haven’t done this yet, check our video & blog on installing Rocky Linux in VirtualBox.
  3. A stable internet connection for downloading required packages.

Let’s start by updating the system to ensure all packages are up-to-date. Open your terminal and run:

sudo dnf update -y  

Installing Apache on Rocky Linux

Apache is one of the most widely used web servers. Here’s how you can install and configure it:

  1. Install Apache:
    sudo dnf install httpd -y  
    
  2. Enable and Start the Service:
    sudo systemctl enable httpd  
    sudo systemctl start httpd  
    
  3. Verify Apache is Running:
    sudo systemctl status httpd  
    
  4. Test the Configuration:
    Open your web browser and enter the IP address of your Rocky Linux VM. If Apache is configured correctly, you’ll see the default Apache page.

Configuring the Firewall for Apache

If the page doesn’t load, you might need to configure your firewall:

  1. Check Current Firewall Rules:
    sudo firewall-cmd --list-all  
    
  2. Allow HTTP and HTTPS Traffic:
    sudo firewall-cmd --add-service=http --permanent  
    sudo firewall-cmd --add-service=https --permanent  
    sudo firewall-cmd --reload  
    

Refresh your browser to confirm the default page loads successfully.


Installing Nginx on Rocky Linux

Nginx is a high-performance alternative to Apache. Follow these steps to install and set it up:

  1. Remove Apache to Avoid Conflicts:
    sudo systemctl stop httpd  
    sudo dnf remove httpd -y  
    
  2. Install Nginx:
    sudo dnf install nginx -y  
    
  3. Enable and Start the Nginx Service:
    sudo systemctl enable nginx  
    sudo systemctl start nginx  
    
  4. Test Nginx Configuration:
    Enter your VM’s IP address in the browser. You’ll see the Nginx default page if everything is set up correctly.

FAQs

  1. Which is better, Apache or Nginx?
    Both are excellent web servers. Apache is known for its flexibility, while Nginx excels in handling high traffic with minimal resources.
  2. Can I install both Apache and Nginx together?
    It’s not recommended to run both on the same server to avoid port conflicts unless specifically configured.
  3. How do I find my VM’s IP address?
    Run ip a in the terminal to locate your IP address.
  4. Can I use this setup for hosting a live website?
    Yes, but ensure your VM is configured with a public IP and necessary security measures.
  5. What’s the difference between HTTP and HTTPS traffic?
    HTTP is unencrypted, while HTTPS ensures secure communication by using encryption.

Conclusion

You’ve successfully configured a web server on Rocky Linux using Apache or Nginx. Both options are powerful tools for hosting websites and applications. For more details, watch our step-by-step video tutorial.

See also:

List of monitoring tools 

Linux Blogs

AWS Cloud Blogs

Database Blogs

DevOps Blogs

Interview Questions & Answers

Docker Blogs

Google Cloud Blogs







Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.