Skip to content
Home » Web Server

Web Server

Web Server (Apache): HTTP Protocol, Installation, Control & Configuration


1. Understanding the HTTP Protocol (Quick Recap)

HTTP (HyperText Transfer Protocol) is used for communication between client (browser) and web server.

Working Flow

Browser (Client)
     ↓ HTTP Request
------------------------
   Apache Web Server
------------------------
     ↑ HTTP Response
Browser displays webpage

Key Points

  • Stateless protocol
  • Uses port 80 (HTTP) and 443 (HTTPS)
  • Works on request–response model

2. Installing Apache HTTP Server

Apache is one of the most popular web servers.


2.1 On Ubuntu / Debian

sudo apt update
sudo apt install apache2

2.2 On RHEL / CentOS

sudo yum install httpd

2.3 Verify Installation

Open browser:

http://localhost

👉 Default Apache page should appear.


3. Starting, Stopping & Managing Apache


3.1 Start Apache

sudo systemctl start apache2      # Ubuntu
sudo systemctl start httpd        # RHEL

3.2 Stop Apache

sudo systemctl stop apache2

3.3 Restart Apache

sudo systemctl restart apache2

3.4 Check Status

sudo systemctl status apache2

3.5 Enable at Boot

sudo systemctl enable apache2

4. Apache Directory Structure


Ubuntu

  • /etc/apache2/ → Configuration files
  • /var/www/html/ → Web files
  • /etc/apache2/sites-available/ → Virtual hosts
  • /etc/apache2/sites-enabled/ → Active sites

RHEL

  • /etc/httpd/ → Config files
  • /var/www/html/ → Web root

5. Configuring Apache


5.1 Main Configuration File

Ubuntu:

/etc/apache2/apache2.conf

RHEL:

/etc/httpd/conf/httpd.conf

5.2 Basic Configuration Example

ServerName localhost
DocumentRoot /var/www/html

5.3 Creating a Simple Web Page

sudo vi /var/www/html/index.html

Example:

<h1>Welcome to My Apache Server</h1>

5.4 Virtual Host Configuration

Create file:

sudo vi /etc/apache2/sites-available/example.conf

Example:

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

Enable site:

sudo a2ensite example.conf
sudo systemctl reload apache2

5.5 Directory Permissions

chmod -R 755 /var/www
chown -R www-data:www-data /var/www

5.6 Listening Port Configuration

sudo vi /etc/apache2/ports.conf

Example:

Listen 80

6. Testing Apache Server


Using Browser

http://localhost

Using Command Line

curl http://localhost

7. Firewall Configuration

sudo ufw allow 80
sudo ufw allow 443

8. Logs in Apache

Log FilePurpose
access.logClient requests
error.logErrors

Location:

/var/log/apache2/

9. Real-World Example

  • Hosting website:
    • Files in /var/www/html
    • Apache serves pages via HTTP
  • Used in:
    • Company websites
    • E-commerce platforms
    • APIs

10. Advantages of Apache

  • Open source
  • Highly configurable
  • Supports modules
  • Cross-platform
  • Secure and stable

11. Conclusion

Apache HTTP Server is a powerful and widely used web server in Linux. Understanding HTTP, installation, service management, and configuration enables efficient web hosting and server administration, making it essential for developers and system administrators.