Home / Guides / WordPress handbook / Chapter 01

WordPress handbook · Chapter 01 · Infrastructure

Complete WordPress Architecture

Most WordPress problems are misdiagnosed because the person fixing them pictures "the website" as one thing. It is a chain of separate systems: DNS, a CDN, a web server, PHP, the WordPress application, a database and several caches. Each can fail independently, and each fails with its own symptoms. This chapter maps the chain so you can say which link broke.

Updated · 21 min read · Level: Intermediate

On this page
  1. What WordPress actually is
  2. Architecture diagram
  3. Core, themes and plugins
  4. PHP, PHP-FPM and the web server
  5. The filesystem and document root
  6. wp-config.php and the WordPress bootstrap
  7. The WordPress database structure
  8. DNS, domains, SSL and HTTPS
  9. CDNs, reverse proxies and the real visitor IP
  10. Caching layers: page, object, browser and opcode
  11. The complete request lifecycle and where it fails

What WordPress actually is

WordPress is an open-source PHP application that stores content and settings in a MySQL-compatible database and builds web pages on request. Nothing in a standard installation is "running" between requests. When a request arrives, the web server starts (or reuses) a PHP process. PHP loads WordPress from disk, WordPress reads its configuration, connects to the database, loads every active plugin and the active theme, works out what was asked for, builds the HTML and hands it back. Then PHP forgets everything. The next request repeats the whole process unless a cache answers first.

That single fact explains a lot of WordPress behaviour:

  • Every active plugin runs on every uncached request, including requests that have nothing to do with it. A slow plugin slows every page, not just the page that uses it.
  • Performance depends heavily on caching. An uncached WordPress page might take 300–1,500 ms of server work. A cached copy is served in a few milliseconds without touching PHP or the database.
  • Scheduled work (WP-Cron) has no clock of its own. By default it piggybacks on visitor requests, so a site with no visitors runs no scheduled tasks.
  • A PHP fatal error in any active plugin or theme can take down the whole site, because all of them load into the same process.
WordPress.org versus WordPress.com

"WordPress" in this manual means the self-hosted software from WordPress.org, installed on hosting you control. WordPress.com is a hosted service run by Automattic. It runs the same core software, but on many plans you cannot install plugins, edit server configuration or reach the database. Much of the infrastructure advice here applies to WordPress.com only on its business-tier plans.

Architecture diagram

WordPress request architecture The visitor's browser resolves the domain through DNS, then connects to a CDN or WAF edge, which forwards to a reverse proxy and then the web server. The web server passes PHP requests to PHP workers, which run WordPress. WordPress reads from the object cache, the database, the filesystem and external APIs. The web server serves static files straight from the filesystem. Visitor's browserbrowser cache · cookies DNS resolverdomain name → IP address CDN / WAF edgeTLS · edge cache · bot rules Reverse proxy / LBVarnish · Nginx · host edge Web serverApache · Nginx · LiteSpeed · page cache PHP runtimePHP-FPM / LSAPI workers · OPcache WordPress applicationwp-config.php → core → mu-plugins→ plugins → theme → template Object cacheRedis / Memcached DatabaseMySQL / MariaDB Filesystemcore · wp-content · uploads Third-party APIspayments · SMTP · updates HTTPS origin FastCGI / LSAPI executes SQL outbound HTTP (wp_remote_get, SMTP) static Responses return along the same path. Any layer from the browser to the web server may cache them.
Figure 1.1: Components a typical WordPress request can pass through. Small sites may have no CDN or reverse proxy; large sites may run several web and database servers.

Read the diagram left to right for a request and right to left for a response. Two shortcuts matter. First, static files (images, CSS, JavaScript, fonts) are usually served by the web server straight from disk and never touch PHP or WordPress. Second, cached pages can be returned by the CDN, the reverse proxy or the web server's page cache without PHP running at all. So a site can be "up" for anonymous visitors (served from cache) while it is completely broken for logged-in administrators, who bypass the cache.

Core, themes and plugins

WordPress core

Core is the code in the root directory, wp-admin/ and wp-includes/, as distributed by WordPress.org. It provides the database layer (wpdb), the hook system (actions and filters), users and roles, the REST API, the block editor, media handling, the update system and the template loader. Core files should never be edited. Updates replace them wholesale, and any modification is either lost or, if left behind by an attacker, a sign of compromise. Core ships with checksums for every file, so you can verify it with wp core verify-checksums.

Themes

A theme controls presentation. Classic themes use PHP template files (header.php, single.php and so on) plus functions.php, which runs on every request just as a plugin does. Block themes use HTML templates and theme.json, and still often include a functions.php. A child theme inherits from a parent theme so that customisations survive parent updates. Only one theme (plus its parent) is active, but every installed theme's files sit on disk and can be reached directly by URL. That is why unused themes with vulnerabilities are still a risk.

Plugins

Plugins are PHP packages in wp-content/plugins/. An active plugin is loaded on every request and can hook into almost anything: it can change queries, add admin pages, register REST endpoints, write files, send email and call external services. A plugin runs with the full privileges of the PHP process, so installing a plugin means trusting its author with the whole site, including the database credentials.

Must-use plugins and drop-ins

wp-content/mu-plugins/ holds must-use plugins. They load automatically before normal plugins, cannot be deactivated from the dashboard, and appear under a separate "Must-Use" tab. Hosts often place platform code here. Attackers like the folder too, because people rarely look in it.

Drop-ins are specially named files directly in wp-content/ that replace parts of core:

Drop-inPurposeTypically created by
advanced-cache.phpServes cached pages very early in loading. Only used when WP_CACHE is true.Page caching plugins
object-cache.phpReplaces the in-memory object cache with a persistent backend such as Redis.Object cache plugins, hosts
db.phpReplaces the database class (query monitoring, alternative databases, read replicas).Query Monitor, HyperDB-style tools
maintenance.phpCustom page shown while the .maintenance file exists.Themes, developers
php-error.php / fatal-error-handler.phpCustom fatal error page / replacement fatal error handler.Developers, hosts
sunrise.phpRuns early on Multisite, often for domain mapping.Multisite setups
Orphaned drop-ins are a classic failure

Uninstalling a caching plugin by deleting its folder can leave advanced-cache.php or object-cache.php behind. WordPress keeps loading them. Results range from stale pages to fatal errors referencing a missing plugin. Site Health lists active drop-ins under Tools → Site Health → Info → Drop-ins.

PHP, PHP-FPM and the web server

PHP is the language WordPress is written in. The PHP interpreter reads the source files, compiles them to opcodes and executes them. OPcache keeps the compiled opcodes in shared memory so the files are not recompiled on every request; it is one of the largest free performance wins available.

Web servers do not execute PHP themselves (except the legacy Apache mod_php). They hand PHP requests to a separate process manager:

  • PHP-FPM (FastCGI Process Manager) runs a pool of PHP worker processes. Nginx and modern Apache setups pass requests to it over a Unix socket or TCP port. Each worker handles one request at a time, so the number of workers caps how many uncached PHP requests the site can process at once. This is the most important capacity number on a WordPress server; Chapter 06 covers it in depth.
  • LSAPI is LiteSpeed's equivalent, used by LiteSpeed Web Server and OpenLiteSpeed.
  • mod_php embeds PHP inside every Apache process. It is simple but memory-hungry, and it runs PHP as the Apache user. It is rare on modern hosting.

The web server (Apache, Nginx or LiteSpeed) accepts the HTTP connection, terminates TLS if no proxy has done so, serves static files from disk, applies rewrite and access rules, and forwards everything else to PHP. Chapter 06 compares the three servers and Chapter 07 covers their configuration.

MySQL and MariaDB

WordPress stores everything except files in a relational database: MySQL or MariaDB. MariaDB began as a fork of MySQL and is wire-compatible for WordPress's purposes; most hosts offer one or the other. WordPress connects using the credentials in wp-config.php, usually to localhost over a Unix socket, or to a separate database server over TCP on managed platforms. Chapter 08 covers the database in depth.

The filesystem and document root

The document root is the directory the web server maps to the website's URL root. Common examples are public_html/ on cPanel, /var/www/example.com/public/ on self-managed servers, htdocs/ on some panels, and /www/ or /sites/ on managed platforms. Every file under the document root can be requested by URL unless a server rule blocks it. That is why backups, logs, exports and configuration files must never sit there unprotected.

PathContentsShould the web server user be able to write here?Security notes
/ (WordPress root)index.php, wp-load.php, wp-settings.php, wp-login.php, xmlrpc.php, wp-cron.php, .htaccessIdeally no, except .htaccess if you want WordPress to manage permalinks on ApacheUnknown PHP files here are a strong sign of compromise. wp-login.php and xmlrpc.php attract brute-force traffic.
wp-config.phpDatabase credentials, keys and salts, constantsNoThe most sensitive file. Permissions 400/440/600 where the host allows. It may be moved one directory above the WordPress root.
wp-admin/Dashboard code, admin-ajax.php, admin-post.phpNo (only during core updates)Front-end features use admin-ajax.php, so blocking all of /wp-admin/ for visitors breaks sites.
wp-includes/Core librariesNo (only during core updates)Should contain only core files; checksums verify it.
wp-content/plugins/PluginsOnly if you update from the dashboardMost real-world compromises start with a vulnerable plugin.
wp-content/themes/ThemesOnly if you update from the dashboardRemove unused themes, but keep one default theme for troubleshooting.
wp-content/uploads/Media in YYYY/MM/ folders, plugin data, form uploads, sometimes cache and backup filesYes. It must be writable.Writable and publicly reachable. PHP execution must be disabled here. See Chapter 04 and Chapter 07.
wp-content/upgrade/, upgrade-temp-backup/Temporary update working directoriesYesLeftovers here can explain failed updates.
wp-content/cache/Page and asset cache from pluginsYesSafe to clear via the plugin; deleting by hand can break the plugin's state.
wp-content/debug.logWordPress debug log when WP_DEBUG_LOG is trueYesPublicly downloadable by default. It can contain paths, queries and personal data. Log to a path outside the document root instead.

WordPress can also live in a subdirectory, for example core in /wp/ while the site is served from /, by changing the siteurl and home options and copying index.php. Some modern stacks (Bedrock, for example) go further and keep wp-config.php, Composer dependencies and environment files entirely outside the web root. Before you edit any file, find out which layout you have.

wp-config.php and the WordPress bootstrap

wp-config.php is plain PHP that runs on every request before anything else in WordPress. It defines the database connection, the table prefix, authentication keys and salts, and any constants that change core behaviour. It ends by loading wp-settings.php, which starts WordPress proper. Constants must be defined above the line /* That's all, stop editing! */. Anything placed after require_once ABSPATH . 'wp-settings.php'; runs too late to affect loading.

<?php
// Database connection. Host may be 'localhost', '127.0.0.1:3306',
// 'localhost:/path/to/mysql.sock' or a managed database hostname.
define( 'DB_NAME',     'example_wp' );
define( 'DB_USER',     'example_wp_user' );
define( 'DB_PASSWORD', 'use-a-long-random-value' );
define( 'DB_HOST',     'localhost' );
define( 'DB_CHARSET',  'utf8mb4' );
define( 'DB_COLLATE',  '' );

// Eight unique random keys and salts sign and protect login cookies.
// Generate at https://api.wordpress.org/secret-key/1.1/salt/
// Changing them logs every user out.
define( 'AUTH_KEY',         '...' );
// ... SECURE_AUTH_KEY, LOGGED_IN_KEY, NONCE_KEY and four *_SALT values

$table_prefix = 'wp_';

define( 'WP_ENVIRONMENT_TYPE', 'production' ); // local | development | staging | production
define( 'WP_DEBUG', false );

/* That's all, stop editing! Happy publishing. */
if ( ! defined( 'ABSPATH' ) ) {
	define( 'ABSPATH', __DIR__ . '/' );
}
require_once ABSPATH . 'wp-settings.php';
Deep dive: the order in which WordPress loads

Knowing the load order tells you which component could have produced an error, and why some fixes have to go in wp-config.php instead of a plugin.

  1. index.php → wp-blog-header.php → wp-load.php, which locates wp-config.php (in the root, or one directory above it).
  2. wp-config.php defines constants and requires wp-settings.php.
  3. wp-settings.php loads core libraries, the fatal error handler, advanced-cache.php (if WP_CACHE), and connects to the database (db.php drop-in if present). It then loads the object cache (object-cache.php if present).
  4. If .maintenance exists in the root and is recent, the maintenance message is shown and loading stops.
  5. Must-use plugins load, then network-activated plugins (Multisite), then active plugins, in the order stored in the active_plugins option. The plugins_loaded action fires.
  6. The theme's functions.php loads (child first, then parent). after_setup_theme fires.
  7. init fires: post types, taxonomies, shortcodes and blocks are registered here. Then wp_loaded.
  8. The request is parsed against the rewrite rules (parse_request), the main query runs (wp), template_redirect fires (where many redirects and access checks happen), and the template loader picks a template from the theme hierarchy.
  9. The template renders the HTML. shutdown fires at the end. Some plugins send late output or run tasks here.

A fatal error in step 5 is a plugin. In step 6 it is the theme. An error in step 3 points to the drop-ins, configuration or database. PHP error messages include the file path, which tells you directly which of these it is. See Chapter 10.

The WordPress database structure

A single-site installation creates twelve core tables. Plugins add their own: WooCommerce alone adds dozens.

TableStoresOperational notes
wp_optionsSite settings, plugin settings, transients, the cron schedule, active plugins, the active themeOptions marked for autoload are read on every request. Bloated autoloaded data is a common hidden cause of slowness. The siteurl and home rows define the site's URLs.
wp_postsPosts, pages, revisions, attachments, menu items, reusable blocks, templates, custom post types, and (on non-HPOS stores) WooCommerce ordersUsually the largest content table. Revisions and auto-drafts accumulate here.
wp_postmetaKey/value metadata for postsOften the biggest table by row count. Meta-heavy queries are a frequent source of slow pages.
wp_users, wp_usermetaAccounts, password hashes, roles and capabilities (wp_capabilities meta key), session tokensA user's role lives in usermeta, not in the users table.
wp_comments, wp_commentmetaComments, pingbacks, WooCommerce product reviews and order notesSpam can grow these to millions of rows.
wp_terms, wp_term_taxonomy, wp_term_relationships, wp_termmetaCategories, tags, custom taxonomies, product attributesCounts in term_taxonomy can drift out of sync after bulk imports.
wp_linksLegacy blogroll linksUnused on most sites, but still created.

Multisite adds network tables (wp_blogs, wp_site, wp_sitemeta, wp_signups, wp_registration_log, wp_blogmeta) and a separate set of content tables per site (wp_2_posts, wp_2_options and so on).

Serialized data

Many options and meta values are stored as PHP serialized strings, which record the length of each string inside them. For example: s:19:"https://example.com";. A plain SQL REPLACE() that changes a URL's length corrupts that structure, and the setting silently resets or breaks. Use serialization-aware tools such as wp search-replace for URL changes. See Chapter 08.

DNS, domains, SSL and HTTPS

Domains and DNS

Three separate roles are often confused, and they may belong to three different companies:

  • The registrar leases you the domain name and records which nameservers are authoritative for it.
  • The DNS host runs those nameservers and holds the records: A (IPv4 address), AAAA (IPv6), CNAME (alias to another name), MX (mail servers), TXT (SPF, DKIM, DMARC, verification tokens), CAA (which certificate authorities may issue certificates).
  • The web host runs the server the A/AAAA records point at.

When a browser needs example.com, it asks a recursive resolver (from the ISP or a public service). The resolver asks the authoritative nameservers and caches the answer for the record's TTL (time to live). "DNS propagation" is mostly caches expiring. Lowering the TTL a day before a planned migration lets the change take effect quickly; lowering it at the moment of migration does not help, because resolvers keep the old TTL they already cached.

Moving the nameservers (for example to a CDN such as Cloudflare) moves all DNS records. If MX and TXT records are not recreated first, email stops. This is one of the most common migration mistakes.

HTTP, HTTPS and TLS certificates

HTTPS is HTTP inside a TLS-encrypted connection. During the TLS handshake the server presents a certificate proving it is entitled to the domain. The browser checks that the certificate is valid for the hostname (using SNI, the server name the browser sends), that it is unexpired, and that it chains to a trusted certificate authority through the intermediate certificates the server provides. Failures show up as browser security warnings, not WordPress errors:

  • Expired certificate: renewal failed. Usually automated renewal could not complete domain validation because DNS changed, a CDN or a redirect blocked the /.well-known/acme-challenge/ path, or a CAA record forbids the authority.
  • Name mismatch: the certificate covers example.com but not www.example.com, or the reverse.
  • Incomplete chain: works in some browsers but fails in others and in server-to-server calls (payment webhooks, for example).

Maximum public certificate lifetimes are being reduced in stages from 2026 onwards, so manual renewal is no longer realistic. Automated renewal through the host, the CDN, or an ACME client such as Certbot is essential. Monitor expiry dates independently of the renewal mechanism.

WordPress itself knows nothing about certificates. It only knows the URLs in siteurl and home, and whether PHP reports the current request as HTTPS. That second point is why proxies cause redirect loops; see the next section and the Error Encyclopedia entry for Too many redirects.

CDNs, reverse proxies and the real visitor IP

A reverse proxy sits in front of the origin server and forwards requests to it. A CDN is a globally distributed reverse proxy with caching. Both also act as security layers: a WAF (web application firewall) inspects requests and blocks known attack patterns before they reach WordPress, and bot management challenges suspicious clients.

A proxy brings three side effects that cause real-world problems:

  1. The origin sees the proxy's IP address, not the visitor's. The proxy passes the real address in a header such as X-Forwarded-For or CF-Connecting-IP. If WordPress, a security plugin or the web server is not configured to trust that header only from the proxy's IP ranges, two things go wrong. Either every visitor appears to share a handful of IPs (so one bad actor gets the whole CDN blocked, or rate limits hit everyone), or an attacker can spoof the header to fake their address.
  2. TLS may end at the proxy. If the proxy talks to the origin over plain HTTP, PHP believes the request is not HTTPS. WordPress then redirects to HTTPS, the proxy sends that request back over HTTP, and you get an infinite redirect loop. The proxy signals the original scheme in X-Forwarded-Proto.
  3. The proxy can cache things it should not, such as pages with a logged-in user's name, cart contents or a checkout nonce, if cache rules ignore cookies.
Exposed origin IP

A CDN or WAF only protects traffic that goes through it. If the origin server's real IP is known (from old DNS records, a mail server on the same IP, or a subdomain that bypasses the CDN), attackers can send requests straight to the origin. Where the platform supports it, restrict the origin firewall to accept web traffic only from the CDN's published IP ranges, or use an authenticated tunnel. This needs host or server-administrator involvement.

Caching layers: page, object, browser and opcode

Caching means keeping the result of expensive work so it can be reused. A WordPress site can have five or more independent caches. Most "my change isn't showing" problems are a cache you forgot existed, and most "the wrong user's data is showing" problems are a cache storing something personal.

LayerWhat it storesWhereHow it is clearedTypical failure
Browser cacheStatic assets, sometimes whole pagesVisitor's deviceExpiry headers; a hard refresh; changing the file URL (version query string)Visitors see old CSS/JS after a deploy; only fixed by cache-busting file names
CDN / edge cacheStatic assets; full HTML if "cache everything" is enabledCDN points of presenceCDN purge (API, dashboard or plugin integration)Logged-in or cart content served to strangers; purges not reaching all edges
Server page cacheFull HTML responsesNginx FastCGI cache, Varnish, LiteSpeed LSCache, host platform cacheHost dashboard, host plugin, or a plugin that talks to the server cachePurges from a WordPress plugin never reach a host-level cache it doesn't know about
Plugin page cacheStatic HTML fileswp-content/cache/ via advanced-cache.phpThe plugin's purge button or automatic purge on editsTwo plugins fighting over advanced-cache.php; stale pages after edits
Object cacheResults of database queries and computations (options, posts, transients)Per-request memory by default; Redis/Memcached if persistentwp cache flush or the plugin's flush buttonStale settings after direct DB edits; one site's keys colliding with another's on a shared Redis without a unique key prefix
OPcacheCompiled PHP codePHP shared memoryPHP-FPM reload; automatically when validate_timestamps is onOld code keeps running after a file change when timestamps are not validated
Database buffer poolTable and index pagesMySQL/MariaDB memoryManaged by the database serverToo small for the data set, so queries hit disk

WordPress's object cache deserves a note. Without a persistent backend, WP_Object_Cache lives only for the current request and is thrown away afterwards. Installing a Redis- or Memcached-backed object-cache.php keeps those values between requests, which helps a lot on dynamic sites (WooCommerce, membership, logged-in traffic) that page caching cannot help. It also changes behaviour: transients stop being stored in wp_options and live in Redis instead, and data changed directly in the database is not seen until the cache is flushed.

The complete request lifecycle and where it fails

Here is one uncached page view, step by step, with the main ways each step fails. When troubleshooting, find the first step that is not completing. Everything after it is a consequence.

  1. A visitor enters a website address. The browser parses the URL into scheme (https), host (www.example.com) and path. It may already have an HSTS rule that forces HTTPS, or a cached redirect. Fails when: a cached 301 redirect keeps sending the browser to an old URL. Test in a private window or another browser.
  2. DNS resolves the domain. The resolver returns the IP of the CDN or origin. Fails when: the domain has expired, nameservers are wrong, a record was deleted, or an old IP is still cached. Browsers show "DNS_PROBE_FINISHED_NXDOMAIN" or "server IP address could not be found". Check with dig; see Chapter 12.
  3. The browser establishes a connection. A TCP connection (or QUIC for HTTP/3) to port 443. Fails when: the server is down, a firewall blocks the visitor's IP, or the host is under a DDoS attack. You see "connection refused" or "timed out".
  4. HTTPS is negotiated. TLS handshake: protocol version, cipher, certificate validation. Fails when: the certificate is expired, mismatched or missing its chain, or the protocol versions are incompatible. The browser shows a security interstitial before any HTTP happens, so WordPress is not involved.
  5. The request reaches the hosting infrastructure. CDN/WAF rules apply, the edge cache may answer, and the request is forwarded to the origin's load balancer or proxy. Fails when: a WAF rule blocks it (403 or a challenge page), the edge cannot reach the origin (502, 504, or CDN-specific 52x codes), or rate limiting triggers (429).
  6. The web server processes the request. It applies virtual-host routing, access rules, rewrite rules and limits (body size, timeouts), serves static files directly, or passes PHP requests on. Fails when: .htaccess syntax is broken (500), access is denied by permissions or rules (403), the file is missing (404), the request body is too large (413), or no PHP worker is free (502/503/504).
  7. PHP executes WordPress. A PHP-FPM or LSAPI worker picks up the request and runs index.php. Fails when: PHP-FPM is stopped or its socket path is wrong (502), workers are saturated (requests queue, then 502/504), or the PHP version is incompatible with the code (fatal error).
  8. WordPress loads its configuration. wp-config.php runs and constants are defined. Fails when: there is a syntax error in wp-config.php (500/blank page), file permissions prevent reading it, or constants conflict.
  9. Plugins and themes execute. mu-plugins, plugins and theme functions.php load and register hooks. Fails when: a PHP fatal error occurs ("There has been a critical error"), memory runs out ("Allowed memory size exhausted"), a plugin makes a slow remote call during load, or two plugins declare the same function or class.
  10. WordPress interacts with the database. Options autoload, the main query runs, and plugins run their own queries. Fails when: the credentials are wrong or the database server is down ("Error establishing a database connection"), tables are corrupt, max connections are reached, or slow queries cause timeouts.
  11. The response is generated. The template renders HTML, and headers (cookies, cache-control, security headers) are set. Fails when: output is sent before headers ("Cannot modify header information - headers already sent"), template files are missing, or the execution time limit is exceeded mid-render.
  12. Caching layers may store or serve the response. Page caches, proxies and the CDN decide whether to keep a copy according to headers, cookies and rules. Fails when: an error page is cached and served to everyone, personalised content is cached, or a purge does not reach every layer.
  13. The browser displays the page. It parses the HTML, requests CSS, JavaScript, images and fonts (repeating steps 2–12 for each, often from the CDN), and runs scripts. Fails when: mixed content is blocked, JavaScript errors stop interactive features, CSP blocks resources, or assets 404 after minification. The developer tools Console and Network tabs show these; the server never sees an error.
The single most useful diagnostic question

"Does the request reach PHP?" If the PHP error log or WordPress debug log records anything for the failing request, the problem is in steps 7–11. If the web server access log shows the request but PHP does not, look at steps 5–6. If the origin access log never sees the request, look at DNS, TLS, the CDN or a firewall: steps 2–5.

Rather have someone else keep WordPress healthy?

Our managed hosting and care plans cover updates, backups, security monitoring and fixes like the ones in this handbook, so you can get on with running the business.

See Hosting & Care