- How do I install spatie/ssl-certificate in a Laravel application?
- Run composer require spatie/ssl-certificate. There is no service provider, config file, or facade to register because the package is a single class you can use directly or bind behind your own container service. The only notable dependency is Carbon for date handling, plus ext-openssl and outbound network access for hostname lookups. Most teams wrap it in a small inspector or monitor service of their own.
- Which PHP and Laravel versions does spatie/ssl-certificate support?
- The package targets PHP 8.x and is framework agnostic, so it works with any Laravel version running on a supported PHP release. Carbon v3 support only landed in 2.6.5, so older pins can conflict with Laravel releases that ship Carbon 3. Check the Composer constraints before locking it into a legacy project.
- Does spatie/ssl-certificate verify that a certificate is trusted by a browser?
- No. The README carries an explicit notice that the package does not check whether the certificate is signed by a trusted authority. isValid() only means the current time falls between validFromDate and expirationDate, and optionally that the domain is covered. Treat it as an inventory and expiry monitoring tool rather than TLS security assurance, and pair it with openssl verify or a dedicated trust-validating tool if chain verification is mandatory.
- How do I get the number of days remaining before an SSL certificate expires?
- Call daysUntilExpirationDate() on the certificate instance to get an integer day count. expirationDate() and validFromDate() return Carbon instances, and lifespanInDays() gives the total validity window. These are the values you would typically compare against alert thresholds in a scheduled monitoring job.
- Can I fetch a certificate from a specific IP address or a non-standard port?
- Yes. Use the fluent downloader: SslCertificate::download()->usingPort(443)->fromIpAddress('1.2.3.4')->withSocketContextOptions([...])->forHost('example.com'). This helps when checking a node behind a load balancer before DNS is switched, or when dealing with SNI edge cases. Remember downloads go through stream_socket_client, so there is no built-in HTTP proxy support.
- How do I test SSL certificate monitoring without hitting the network?
- Use SslCertificate::createFromString($certificateData) with a captured PEM blob, or createFromFile() with a fixture file. Both paths avoid network and DNS entirely, so your tests stay deterministic and fast. You can also use createFromArray() to replay a certificate you previously serialized with toArray().
- What exceptions does spatie/ssl-certificate throw and how should I handle them?
- The package throws InvalidIpAddress, InvalidUrl, and CouldNotDownloadCertificate. All three are simple to catch and map onto whatever error taxonomy your application already uses. Network-bound problems such as DNS failures, timeouts, or blocked egress usually surface as CouldNotDownloadCertificate, so log the host and context alongside it.
- Can I inspect an expired or otherwise invalid SSL certificate?
- Yes. Pass false as the third argument to createForHostName(), for example SslCertificate::createForHostName('example.com', 30, false), to download the certificate even when it is invalid or expired. The object is populated normally afterwards and isValid() will return false, which is exactly what you want for expiry forensics and audit reporting.
- Does spatie/ssl-certificate work behind a proxy or on servers with restricted outbound traffic?
- Downloads use stream_socket_client and the package has no built-in HTTP proxy support. If your application servers have restricted egress, run certificate checks from a dedicated monitoring host or pass proxy-related settings through withSocketContextOptions(). Also plan for DNS flakiness, SNI handling, and IPv6 route availability as operational risks.
- How do I check that a certificate covers my domain, including wildcards?
- Use coversDomain($domain), or isValid($domain) to combine date validity with domain coverage in a single call. Wildcard-covers-root behaviour was only corrected in 2.6.10, so pin at least that version if you depend on wildcard assertions. For alerting pipelines, persist the toArray() output so you can diff SANs, issuer, and key details over time without re-downloading.