Apache
— ny_wk

Disclosure: some links above are affiliate links — if you buy through them I may earn a small commission at no extra cost to you. Thanks for supporting the channel!
Apache HTTP Server interview questions show up in almost every Linux system administrator and DevOps screening, because Apache still powers a huge share of the web. This guide organizes the most-asked Apache interview questions and answers into clear topic sections, corrects the common myths, and updates every command for modern Apache 2.4 on both Red Hat and Debian family systems.
Treat each section as a study unit rather than a flashcard dump. Read the explanation, run the command on a test server, and you will be able to answer follow-ups confidently instead of reciting a memorized line. All examples use real, current syntax, and where a legacy answer is still floating around the internet, it is flagged and corrected.
Apache Fundamentals: What Interviewers Expect First
Early questions check whether you actually understand what the server does, not just that you can start it. Be precise with terminology here.
What is the Apache HTTP Server?
Apache HTTP Server (often called httpd) is a free, open-source, cross-platform web server maintained by the Apache Software Foundation. It speaks HTTP/HTTPS, the protocol browsers and clients use to request and receive web content. Its strengths are its modular architecture, extensive configuration through directives, support for virtual hosting, SSL/TLS, CGI, reverse proxying, and a massive ecosystem of modules.
What is the Apache daemon and which user does it run as?
The running process is the httpd daemon (named apache2 on Debian/Ubuntu). For security, the parent process starts as root so it can bind to privileged port 80, then spawns worker children that drop to an unprivileged account. On RHEL/CentOS/Rocky/AlmaLinux that account is the apache user; on Debian/Ubuntu it is www-data.
Correction: an older, widely copied answer claims Apache "runs as the user nobody." That is outdated. Modern distributions use a dedicated apache or www-data account precisely so that web content is isolated from other services. Verify on any box with:
ps -ef | grep -E 'httpd|apache2'— the first column shows the owning user of each worker.- Check the configured value:
grep -Ei '^User|^Group' /etc/httpd/conf/httpd.conf(or/etc/apache2/apache2.confand/etc/apache2/envvarson Debian).
What is the difference between a daemon and a service?
A daemon is a background process not attached to a terminal — httpd itself is a daemon. A service is the broader managed unit that systemd or init starts, stops, and supervises. In everyday admin language they overlap, but the clean answer is: "Apache is a service managed by systemd, and that service runs one or more httpd daemon processes."
Apache Installation, Versions, and Configuration Files
This block separates candidates who have only read about Apache from those who have installed and operated it.
How do you install Apache on Linux?
Use the distribution package manager:
- RHEL / CentOS / Rocky / AlmaLinux / Fedora:
sudo dnf install httpd(older systems usedyum install httpd). - Debian / Ubuntu:
sudo apt update && sudo apt install apache2.
How do you check the Apache version?
Query the binary directly:
- RHEL family:
httpd -vand confirm the package withrpm -qa | grep httpd. - Debian family:
apache2 -vand confirm withdpkg -l | grep apache2.
Knowing the major version matters because Apache 2.4 is today's standard and differs significantly from the long-dead 2.2 series — most importantly in access control syntax (covered below).
Where are the main Apache configuration files?
Memorize the layout for both families, because mixing them up is a classic interview trip-up.
| Item | RHEL / CentOS / Fedora | Debian / Ubuntu |
| Main config | /etc/httpd/conf/httpd.conf | /etc/apache2/apache2.conf |
| Config drop-in dir | /etc/httpd/conf.d/ | /etc/apache2/conf-enabled/ |
| Virtual hosts | files in /etc/httpd/conf.d/ | /etc/apache2/sites-available/ (enabled via a2ensite) |
| Modules | /etc/httpd/conf.modules.d/ | /etc/apache2/mods-available/ (enabled via a2enmod) |
| Listening ports | in httpd.conf | /etc/apache2/ports.conf |
| Document root (default) | /var/www/html | /var/www/html |
| Access / error logs | /var/log/httpd/ | /var/log/apache2/ |
Correction: the Debian main file is /etc/apache2/apache2.conf — not /etc/apache2.conf as some cheat sheets wrongly state.
Apache Interview Questions on Ports and Listening
Networking fundamentals frequently anchor an Apache interview, so be exact about ports and the Listen directive.
Which ports does Apache use?
By default Apache listens on port 80 (HTTP) and port 443 (HTTPS/TLS). Both are TCP. Confirm what is actually bound with the modern tool ss (the old netstat is deprecated but still works):
sudo ss -tlnp | grep -E ':80|:443'- Legacy equivalent:
sudo netstat -tlnp | grep httpd
How does the Listen directive work, and how do you change the port?
The Listen directive tells Apache which port and, optionally, which IP/interface to bind. To run on a custom port, edit the config and restart:
- Open the relevant file (
httpd.confon RHEL,ports.confon Debian). - Change
Listen 80to, for example,Listen 8080, or bind a specific interface withListen 192.168.0.10:8080. - If SELinux is enforcing on RHEL, allow the new port:
sudo semanage port -a -t http_port_t -p tcp 8080. - Validate syntax:
sudo apachectl configtest. - Restart:
sudo systemctl restart httpd(orapache2).
Can two Apache instances run on one machine?
Yes — either by using virtual hosts under a single httpd service, or by running genuinely separate instances. Separate instances must listen on different ports or different IP addresses so they do not collide on the same socket.
Controlling the Apache Service: Start, Stop, Restart
How do you start, stop, and restart Apache?
On any modern Linux running systemd, manage the service with systemctl; the cross-platform helper apachectl also works everywhere.
- Start:
sudo systemctl start httpd - Stop:
sudo systemctl stop httpd - Restart:
sudo systemctl restart httpd - Enable at boot:
sudo systemctl enable httpd
Correction: answers citing /etc/init.d/httpd stop or chkconfig --level 35 httpd on describe the retired SysV init era. They survive only as compatibility shims. The current, correct tooling is systemctl. (Also note the frequently miscopied path /etc/inid.t/httpd is simply a typo for /etc/init.d/httpd.)
What is the difference between restart and graceful?
This is a favorite question. With apachectl restart, Apache stops and starts immediately, dropping in-flight connections. With apachectl graceful, Apache reloads configuration without killing active requests — existing connections finish on the old config while new ones use the new config. Use graceful on a busy production server to avoid interrupting users. The systemd equivalent is sudo systemctl reload httpd.
Apache Virtual Hosts Interview Questions
Virtual hosting — serving many sites from one server — is the backbone of shared and reseller hosting, so expect detailed questions.
What is a virtual host and what are the minimum directives?
A virtual host is a configuration block that lets one Apache instance serve multiple websites. The two mandatory directives are ServerName (the hostname) and DocumentRoot (where the files live). Common extras are ServerAlias, ServerAdmin, ErrorLog, and CustomLog.
What is the difference between name-based and IP-based virtual hosting?
- Name-based: many domains share a single IP. Apache picks the right site using the
Host:header (and SNI for HTTPS). It is the common, cost-effective choice. - IP-based: each site gets its own IP address. Historically required for SSL before SNI existed, or for strict isolation.
Important Apache 2.4 update: the old NameVirtualHost directive is obsolete and removed in 2.4. You no longer declare it — name-based hosting works automatically when multiple <VirtualHost> blocks share an address. Cheat sheets telling you to "uncomment NameVirtualHost" are out of date.
How do you configure a name-based virtual host (Apache 2.4)?
- Create the document root:
sudo mkdir -p /var/www/example1.com/html - Add a landing page:
echo 'Welcome to example1.com' | sudo tee /var/www/example1.com/html/index.html - Create a config block (Debian:
/etc/apache2/sites-available/example1.com.conf; RHEL:/etc/httpd/conf.d/example1.com.conf):<VirtualHost *:80>ServerName www.example1.comServerAlias example1.comDocumentRoot /var/www/example1.com/htmlErrorLog ${APACHE_LOG_DIR}/example1.com-error.logCustomLog ${APACHE_LOG_DIR}/example1.com-access.log combined</VirtualHost>
- On Debian enable it:
sudo a2ensite example1.com. - Test syntax:
sudo apachectl configtest(expectSyntax OK). - Reload:
sudo systemctl reload apache2.
What is DocumentRoot, and what is the Alias directive?
DocumentRoot is the top directory from which Apache serves files for a host (default /var/www/html). The Alias directive (from mod_alias) maps a URL path to a directory outside the document root. For example, Alias /images /var/data/images/ makes a request for /images/logo.png serve /var/data/images/logo.png.
Core Directives, .htaccess, and Access Control
What is DirectoryIndex?
DirectoryIndex sets which file Apache serves when a client requests a directory rather than a specific file, for example DirectoryIndex index.html index.php. If none of the listed files exist, Apache either lists the directory or returns 403, depending on your options.
How do you turn directory listing on or off?
Directory listing is controlled by the Indexes option (provided by mod_autoindex):
- Turn it off (the secure default):
Options -Indexes - Turn it on:
Options +Indexes
Apply this in the relevant <Directory> block or in a per-directory .htaccess file.
What is .htaccess and what does htpasswd do?
An .htaccess file applies directives to the directory it sits in (and below) without restarting Apache — convenient when you cannot edit the main config, but slower because Apache reads it on every request. For performance, enable it only where needed via AllowOverride. The htpasswd utility creates and manages the username/password file used for HTTP Basic authentication, e.g. htpasswd -c /etc/apache2/.htpasswd alice.
What is the difference between the Directory and Location blocks?
<Directory> matches paths on the filesystem; <Location> matches the URL as requested. Use <Directory> for real folders and <Location> for virtual URLs (such as a status handler) that have no direct filesystem mapping.
If both "allow" and "deny" apply, which wins? (and the 2.4 update)
In legacy Apache 2.2, with Order deny,allow/Order allow,deny the result depended on the Order directive, and in the classic ambiguous case deny took precedence. This entire model is deprecated. Apache 2.4 replaces it with the mod_authz_host Require syntax:
- Allow everyone:
Require all granted - Deny everyone:
Require all denied - Restrict by network:
Require ip 192.168.1.0/24
Stating the modern Require directives, then noting the old Allow/Deny/Order for context, is the answer that signals current knowledge.
Apache Performance: MPM and Modules Interview Questions
What is an MPM in Apache?
MPM stands for Multi-Processing Module — the component that decides how Apache accepts connections and dispatches work across processes and threads. The choice of MPM is the single biggest lever on Apache's concurrency and memory behavior.
What is the difference between prefork, worker, and event MPMs?
| MPM | Model | Concurrency | Best for |
| prefork | Multiple processes, one thread each | One connection per process | Non-thread-safe modules (e.g. classic mod_php); higher memory use |
| worker | Multiple processes, many threads each | One connection per thread | Lower memory, higher concurrency than prefork |
| event | Threaded, with a dedicated listener for keep-alive | Handles idle keep-alive connections efficiently | The modern default on Apache 2.4; best for high-traffic, many idle connections |
Update: older guides only mention prefork vs worker. Apache 2.4 added the event MPM as the default on most distributions because it solves the keep-alive scaling problem. For PHP today, the recommended pairing is event MPM with PHP-FPM over mod_proxy_fcgi, rather than the memory-heavy mod_php with prefork.
What are mod_perl, mod_php, mod_ssl, mod_evasive, and mod_security?
- mod_perl embeds a Perl interpreter in Apache so Perl handlers run in-process for speed.
- mod_php embeds the PHP interpreter into Apache. It works only with prefork and increases per-process memory; modern stacks prefer PHP-FPM.
- mod_ssl provides HTTPS by adding TLS/SSL support via OpenSSL.
- mod_evasive is a third-party module that mitigates HTTP DoS/DDoS and brute-force floods by rate-limiting abusive clients.
- mod_security is a web application firewall (WAF) that inspects requests against rule sets (such as the OWASP Core Rule Set) to block common attacks like SQL injection and XSS.
How do you limit upload size with LimitRequestBody?
LimitRequestBody caps the size, in bytes, of a request body Apache will accept — useful for restricting uploads. For example, to cap uploads in a directory at 100,000 bytes, place inside its <Directory> block: LimitRequestBody 100000.
HTTP Status Codes, Logs, and Troubleshooting
What do the 2xx, 3xx, 4xx, and 5xx codes mean?
- 2xx Success — the request was received and processed (e.g. 200 OK).
- 3xx Redirection — further action needed, such as a redirect (301/302).
- 4xx Client Error — the request was bad or unauthorized (403 Forbidden, 404 Not Found).
- 5xx Server Error — the server failed to fulfil a valid request (500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable).
What are the Apache log files, and what does LogLevel debug do?
The two primary logs are the access log (every request) and the error log (problems and diagnostics), in /var/log/httpd/ (RHEL) or /var/log/apache2/ (Debian). Setting LogLevel debug in the config makes Apache record far more detail in the error log, which is invaluable when diagnosing a misbehaving site. Return it to warn or error afterward to keep logs manageable.
What does "connection reset by peer" mean in the error log?
It means the client closed the connection before Apache finished sending the response — for example a user who navigated away or a flaky network. It is usually a client-side event, not an Apache fault, though a flood of them can indicate timeouts or an overloaded backend.
How do you dump HTTP traffic for analysis?
Capture port 80 packets to a file with tcpdump: sudo tcpdump -i any tcp port 80 -s 0 -w http.out. Open http.out later in Wireshark or replay it with tcpdump -r http.out.
Apache Security and Hardening Interview Questions
Security questions separate junior from senior candidates. Know these cold.
How do you hide the Apache version and OS in responses?
By default Apache advertises its version and OS in error pages and the Server: header — useful intelligence for attackers. Suppress it in the main config:
ServerTokens Prod— theServer:header reports only "Apache", hiding version and OS.ServerSignature Off— removes the version footer from Apache-generated error pages.- Apply and reload:
sudo systemctl reload httpd.
How does SSL/TLS work with Apache?
Apache uses mod_ssl to terminate HTTPS. The certificate workflow is:
- Generate a private key and a Certificate Signing Request (
.csr) on the server. - Submit the CSR to a Certificate Authority (CA).
- The CA validates and returns a signed certificate (
.crt). - Reference the key and certificate in the SSL virtual host (
SSLCertificateFile,SSLCertificateKeyFile) and restart.
Modern note: for public sites you rarely buy a certificate today — Let's Encrypt with the certbot tool issues and auto-renews free, trusted certificates, and configures the Apache virtual host for you.
Can Apache be secured with TCP wrappers?
No. Apache's httpd binary is not linked against libwrap, so /etc/hosts.allow and /etc/hosts.deny do not apply to it. Restrict access using Apache's own Require directives or a host firewall (firewalld/nftables) instead.
What is a reverse proxy, and is Apache or Squid better for it?
A reverse proxy sits in front of one or more backend servers and forwards client requests to them, often adding caching, TLS termination, or load balancing. Apache does this well with mod_proxy and mod_proxy_http. Squid is a caching proxy historically favored for forward/caching proxy roles, while in modern stacks Nginx and HAProxy are the common reverse-proxy choices alongside Apache — mention them to show current awareness.
How do you redirect multiple hostnames to one canonical name?
If example.com, www.example.com, and example.net all serve the same site, pick one canonical hostname and 301-redirect the rest, which is better for SEO and caching. Two approaches:
- A virtual host that issues a permanent redirect:
Redirect permanent / https://www.example.com/. mod_rewritewithRewriteEngine Onand a rule that rewrites non-canonical hosts to the canonical one.
Key Takeaways
- Master both RHEL and Debian paths and tooling —
httpdvsapache2,dnfvsapt, and the differing config and log locations are constant interview fodder. - Always answer with Apache 2.4 syntax: use
Require all granted/deniedinstead ofOrder/Allow/Deny, and skip the removedNameVirtualHostdirective. - Apache runs as the unprivileged apache (RHEL) or www-data (Debian) user — not
nobody— and is managed bysystemctl, not legacyinit.d/chkconfig. - Know the MPMs: prefork (process-per-connection), worker (threaded), and the modern default event MPM, ideally paired with PHP-FPM rather than
mod_php. - For hardening, recall
ServerTokens Prod,ServerSignature Off,Options -Indexes, a WAF like mod_security, and free TLS via Let's Encrypt/certbot.
Frequently Asked Questions
What is the difference between httpd and apache2?
They are the same software — the Apache HTTP Server — packaged under different names. Red Hat-based distributions (RHEL, CentOS, Rocky, AlmaLinux, Fedora) call the package and service httpd, while Debian-based distributions (Debian, Ubuntu) call them apache2. The config layouts also differ, but the underlying server is identical.
How do I check if Apache is running?
Run sudo systemctl status httpd (or apache2) to see whether the service is active and view recent log lines. You can also confirm it is bound to its ports with sudo ss -tlnp | grep -E ':80|:443', or simply request a page with curl -I http://localhost/ and check for an HTTP response header.
Is Apache or Nginx better for an interview answer?
Neither is universally "better" — explain the trade-off. Apache is highly flexible with per-directory .htaccess overrides and a vast module ecosystem; Nginx uses an event-driven model that excels at serving static files and high concurrency with low memory. A strong answer notes that many production stacks combine them: Nginx as a front-end reverse proxy or load balancer with Apache behind it, or Apache with the event MPM and PHP-FPM for dynamic apps.
What is the default Apache document root?
On both RHEL and Debian families the default DocumentRoot is /var/www/html (some setups use /var/www). You can change it per site with the DocumentRoot directive inside a virtual host — just make sure the new directory has correct ownership and, on RHEL, the right SELinux context (httpd_sys_content_t).
For more Linux and Apache admin walkthroughs, subscribe on YouTube @explorenystream.