← Back to list

Mastering Apache Web Server on CentOS: Installation, Configuration, and Virtual Hosts

Learn to install, configure, and manage the Apache web server on CentOS, including virtual hosts and best practices for beginners.

codingsprints in InfoSec Write-ups · 2025-04-30 03:32 · 0 claps · 4.1 min read paywalled
#apache-web-server #centos-server #virtual-host #basic-web-hosting #server-configuration
Open on Medium ↗

Mastering Apache Web Server on CentOS: Installation, Configuration, and Virtual Hosts

Learn to install, configure, and manage the Apache web server on CentOS, including virtual hosts and best practices for beginners.

Get started with Apache web server installation, setup, and hosting multiple websites on CentOS easily!

Introduction

Apache HTTP Server, simply known as Apache, is one of the oldest and most reliable open-source web servers, developed by the Apache Software Foundation. It powers millions of websites across the globe, serving static files like HTML, CSS, and JavaScript efficiently.

In today’s tutorial, we’ll walk through how to install Apache on CentOS, configure your first website, and even host multiple websites using Apache’s Virtual Host feature. 📡

Understanding the fundamentals of Apache is essential if you aim to work in web development, DevOps, or system administration.

What Is Apache Web Server?

Definition: Apache is an open-source web server software that manages the delivery of web content to a client over the HTTP protocol.

Key Points:

  • Open-source and free to use.
  • Highly configurable to host multiple sites on one server.
  • Cross-platform — runs on Unix/Linux, Windows, and Mac OS.

💡 Fun Fact: Apache was named because it was a “patchy” server — patched together from various contributions!

Installing Apache on CentOS

Apache installation on CentOS is straightforward since it is available in the default repositories.

Steps to Install:

  • Install Apache HTTP server:
yum install httpd
  • Start the Apache service:
service httpd start
  • Check if Apache is running:
service httpd status

Sample output after **service httpd status**:

Redirecting to /bin/systemctl status httpd.service
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Sun 2020-03-22 12:01:42 UTC; 56s ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 4253 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:  0 B/sec"

Allowing HTTP Traffic Through the Firewall

If you have a firewall enabled, ensure you allow HTTP traffic:

firewall-cmd --permanent --add-service=http
firewall-cmd --reload

Installation Tip: Use **systemctl instead of `service`** on newer CentOS versions!

Understanding Apache Log Files and Configuration

Once Apache is installed, it’s important to know where everything lives:

Log Files (Located at /var/log/httpd/):

  • Access Logs: Updated whenever a user accesses the website.
  • Error Logs: Updated whenever an error occurs.

Main Configuration File:

  • Location: **/etc/httpd/conf/httpd.conf**
  • This file manages various operational parameters, including the port number, location of static content, SSL/HTTPS settings, and log configurations.

Key parameters:

  • **Listen 80** — Apache listens on HTTP port 80.
  • **DocumentRoot "/var/www/html" **— Location where website files are stored.

Hosting Your First Website

By default, Apache serves content from **/var/www/html**. Replace the default page with your HTML files:

cp /path/to/your/index.html /var/www/html/

Then visit your server’s IP address in a browser to see your website!

Example: If your server’s IP is **192.168.1.100, visiting `http://192.168.1.100`** will show your uploaded site.

Configuring Server Name

The ServerName directive tells Apache which domain to respond to.

Example Configuration:

Listen 80
DocumentRoot "/var/www/"
ServerName www.houses.com:80

Local Testing Tip 🧪: To simulate DNS, map the domain in your **/etc/hosts** file:

127.0.0.1   www.houses.com

This way, typing **www.houses.com** In your browser, your local server!

Hosting Multiple Websites with Virtual Hosts

Apache allows multiple websites on a single server via Virtual Hosts.

Virtual Host Example:

<VirtualHost *:80>
    ServerName www.houses.com
    DocumentRoot /var/www/houses
</VirtualHost>

<VirtualHost *:80>
    ServerName www.oranges.com
    DocumentRoot /var/www/oranges
</VirtualHost>

Key Actions:

  • Create directories **/var/www/houses and `/var/www/oranges`**.
  • Place site-specific files (HTML, CSS, JS) inside these directories.
  • Restart Apache for changes to take effect:
service httpd restart

Splitting Virtual Host Configurations for Better Management

Rather than crowding everything into one file, it’s best practice to split Virtual Hosts into separate files.

How To Do It:

  • Modify your main configuration (**httpd.conf) to include** additional configuration files:
ServerName www.houses.com:80

Include conf/houses.conf
Include conf/oranges.conf
  • The contents of **/etc/httpd/conf/houses.conf** could be:
<VirtualHost *:80>
    ServerName www.houses.com
    DocumentRoot /var/www/houses
</VirtualHost>
  • Similarly, **/etc/httpd/conf/oranges.conf** might contain:
<VirtualHost *:80>
    ServerName www.oranges.com
    DocumentRoot /var/www/oranges
</VirtualHost>

For effective local testing, add these entries to your **/etc/hosts** file:

# Host Database
127.0.0.1       localhost
127.0.0.1       www.houses.com
127.0.0.1       www.oranges.com

Advantages:

  • Easier to troubleshoot 🛠️
  • Cleaner configuration 🧹
  • Scalability for more sites 🚀

Bonus: Securing Apache

Security Best Practices:

  • Disable directory listing:
Options -Indexes
  • Hide Apache version details: Edit **/etc/httpd/conf/httpd.conf:**
ServerSignature Off
ServerTokens Prod
  • Always keep Apache updated 🔒

🎯 Conclusion

Congratulations! 🎉 You’ve learned how to install Apache, set up your first website, configure multiple domains with virtual hosts, and secure your server.

Mastering Apache is a fundamental step in any web development or server management journey. Experiment with configurations, dive deeper into modules, and start hosting dynamic content!

💬 Claps, comments, and following the CodingSprints channel are appreciated! 👏

Stay updated and grow your DevOps and programming skills with us:

🔗 Connect with us: 📘 Facebook | 🐦 Twitter | 💻 GitHub | 🔗 LinkedIn

Keep building. Keep learning. See you in the next tutorial! 🚀


메타데이터
post_id
b3a751e7e0cf
slug
mastering-apache-web-server-on-centos-installation-configuration-and-virtual-hosts-b3a751e7e0cf
url
https://infosecwriteups.com/mastering-apache-web-server-on-centos-installation-configuration-and-virtual-hosts-b3a751e7e0cf
canonical_url
https://infosecwriteups.com/mastering-apache-web-server-on-centos-installation-configuration-and-virtual-hosts-b3a751e7e0cf
author_url
https://medium.com/@codingsprints
status
ok
fetched_at
2026-07-22 23:41:08