The Apache HTTP Server is one of the most widely used web servers in the world. It powers millions of websites and is commonly used in the LAMP Stack, which includes Linux, Apache, MySQL, and PHP.
For developers building web applications (Laravel, PHP, Node.js, etc.), understanding how Apache works helps with deployment, performance, routing, and security.
This guide explains Apache step-by-step.
1. What is Apache Web Server?
Apache is open-source web server software that delivers web content to users through HTTP/HTTPS.
When someone visits a website:
Browser → Web Server → Application → Database
Apache acts as the middle layer that receives the request and returns the response.
Example:
User visits:
https://example.com
Apache processes the request and returns:
HTML
CSS
JavaScript
Images
API responses
2. How Apache Works (Request Lifecycle)
When a user visits a website, Apache processes the request in several steps.
Step 1 — Browser Sends HTTP Request
Example request:
GET /index.php HTTP/1.1
Host: example.com
The browser sends this request to the Apache server.
Step 2 — Apache Receives Request
Apache listens on a port.
Common ports:
80 → HTTP
443 → HTTPS
Apache checks:
-
Domain name
-
Requested file
-
Server configuration
Step 3 — Virtual Host Selection
Apache determines which website configuration to use.
Example configuration:
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/example
</VirtualHost>
This tells Apache:
If domain = example.com
Serve files from /var/www/example
Step 4 — Apache Processes the Request
Apache decides how to process the request.
Example:
Request:
/index.html
Apache returns a static file.
Request:
/index.php
Apache sends the file to PHP for execution.
Step 5 — Application Runs
If the application uses a framework like Laravel, Apache routes the request through:
public/index.php
Laravel then processes:
Route → Controller → Model → Response
Step 6 — Apache Sends Response
Apache returns the response to the browser:
HTTP/1.1 200 OK
Content-Type: text/html
Then the user sees the webpage.
3. Apache Directory Structure
Typical Apache directories:
/etc/apache2/
/var/www/html/
/etc/apache2/sites-available/
/etc/apache2/sites-enabled/
Example:
/var/www/html
Contains website files.
Example:
/var/www/project/public
Laravel public directory.
4. Apache Configuration Files
Important configuration files:
Main Config
/etc/apache2/apache2.conf
Controls global server behavior.
Ports Configuration
/etc/apache2/ports.conf
Example:
Listen 80
Listen 443
Virtual Hosts
/etc/apache2/sites-available/
Example file:
example.conf
Example Virtual Host:
<VirtualHost *:80>
ServerName myapp.test
DocumentRoot /var/www/myapp/public
<Directory /var/www/myapp>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
5. Apache Modules
Apache works using modules.
Modules add functionality.
Common modules:
| Module | Purpose |
|---|---|
| mod_rewrite | URL rewriting |
| mod_ssl | HTTPS support |
| mod_headers | HTTP headers |
| mod_proxy | Reverse proxy |
| mod_deflate | Compression |
Example enabling a module:
sudo a2enmod rewrite
Restart Apache:
sudo systemctl restart apache2
6. Apache .htaccess File
The .htaccess file allows directory-level configuration.
Example:
/public/.htaccess
Laravel uses .htaccess for routing.
Example:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
This means:
All routes → index.php
Laravel then handles routing.
7. Apache vs Nginx
Another popular server is Nginx.
Comparison:
| Feature | Apache | Nginx |
|---|---|---|
| Architecture | Process-based | Event-based |
| .htaccess | Supported | Not supported |
| Performance | Good | Very high |
| Configuration | Flexible | Lightweight |
Typical setups:
Small projects → Apache
High traffic apps → Nginx
8. Apache with PHP Applications
Apache commonly runs PHP applications like:
-
Laravel
-
WordPress
-
Drupal
Deployment example:
/var/www/laravel-app
Document root:
/var/www/laravel-app/public
9. Apache Security Best Practices
Important Apache security settings:
Disable directory listing
Options -Indexes
Hide server information
ServerSignature Off
ServerTokens Prod
Enable HTTPS
Using OpenSSL certificates.
10. Apache Performance Optimization
For production servers:
Enable compression
a2enmod deflate
Enable caching
a2enmod expires
Adjust worker settings
Example:
MaxRequestWorkers
KeepAlive
11. When Developers Use Apache
Developers typically use Apache for:
✔ PHP applications
✔ Laravel projects
✔ WordPress hosting
✔ API servers
✔ Development environments
It is extremely popular in shared hosting environments.
Conclusion
The Apache HTTP Server is a powerful and flexible web server used by developers worldwide.
Understanding Apache helps developers:
-
Deploy web applications
-
Configure routing
-
Improve performance
-
Secure web servers
-
Debug production issues
Apache remains a key technology in modern web development and is still widely used alongside servers like Nginx.
