Fix Apache AH02565: Certificate and private key do not match
AH02565 means the first certificate and the key are not a pair. httpd -t still passes and graceful took Apache down, so compare public key hashes first.
[ssl:emerg] [pid …] AH02565: Certificate and private key example.com:443:0 from /usr/local/apache2/conf/ssl/fullchain.pem and /usr/local/apache2/conf/ssl/old.key do not matchThe first certificate in SSLCertificateFile and the private key in SSLCertificateKeyFile do not belong together. Either the key is from a different issuance, or an intermediate certificate sits at the top of the certificate file. Comparing the public key hashes of the two files tells you which.
[1] Read the two paths from the error line, in the order from <certificate> and <key>. example.com:443:0 identifies the virtual host and which certificate slot it is.
[2] Compare the public key hashes of the two files.
# openssl x509 -in /usr/local/apache2/conf/ssl/fullchain.pem -noout -pubkey | openssl sha256# openssl pkey -in /usr/local/apache2/conf/ssl/old.key -pubout | openssl sha256SHA2-256(stdin)= b57f38f07b48c9bd229efe26020cdc59751ff570edd54cad35ad5cd766f9fd42SHA2-256(stdin)= ddc2971339a6e3db04d664c47140411b3e3e1c11ade420565c87c55d1ef7bbd3Different hashes mean they are not a pair. openssl x509 reads only the first certificate in the file, which is the one Apache compares. This works the same for RSA and EC keys.
[3] If the hashes differ, check whose certificate comes first.
# openssl x509 -in /usr/local/apache2/conf/ssl/reversed.pem -noout -subjectsubject=CN=Test-CA| Subject of the first certificate | Cause | What to do |
|---|---|---|
Your domain (CN=example.com) | The key is from another issuance or another server | Find the key used for that certificate: hash each candidate key with the second command in [2] and pick the match. If none matches, reissue with a new key |
| A CA or intermediate name | The order inside the file is reversed | Rebuild it as server certificate, then intermediates |
The mod_ssl docs also say intermediate certificates in SSLCertificateFile must be sorted from leaf to root. In the reproduction, a file with the CA first (reversed.pem) produced the same AH02565.
[4] Fix the file. Keep the original.
# cp -a fullchain.pem fullchain.pem.bak# cat example.com.crt ca.crt > fullchain.pemWith Let's Encrypt, set SSLCertificateFile to /etc/letsencrypt/live/<domain>/fullchain.pem and SSLCertificateKeyFile to privkey.pem in the same folder. Copying only one of them elsewhere leaves the two from different issuances after a renewal, which produces this error.
[5] Before sending a graceful restart, repeat the hash comparison from [2] on the rebuilt file and the key file in the configuration. These commands only read files, so the running Apache is not affected.
# openssl x509 -in /usr/local/apache2/conf/ssl/fullchain.pem -noout -pubkey | openssl sha256# openssl pkey -in /usr/local/apache2/conf/ssl/<key from SSLCertificateKeyFile> -pubout | openssl sha256Only when the two lines match, continue with apachectl -t and then apachectl -k graceful. If they differ, do not send a graceful restart; go back to [3]. If you changed paths in the configuration, compare the new SSLCertificateFile and SSLCertificateKeyFile paths. With several virtual hosts using certificates, compare each one.
# httpd -f /tmp/t.conf -t# httpd -f /tmp/t.conf -k gracefulSyntax OK# grep -E "emerg|notice" /tmp/error.log[Tue Oct 27 03:59:43.048651 2026] [mpm_event:notice] [pid …] AH00493: SIGUSR1 received. Doing graceful restart[Tue Oct 27 03:59:43.053069 2026] [ssl:emerg] [pid …] AH02565: Certificate and private key example.com:443:0 from /usr/local/apache2/conf/ssl/fullchain.pem and /usr/local/apache2/conf/ssl/old.key do not match[Tue Oct 27 03:59:43.053095 2026] [:emerg] [pid …] AH00020: Configuration Failed, exitingNo Apache process was left after AH00020 … exiting. On a live server that means the whole site goes down. If it is already down, restore the .bak from [4] (or fix the pair until the hashes match) and start Apache again.
[6] If the messages are AH02579: Init: Private key not found and AH02564: Failed to configure encrypted (?) private key instead of AH02565, the cause is different. In the reproduction this happened when the SSLCertificateKeyFile line was missing: without it, mod_ssl looks for the key inside the certificate file (httpd source). Add the key file line.
The nginx version of this problem is nginx key values mismatch.
Analyze your Apache log in the browser ↗ — nothing is uploaded.
Check it with the Certificate (PEM · X.509) decoder tool ↗ — calculated in your browser.