PHP LDAP in Laravel fails with Can't contact LDAP server over TLS
Can't contact LDAP serverShort answer
PHP's LDAP client uses OpenLDAP's settings. If it does not trust the CA that signed your directory server's certificate, a TLS connection fails with Can't contact LDAP server. Point TLS_CACERT in ldap.conf at your CA file, restart PHP, and check that SSL or TLS mode and the port match.
Fix it fast
1Find out which cause you have
Rule out the certificate first: run the same connection from the server with the OpenLDAP tool, using the same host and port as the app.
ldapsearch -x -H ldaps://ldap.example.com:636 -b "" -s base2Match what you see, then jump to its fix
- 1
The failure appears only with ldaps:// or StartTLS, and ldapsearch reports the same certificate problemThe client does not trust the CA that signed the server certificateFix - 2
You set a TLS option in PHP code and it has no effectTLS options are set after the connection already existsFix - 3
use_ssl and use_tls are both on, or use_tls is combined with port 636SSL, TLS and the port do not matchFix
- 1
What does the error look like?
Can't contact LDAP serverunable to get local issuer certificate
Cause 1 of 3
The client does not trust the CA that signed the server certificate
1Check
ldap.conf is where OpenLDAP-based clients, including PHP, read their trust settings. TLS_CACERT names the file with the Certificate Authorities the client will recognize.
cat /etc/ldap/ldap.conf
php --ri ldap2Fix
Copy your domain CA certificate to the server and reference it in ldap.conf, then restart the web server or PHP-FPM so the change is picked up.
# /etc/ldap/ldap.conf (or /etc/openldap/ldap.conf)
TLS_CACERT /etc/ssl/certs/ca.pem
TLS_REQCERT hard3Verify
Repeat the ldapsearch command; it now connects without a certificate error.
ldapsearch -x -H ldaps://ldap.example.com:636 -b "" -s baseConfirmed by ldaprecord.com
Cause 2 of 3
TLS options are set after the connection already exists
1Check
PHP requires TLS-related options to be set globally, by passing null as the link, and before ldap_connect or ldap_start_tls.
grep -rn "ldap_set_option\|LDAP_OPT_X_TLS" app config2Fix
Set the option before connecting. In LdapRecord, put it in the connection's options array, which passes ldap_set_option constants.
'options' => [
LDAP_OPT_X_TLS_REQUIRE_CERT => LDAP_OPT_X_TLS_HARD,
],3Verify
Clear the cached config, then retry the login.
php artisan config:clearConfirmed by php.net
Cause 3 of 3
SSL, TLS and the port do not match
1Check
LdapRecord allows only one of use_ssl or use_tls. With use_tls you must keep the default port 389, and use_ssl moves the default to 636.
grep -n "use_ssl\|use_tls\|port" config/ldap.php2Fix
Pick one mode and the port that matches it.
'use_tls' => true,
'use_ssl' => false,
'port' => 389,3Verify
Retry the connection from the app.
php artisan config:clearConfirmed by ldaprecord.com
How do I stop it coming back?
- Keep the directory's CA certificate in your server provisioning, next to ldap.conf.
- Do not set TLS_REQCERT never in production; it stops the client checking the server certificate at all.
- Restart PHP-FPM or the web server after every ldap.conf change.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Security
Laravel answers a form or AJAX call with 419 Page Expired
419 Page Expired (a POST, PUT, PATCH or DELETE request)
Laravel could not match the CSRF token in your request to the one stored in the visitor's session.
5 causes, each with a fixSecurity
Is my PHP application affected by PHP2Shell, and how do I mitigate it?
A scanner or advisory feed reports CVE-2026-109619 (RCE via stale global state) on your server
You are exposed when the PHP serving web requests is older than 8.2.35, 8.3.36, 8.4.27 or 8.5.12 on its branch, or when a distribution package is older than its vendor's fixed build.
6 causes, each with a fixSecurity
Your auth.log is full of Failed password and Invalid user attempts
Invalid user ubnt from 198.51.100.23 port 40122
Any public SSH port gets password guesses within hours; the log lines alone are not a breach.
4 causes, each with a fixBack end
Composer says the gd extension is missing on a Laravel project
composer install or composer update stops on a package that requires ext-gd
Composer refuses to install a package that requires ext-gd when the PHP binary running Composer has no GD extension.
4 causes, each with a fixSecurity
Inline base64 images do not show because of the Content Security Policy
Refused to load the image 'data:image/svg+xml;base64,...' because it violates the following Content Security Policy directive: "default-src 'self'".
A base64 image has a data: URL, and a policy such as default-src 'self' does not allow that scheme.
3 causes, each with a fixSecurity
Video from a MediaSource is blocked: 'Content at ... may not load data from blob:'
Content-Security-Policy: The page's settings blocked the loading of a resource (media-src) at blob:http://localhost:3000/...
A MediaSource video plays from a blob: URL.
3 causes, each with a fix