// The world's most popular web server.
APACHE2 IS THE BACKBONE OF THE WEB.
Serving over 30% of all websites, Apache HTTP Server is the most widely used web server software. It's free, open-source, and incredibly powerful.
WHY APACHE2?
Apache2 offers unmatched flexibility through its module system, supports all major protocols, and runs on virtually every operating system. The .htaccess feature allows per-directory configuration without access to main config files.
TAKE CONTROL.
Learn to configure, secure, and optimize Apache2. Host multiple websites, enable SSL/TLS, implement rewrite rules, and master the art of web server administration.
12 lessons. Complete Apache2 control.
World's most popular web server fundamentals.
BeginnerInstall and configure on any Linux distribution.
BeginnerMaster httpd.conf and configuration syntax.
BeginnerHost multiple websites on one server.
IntermediateExtend functionality with loadable modules.
IntermediateSecure sites with Let's Encrypt certificates.
IntermediatePer-directory config and mod_rewrite rules.
IntermediatePassword protection and access control.
IntermediateForward requests to backend applications.
AdvancedHarden Apache against attacks and exploits.
AdvancedClustering and failover configurations.
AdvancedFix configuration errors and optimize.
AdvancedApache HTTP Server has been the backbone of the internet since 1995. Its modular architecture, vast ecosystem, and rock-solid stability make it the choice for everything from personal blogs to enterprise deployments.
Unlike proprietary web servers, Apache2 is completely free and open source. You have full access to the source code, can modify it, and distribute your changes. This transparency is essential for security and trust.
Apache2's configuration system is incredibly powerful. With virtual hosts, you can host hundreds of websites on a single server. With mod_rewrite, you have complete control over URLs. With SSL/TLS, you can secure every connection.
The web runs on Apache. Now you can too.
Apache HTTP Server (Apache2) is the world's most widely-used web server software. Originally created in 1995, Apache has been the dominant web server for over two decades. The "2" in Apache2 refers to the major version number, representing a complete rewrite of the original codebase.
Apache2 offers several advantages:
1. Apache2 was first released in _____.
Hint: Mid-1990s
2. The
Hint: Major version
3. Apache2 is an example of _____ software.
Hint: Free with source code
4. The default document root on Ubuntu is _____.
Hint: Under /var/www
5. Virtual hosts allow hosting _____ websites on one server.
Hint: More than one
6. The main Apache2 configuration file is _____.
Hint: In /etc/apache2/
7. Apache2 uses _____ to enable/disable functionality.
Hint: Like plugins
8. To check Apache2 version, use _____ -v.
Hint: The binary name
Installing Apache2 on Debian-based systems is straightforward using apt:
On RHEL-based systems, use dnf or yum:
After installation, verify Apache2 is serving pages:
Or open http://localhost in your browser. You should see the default Apache2 page.
1. On Ubuntu, Apache2 is installed with the _____ command.
Hint: Uses apt package manager
2. On CentOS, the package is called _____.
Hint: Not apache2
3. To start Apache2 on systemd, use _____.
Hint: systemctl
4. To enable Apache2 on boot, use _____ enable.
Hint: systemctl enable
5. The apache2-utils package contains _____.
Hint: Like htpasswd
6. You can test Apache2 with _____ localhost.
Hint: Command-line HTTP client
7. On RHEL, config files are in _____ instead of /etc/apache2/.
Hint: Different path
8. After config changes, you should _____ Apache2.
Hint: systemctl restart
Apache2 configuration is organized in a hierarchical structure. Understanding this structure is key to effective server administration.
The primary configuration file. On Ubuntu/Debian, it's designed to be modular:
The top-level directory containing configuration files:
Specify IP addresses and ports Apache2 listens on:
The directory containing web files:
The
Always test configuration before restarting:
Apache2 uses Include directives to load additional configuration:
1. The main Apache2 configuration file is _____.
Hint: In /etc/apache2/
2. The _____ directive specifies the web root directory.
Hint: Where files are served from
3. To specify which ports Apache listens on, use _____.
Hint: Listen 80
4. The _____ block controls access to directories.
Hint: XML-like tag
5. To test config syntax, use _____.
Hint: apache2ctl
6. On RHEL, Apache2 config is in _____ directory.
Hint: Different from Debian
7. The ServerAdmin directive sets the _____ email.
Hint: For error pages
8. Include directives load additional _____ files.
Hint: Config files
Virtual hosts allow Apache2 to serve multiple websites from a single server. This is essential for web hosting and development.
Create a configuration file in /etc/apache2/sites-available/:
The default site serves requests that don't match any ServerName:
You can have multiple virtual hosts:
Make sure Listen 8080 is in ports.conf:
1. _____ virtual hosts use one IP for multiple domains.
Hint: Most common type
2. To enable a site, use _____.
Hint: Apache2 enable site
3. To disable a site, use _____.
Hint: Apache2 disable site
4. The ServerAlias directive creates _____ names for a site.
Hint: Additional domain names
5. Virtual host configs are in _____ directory.
Hint: Available sites
6. To listen on port 8080, add _____ 8080.
Hint: In ports.conf
7. _____ reload gracefully updates the config.
Hint: Without interrupting
8. The default site serves requests matching no _____.
Hint: Domain name
One of Apache2's greatest strengths is its modular architecture. Modules can be enabled or disabled to add or remove functionality.
Some modules have their own configuration files:
Load external modules using LoadDirective:
MPMs handle how Apache2 accepts and handles connections:
1. To enable a module, use _____.
Hint: Apache2 enable module
2. To list loaded modules, use _____.
Hint: List modules
3. mod_rewrite provides _____ rewriting.
Hint: Clean URLs
4. mod_ssl provides _____ support.
Hint: HTTPS
5. The _____ MPM uses threads for connections.
Hint: Threaded MPM
6. PHP requires the _____ MPM.
Hint: Non-threaded
7. To disable a module, use _____.
Hint: Apache2 disable module
8. Modules are stored in _____ directory.
Hint: Available modules
SSL/TLS encrypts communication between the server and clients, protecting sensitive data from interception. It's essential for security and SEO.
Redirect all HTTP traffic to HTTPS:
1. _____ encrypts communication between server and client.
Hint: HTTPS
2. To enable SSL, use _____.
Hint: Enable SSL module
3. Let
Hint: DV certificates
4. The SSLCertificateFile directive specifies the _____.
Hint: Public key file
5. The SSLCertificateKeyFile directive specifies the _____.
Hint: Secret key file
6. To redirect HTTP to HTTPS, use _____ directive.
Hint: Permanent redirect
7. Self-signed certificates are for _____ only.
Hint: Not production
8. certbot is used to obtain _____ certificates.
Hint: From Let
The .htaccess file allows per-directory configuration without access to the main server configuration. It's incredibly powerful for shared hosting and per-site customization.
First, enable AllowOverride in your virtual host:
Create a password file:
Create .htaccess:
Enable mod_rewrite first:
Convert /article.php?id=123 to /article/123:
1. The .htaccess file allows _____ configuration.
Hint: Without main config
2. To enable .htaccess, set AllowOverride to _____.
Hint: Allow all directives
3. htpasswd creates a _____ file.
Hint: For authentication
4. mod_rewrite provides _____ rewriting.
Hint: Clean URLs
5. The R=301 flag means _____ redirect.
Hint: HTTP 301
6. The [L] flag means _____ rule.
Hint: Last rule, stop processing
7. ErrorDocument handles _____ pages.
Hint: 404, 500, etc.
8. To block an IP, use _____ from.
Hint: Deny from IP
Apache2 provides multiple authentication mechanisms to protect your web resources. Understanding these methods is essential for securing sensitive content.
The simplest form of authentication. Credentials are sent base64-encoded (not encrypted) and should only be used with HTTPS:
More secure than Basic auth as passwords are never sent over the network:
Authenticate against an LDAP directory server:
Place authentication directives in .htaccess for per-directory protection:
1. Basic auth sends credentials _____ encoded.
Hint: Not encrypted
2. _____ authentication never sends passwords over the network.
Hint: Uses MD5 hash
3. Use _____ to create password files for Basic auth.
Hint: Apache utility
4. _____ integrates Apache with directory servers.
Hint: Lightweight Directory
5. Require _____ grants access to valid users only.
Hint: Any valid user
6. _____ files allow per-directory auth config.
Hint: Distributed config
7. Require _____ 192.168.1.0/24 allows that subnet.
Hint: IP-based access
8. AuthGroupFile defines user _____ for authorization.
Hint: User collections
A reverse proxy sits between clients and backend servers, forwarding client requests to the appropriate backend. It's essential for load balancing, SSL termination, and application delivery.
Enable WebSocket support for real-time applications:
1. ProxyPass forwards requests to _____ servers.
Hint: Upstream servers
2. _____ preserves the original Host header.
Hint: Keep original host
3. BalancerMember defines _____ in a cluster.
Hint: Pool members
4. mod_proxy_ enables WebSocket proxy support.
Hint: WS tunnel module
5. _____ handles SSL at the proxy level.
Hint: SSL offloading
6. loadfactor controls the _____ of traffic.
Hint: Traffic split
7. _____ monitors backend server health.
Hint: hcmethod/hcuri
8. status=+H marks a server as _____.
Hint: Standby mode
ModSecurity is an open-source WAF that protects against SQL injection, XSS, and other attacks. It provides real-time monitoring and blocking.
Enable mod_headers to add security headers:
CSP prevents XSS by controlling which resources can load:
1. ModSecurity is a _____ firewall.
Hint: WAF
2. _____ prevents clickjacking attacks.
Hint: Frame control
3. CSP stands for Content _____ Policy.
Hint: Security policy
4. mod_ provides DDoS protection.
Hint: Evasive
5. _____ hides Apache version info.
Hint: Server tokens
6. HSTS enforces _____ connections.
Hint: Secure transport
7. _____ prevents MIME type sniffing.
Hint: Content type header
8. CRS stands for Core Rule _____.
Hint: Rule collection
High availability ensures your web services remain accessible even during server failures. This involves multiple Apache instances, load balancing, and session persistence.
Run multiple Apache instances on different ports or servers:
External load balancer in front of Apache cluster:
1. Multiple Apache instances run on different _____.
Hint: Network ports
2. _____ stores session data in memory cache.
Hint: Memory cache daemon
3. _____ provides in-memory data structure store.
Hint: Remote dictionary server
4. Sticky _____ keeps users on the same server.
Hint: Session affinity
5. status=+H marks a server as _____.
Hint: Backup server
6. _____ checks monitor server health.
Hint: Health checks
7. A cluster of servers provides _____ availability.
Hint: HA
8. _____ insert adds session cookies.
Hint: Cookie directive
When Apache2 fails or behaves unexpectedly, a systematic approach saves time. This lesson covers diagnostic tools and common issues.
The first place to check when something goes wrong:
Increase verbosity for detailed debugging:
Trace system calls for deep debugging:
1. _____ logs contain detailed error information.
Hint: error.log
2. _____ analyzes access log patterns.
Hint: Text processing
3. Permission denied means check file _____.
Hint: chown/chmod
4. mod_dumpio logs request and response _____.
Hint: Full content
5. _____ traces system calls.
Hint: System trace
6. apache2ctl -X runs in _____ mode.
Hint: Foreground mode
7. _____ configtest checks syntax.
Hint: Apache control
8. _____ -S shows virtual host config.
Hint: Apache control