Kokil Thapa - Professional Web Developer in Nepal
Freelancer Web Developer in Nepal with 15+ Years of Experience

Kokil Thapa is an experienced full-stack web developer focused on building fast, secure, and scalable web applications. He helps businesses and individuals create SEO-friendly, user-focused digital platforms designed for long-term growth.

PKI and Certificate Management Basics

By Kokil Thapa | Last reviewed: September 2026

PKI and certificate management basics decide whether browsers trust your site or show a scary warning. Public Key Infrastructure is the system of certificate authorities, keys, and policies that bind identities to cryptographic keys. On production Linux servers running Laravel, WordPress, or API gateways, a missed renewal or broken chain breaks checkout flows and client portals overnight. This guide walks through how PKI works in practice and how to manage certificates so they do not become a Friday-night emergency. If you deploy sites regularly, pair this with our SSL/TLS certificates explained article for the transport-layer side.

What is PKI and how does public key infrastructure work?

PKI is a framework for creating, distributing, and validating digital certificates. Each certificate binds a public key to an identity such as a hostname, organisation, or service account. Browsers and API clients trust that binding only when the certificate chains to a root CA they already trust.

The core actors are straightforward. A Certificate Authority signs certificates. A Registration Authority validates identity before issuance. You hold the private key on the server or in a secrets store. Relying parties—browsers, mobile apps, webhooks—verify the chain during the TLS handshake.

Public Key Infrastructure Trust ChainRoot CAOffline, long-livedIntermediate CAIssues end-entity certsLeaf Certificateexample.com + public keyRelying PartyBrowser or API client verifies chain
PKI and certificate management basics start with the trust chain from root CA through intermediate to your leaf certificate.

Key pairs and X.509 fields that matter

Every TLS certificate is an X.509 document. You care about these fields during audits and renewals:

  • Subject Common Name (CN) or SAN — hostnames the cert covers; modern browsers require Subject Alternative Names.
  • Issuer — which CA signed the cert; mismatches here cause chain errors.
  • Validity windownotBefore and notAfter dates; Let's Encrypt certs are typically 90 days.
  • Key usage extensions — digitalSignature, keyEncipherment, or extended key usage for serverAuth.
  • Serial number — needed for OCSP revocation lookups.

Inspect any cert on a live server with OpenSSL:

openssl x509 -in /etc/ssl/certs/example.com.crt -noout -text | grep -E "Subject:|Issuer:|DNS:|Not "
openssl s_client -connect example.com:443 -servername example.com < /dev/null 2>/dev/null | openssl x509 -noout -dates -issuer -subject

The private key never leaves secure storage unless you are migrating. On Ubuntu servers I maintain, keys live under /etc/ssl/private/ with mode 600 and root ownership. Application containers should mount them read-only. For deeper server hardening, see our install SSL certificates on Ubuntu walkthrough.

How do you manage SSL/TLS certificates in production?

Certificate management is operational work, not a one-time setup task. You need an inventory, renewal automation, monitoring, and a documented rotation procedure. Small teams in Nepal often run five to twenty domains on one EC2 box; one expired cert on a sister site can take down lead forms for a law portal.

I treat certificate management like database backups. If it is not scheduled and monitored, it will fail silently until a user complains.

Build a certificate inventory first

Before automating anything, list every certificate in your environment. Spreadsheet columns I use:

  1. Hostname or service name
  2. Environment (production, staging, internal)
  3. Issuer (Let's Encrypt, DigiCert, internal CA)
  4. Expiry date and auto-renew flag
  5. Where the cert is installed (Apache vhost, Nginx, load balancer, CDN)
  6. Contact owner and runbook link

Query expiry from the command line across a fleet:

echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null \
  | openssl x509 -noout -enddate -issuer -subject

For internal APIs, add the same check to your CI pipeline or cron. Our Linux system administration service includes expiry monitoring on shared hosting stacks because manual tracking does not scale past a dozen certs.

Certificate Lifecycle Management1. GenerateCSR + key pair2. IssueCA signs cert3. DeployWeb server reload4. MonitorExpiry alerts5. Renew before notAfterCertbot cron or ACME client6. Revoke on compromiseOCSP / CRL publish new cert
Production certificate management follows a repeatable lifecycle from CSR generation through monitoring, renewal, and revocation.

Automate renewal with ACME

Let's Encrypt uses the ACME protocol defined in RFC 8555. Certbot on Ubuntu remains the default for Apache and Nginx vhosts I deploy. A typical renewal hook reloads the web server after a successful issue:

sudo certbot renew --dry-run
sudo certbot renew --deploy-hook "systemctl reload apache2"

Certbot installs a systemd timer or cron job. Verify it exists:

systemctl list-timers | grep certbot
sudo certbot certificates

Cloudflare or AWS Certificate Manager can terminate TLS at the edge. You still own expiry tracking. A cert on the origin can expire even when the CDN cert looks fine. Document both layers in your inventory.

What is the difference between public and private certificate authorities?

Public CAs like Let's Encrypt, DigiCert, and Sectigo issue certs that browsers trust globally. Private CAs—often Microsoft AD CS, HashiCorp Vault PKI, or OpenSSL-based internal roots—sign certs for internal services only. You install the private root on employee laptops or cluster trust stores.

CriteriaPublic CA (Let's Encrypt, commercial)Private CA (internal PKI)
Browser trustBuilt into OS and browser trust storesRequires distributing your root or intermediate
ValidationDomain control (HTTP-01, DNS-01, TLS-ALPN-01)Your own identity policy
Typical usePublic websites, customer APIs, eCommerce checkoutMicroservices mTLS, VPN, internal admin panels
CostFree (Let's Encrypt) or Rs 8,000–40,000/year (~USD 60–300) for OV/EVStaff time plus HSM or Vault infrastructure
Certificate lifetimeOften 90 days (Let's Encrypt); industry moving shorterYou set policy; many teams use 1-year internal certs
Revocation visibilityPublic OCSP/CRL infrastructureYou operate OCSP responder or CRL distribution

For a public Laravel storefront like Quick And Easy Nepalese Grocery, public CA certs are mandatory. For service-to-service calls inside a VPC, private PKI with mutual TLS reduces exposure. Compare approaches in our multi-cloud secrets management and HashiCorp Vault secrets articles when certs live beside API keys.

The CA/Browser Forum Baseline Requirements govern public issuers. Shorter maximum lifetimes push teams toward automation. Manual annual renewals are a liability in 2026.

How do you renew and rotate certificates without downtime?

Renewal replaces a cert before expiry with the same key or a new key. Rotation implies replacing the key pair, which is stronger after staff changes or suspected compromise. Both require reloading the TLS terminator without dropping active connections.

Zero-downtime reload patterns

Apache and Nginx support graceful reload. PHP-FPM does not need a restart for cert changes unless you terminate TLS inside PHP, which you should not.

sudo nginx -t && sudo systemctl reload nginx
sudo apachectl configtest && sudo systemctl reload apache2

On Deployer 7 releases I use for sister legal-tech sites, cert paths stay in shared directories outside the release symlink. The web server points to /etc/letsencrypt/live/domain/, not current/public. Renewals never touch application code.

Load balancers need the full chain uploaded. A common mistake is sending only the leaf cert. Clients fail chain validation when intermediates are missing. Always bundle:

cat fullchain.pem  # leaf + intermediate(s)
# privkey.pem stays on server only

Rotation checklist for production

  1. Generate new key and CSR, or let ACME client handle both.
  2. Issue new cert and validate chain with openssl verify.
  3. Deploy to staging; run SSL Labs or curl -vI https://staging.example.com.
  4. Deploy to production during low traffic; reload, do not restart.
  5. Confirm monitoring green for 24 hours.
  6. Revoke old cert if key material may have leaked.

Client-facing portals such as Mijar Law Associates cannot afford document-upload downtime. Schedule rotation in off-peak windows and keep the previous cert until the new one proves stable.

Certificate Management GotchasDo: Central inventoryTrack hostname, issuer, expiryAlert 30 days before notAfterAvoid: Siloed certsForgotten staging subdomainCDN ok but origin expiredAvoid: Incomplete chainLeaf only on load balancerAndroid clients fail TLSDo: Test after deployopenssl s_client + curl -vIVerify SAN covers all hostsOne missed LB cert breaks all routesMap every TLS termination point firstInclude mail, API, and admin subdomains
PKI and certificate management basics fail in production when inventory is incomplete or chains are uploaded without intermediates.

How do you troubleshoot common PKI and certificate management problems?

Most incidents fall into four buckets: expiry, name mismatch, broken chain, and clock skew. Start with observable symptoms, then validate the cert programmatically.

Diagnose handshake and chain errors

curl -vI https://example.com 2>&1 | grep -E "subject:|issuer:|expire|SSL certificate"
openssl s_client -connect example.com:443 -showcerts < /dev/null
openssl verify -CAfile chain.pem cert.pem

ERR_CERT_DATE_INVALID means expired or not yet valid. Renew immediately. ERR_CERT_COMMON_NAME_INVALID usually means SAN does not list the hostname you typed. Wildcard certs cover one level only; *.example.com does not cover api.staging.example.com.

unable to get local issuer certificate signals a missing intermediate. Download the issuer bundle from your CA and concatenate it. The OpenSSL project documents chain building in their verification options manual.

Integrate PKI with application and API layers

Laravel apps behind TLS still need correct APP_URL=https:// and trusted proxy configuration. Payment gateway callbacks—eSewa, Khalti, Stripe—reject mismatched callback URLs when certs fail mid-flow. For API projects, document mTLS requirements in OpenAPI specs. Our API development practice treats cert pinning and webhook TLS as part of the contract, not ops afterthoughts.

Kubernetes ingress controllers store certs as Secrets. Rotation means updating the Secret and letting the controller reload. See Kubernetes secrets management done right for naming and access patterns. Azure Key Vault can issue and store certs for App Service; the Azure Key Vault guide covers import versus managed issuance.

Generate strong keys for CSRs with our password generator mindset applied to entropy—use 2048-bit RSA minimum or prefer ECDSA P-256 where clients support it.

Multi-Layer Certificate DeploymentUser BrowserTrusts public CACDN / WAF EdgeEdge cert (public CA)Origin ServerOrigin cert (often missed)Laravel AppAPP_URL HTTPSInternal microservices (optional mTLS)Private CA issues service-to-service certsMonitor all three layersEdge + origin + internalAudit quarterlyAlign with ISO 27001 controls
Real deployments terminate TLS at multiple layers; PKI management must track every certificate, not only the public-facing edge.

Compliance and audit hooks

ISO 27001 and client security questionnaires ask for key length, CA source, renewal process, and revocation steps. Map your runbooks to control language early. Our ISO 27001 basics for engineers article aligns well with PKI documentation requirements.

Legal-tech portals handling client documents benefit from strict TLS configs plus HSTS headers. Combine cert management with testing and optimization passes that include SSL Labs scans. Vulnerability scanners flag weak ciphers separately from expiry; treat both streams in vulnerability management automation.

Domain and DNS ownership underpins domain-validated certs. If DNS lapses, an attacker can obtain a valid cert for your hostname. Keep registrar locks and auto-renew enabled through your registrar workflow described in domain registration and hosting.

Key Takeaways

  • PKI trust chains run root CA → intermediate → leaf; browsers fail closed when any link is missing or expired.
  • Maintain a central inventory with hostname, issuer, expiry, install location, and owner for every cert in production and staging.
  • Automate renewal with ACME (Certbot) and verify timers with certbot renew --dry-run at least quarterly.
  • Upload full certificate chains to load balancers and CDNs; leaf-only uploads cause subtle mobile client failures.
  • Rotate keys after personnel changes or suspected compromise, and revoke old certificates through the CA portal.
  • Map every TLS termination layer—edge, origin, internal mTLS—because one expired cert anywhere breaks the user journey.

People Also Ask

What is the difference between a certificate and a key?

A certificate is a signed public document containing your public key plus identity metadata. The private key stays secret on the server and proves you own the cert during TLS handshakes. You can reissue a certificate with the same key, but best practice rotates both after security events.

How long do SSL certificates last in 2026?

Let's Encrypt issues 90-day certificates by default, encouraging automation. Public CAs under CA/Browser Forum rules continue shortening maximum lifetimes. Plan for quarterly renewals rather than annual calendar reminders.

Do I need a wildcard certificate?

Wildcard certs cover unlimited subdomains at one DNS level (*.example.com). SAN certificates listing explicit hostnames are often safer and cheaper for small sites. Use wildcards only when you frequently spin up unpredictable subdomains.

What happens if my SSL certificate expires?

Browsers display interstitial warnings and block form submission on many devices. API clients may throw TLS errors silently, breaking payment webhooks and mobile apps. Monitoring with 30-day alerts prevents most outages; keep a manual issuance runbook for CA outages.

Ship trustworthy HTTPS without certificate surprises

PKI and certificate management basics are infrastructure hygiene, not optional security theatre. Inventory your certs, automate ACME renewal, validate chains after every deploy, and document rotation for your team. Whether you run a law portal, eCommerce store, or internal API mesh, the pattern is identical: know what you have, renew before expiry, and test from the client's perspective.

Need help auditing TLS across a multi-site Deployer fleet or setting up monitored Certbot on Ubuntu? Review our Notary Nepal and sister-site work in the portfolio, then reach out through contact us or explore support and maintenance for ongoing certificate monitoring. For mobile clients calling your APIs, also read mobile app security basics and keep web development and hosting under one accountable workflow.

Frequently Asked Questions

PKI is the framework for creating, distributing, and validating digital certificates that bind public keys to identities such as hostnames or organisations. Browsers and API clients trust that binding only when the certificate chains to a root CA they already trust.

A certificate is a signed public document containing your public key plus identity metadata. The private key stays secret on the server and proves you own the cert during TLS handshakes.

Let's Encrypt issues 90-day certificates by default, encouraging automation. Public CAs under CA/Browser Forum rules continue shortening maximum lifetimes, so plan for quarterly renewals rather than annual calendar reminders.

PKI trust runs root CA through intermediate to your leaf certificate. Browsers and API clients fail closed when any link is missing, expired, or signed by an untrusted issuer. A common production mistake is uploading only the leaf cert to a load balancer or CDN; clients then report unable to get local issuer certificate because intermediates are absent. Always bundle the full chain when deploying. On Ubuntu servers I maintain, I verify chains with openssl verify and openssl s_client before and after every deploy, because chain errors often pass desktop checks but break mobile clients or webhooks.

Public CAs such as Let's Encrypt, DigiCert, and Sectigo issue certificates that browsers trust globally after domain validation via HTTP-01, DNS-01, or TLS-ALPN-01. Private CAs—Microsoft AD CS, HashiCorp Vault PKI, or OpenSSL-based internal roots—sign certs for internal services only; you must distribute the private root to employee laptops or cluster trust stores. Public CAs suit customer-facing Laravel storefronts and eCommerce checkout. Private PKI fits microservices mTLS and internal admin panels inside a VPC. Public issuers expose OCSP and CRL revocation; with private PKI you operate that infrastructure yourself or accept limited revocation visibility.

Certificate management is operational work, not a one-time setup. You need an inventory, renewal automation, monitoring, and a documented rotation procedure. I treat it like database backups: if it is not scheduled and monitored, it fails silently until a user complains. Start by listing every cert with hostname, environment, issuer, expiry date, auto-renew flag, install location such as Apache vhost, Nginx, load balancer, or CDN, plus an owner and runbook link. Automate renewal with ACME via Certbot, verify systemd timers or cron jobs exist, and run certbot renew --dry-run at least quarterly. Track every TLS termination layer—edge CDN, origin server, internal mTLS—because one expired cert anywhere breaks checkout or client portals.

Before automating renewals, list every certificate in your environment in a central spreadsheet or asset register. Columns I use: hostname or service name, environment such as production or staging, issuer including Let's Encrypt, DigiCert, or an internal CA, expiry date and whether auto-renew is enabled, where the cert is installed such as Apache vhost, Nginx, load balancer, or CDN, and a contact owner with a runbook link. Query live expiry from the command line with openssl s_client piped to openssl x509 for enddate, issuer, and subject. For internal APIs, add the same check to CI pipelines or cron. Manual tracking does not scale past a dozen certs; on shared hosting stacks I have seen one expired sister-site cert take down lead forms for an entire law portal.

Let's Encrypt uses the ACME protocol defined in RFC 8555. Certbot on Ubuntu remains the default for Apache and Nginx vhosts I deploy. After a successful issue, a deploy hook reloads the web server without dropping connections, for example systemctl reload apache2. Certbot installs a systemd timer or cron job; verify it with systemctl list-timers and sudo certbot certificates. Run sudo certbot renew --dry-run at least quarterly to catch DNS or firewall regressions before a real renewal fails. If TLS terminates at Cloudflare or AWS Certificate Manager, you still own expiry tracking on the origin—a CDN cert can look fine while the backend cert expires. Document both layers in your inventory.

Renewal replaces a cert before expiry, optionally keeping the same key. Rotation replaces the key pair, which is stronger after staff changes or suspected compromise. Both require reloading the TLS terminator, not restarting it. Apache and Nginx support graceful reload after configtest passes; PHP-FPM does not need a restart unless you terminate TLS inside PHP, which you should not. On Deployer 7 releases I use, cert paths stay in shared directories outside the release symlink, pointing to paths like /etc/letsencrypt/live/domain/ rather than application code. Load balancers need the full chain uploaded. Rotation checklist: generate new key and CSR, validate chain with openssl verify, test staging with curl or SSL Labs, deploy during low traffic, confirm monitoring for 24 hours, and revoke the old cert if key material may have leaked.

Browsers display interstitial warnings and block form submission on many devices, which kills trust for law portals and eCommerce checkout flows overnight. API clients may throw TLS errors silently, breaking payment webhooks for eSewa, Khalti, or Stripe and breaking mobile apps that call your APIs. ERR_CERT_DATE_INVALID is the typical symptom. Monitoring with 30-day expiry alerts prevents most outages. Keep a manual issuance runbook for CA outages or ACME failures so you are not dependent on a single automation path when Let's Encrypt or your DNS provider has problems during renewal.

Most incidents fall into four buckets: expiry, name mismatch, broken chain, and clock skew. Start with observable symptoms, then validate programmatically using curl -vI, openssl s_client -showcerts, and openssl verify. ERR_CERT_DATE_INVALID means expired or not yet valid—renew immediately. ERR_CERT_COMMON_NAME_INVALID usually means the SAN does not list the hostname you typed; modern browsers require Subject Alternative Names, not CN alone. Wildcard certs cover one DNS level only; api.staging.example.com is not covered by star.example.com. unable to get local issuer certificate signals a missing intermediate—download the issuer bundle from your CA and concatenate it with the leaf. Integrate expiry checks into cron or CI for internal APIs so problems surface before users do.

Wildcard certificates cover unlimited subdomains at one DNS level, such as star.example.com covering www and api but not api.staging.example.com. SAN certificates listing explicit hostnames are often safer and cheaper for small sites with a fixed set of hosts. Use wildcards only when you frequently spin up unpredictable subdomains and operational overhead of updating SAN lists becomes painful. For most Laravel and WordPress deployments I maintain with five to twenty domains on one server, explicit SAN or individual certs plus ACME automation is easier to audit and inventory. Wildcards also complicate security reviews because one compromised key affects every subdomain at that level.

Let's Encrypt domain-validated certificates are free, which covers most public websites when you automate ACME renewal with Certbot. Commercial organisation-validated or extended-validation certs from public CAs typically run Rs 8,000 to 40,000 per year, roughly USD 60 to 300, depending on issuer and validation level. Private PKI costs are mostly staff time plus infrastructure such as HashiCorp Vault or an HSM rather than per-cert fees. For a public storefront, free DV certs are sufficient. Pay for OV or EV only when contracts, payment processors, or client security questionnaires explicitly require them. Either way, budget for monitoring and renewal automation labour, not just the CA invoice.

Every TLS certificate is an X.509 document. Fields that matter during audits: Subject Common Name or, more importantly, Subject Alternative Names listing every hostname the cert covers; Issuer, because mismatches cause chain errors; Validity window with notBefore and notAfter dates; Key usage extensions such as digitalSignature, keyEncipherment, and extended key usage for serverAuth; and Serial number for OCSP revocation lookups. Inspect live certs with openssl x509 -noout -text or openssl s_client against port 443. ISO 27001 questionnaires and client security reviews routinely ask for key length, CA source, renewal process, and revocation steps, so map these fields to your runbook language early rather than scrambling during an audit.

Renewal replaces the certificate before expiry, often reusing the existing private key for simplicity. Rotation replaces the key pair entirely, which is the stronger response after personnel changes, server compromise, or suspected key leakage. Both require deploying the new material and reloading Apache or Nginx without dropping active connections. After rotation, revoke the old certificate through the CA portal if key material may have leaked, so OCSP and CRL infrastructure reflects the change. Best practice treats scheduled renewal as routine hygiene and rotation as a security event with a longer checklist including staging validation, 24-hour monitoring, and documented rollback. Reissuing a cert with the same key is possible but does not address a compromised private key.

Share this article

0 Comments

Leave a comment

Your email is not published. Comments appear once they have been read. Sign in to have your details filled in.

Quick Contact Options
Choose how you want to connect me: