HTTPS and Let's Encrypt certificates
Without HTTPS a website does not work properly today: the browser marks it as not secure and forms send data in readable form. A certificate from Let's Encrypt is free and the hosting usually issues it by itself. What to watch out for – domain validation, ever shorter certificate lifetimes and mixed content.
Why HTTPS
- Encryption – nobody along the way reads passwords, form data or cookies (public Wi-Fi, the internet provider).
- Integrity – nobody along the way changes the content of the page or inserts an ad or a malicious script into it.
- Browsers mark pages without HTTPS as not secure and many features (geolocation, service workers, the clipboard, HTTP/2 in browsers) work only over HTTPS.
- Search engines prefer addresses with HTTPS, see Canonical URLs and duplicate content.
A certificate confirms that the server may speak for the domain. For a website, a domain validated certificate (DV) is enough – the issuer verifies only that you control the domain. Browsers display paid certificates with organization validation (OV, EV) the same way as DV, so they bring nothing to an ordinary website.
Let's Encrypt and shorter lifetimes
Let's Encrypt is a non-profit certificate authority that issues DV certificates for free and automatically through the ACME protocol. A certificate has a limited validity and a program (an ACME client) renews it by itself before it expires. The validity is getting shorter (as of October 2026):
- Let's Encrypt issues certificates for 90 days. From 10 February 2027 the default validity will be 64 days and from 16 February 2028 only 45 days. It recommends renewing at two thirds of the validity, and even better according to ARI (ACME Renewal Information), which tells the client when to renew.
- The rules agreed between certificate authorities and browsers (the CA/Browser Forum) shorten the maximum validity of all public certificates – paid ones too: from 15 March 2026 to 200 days, from 15 March 2027 to 100 days and from 15 March 2029 to 47 days.
- Let's Encrypt has not sent expiry reminder emails since 4 June 2025. So do not rely on renewal blindly, see monitoring the validity at the end of the article.
Replacing a certificate by hand several times a year makes no sense – the certificate must be renewed by the hosting or by a program on the server.
Web hosting: the certificate in the control panel
On web hosting, a Let's Encrypt certificate is usually turned on in the control panel with one switch and the hosting renews it by itself. For it to be issued:
- the domain and www must point their A and AAAA records to this hosting (see Hosting, domains and DNS). A common mistake: the AAAA record stayed on the old server and the validation over IPv6 fails;
- the CAA record, if the domain has one, must allow letsencrypt.org;
- the address http://example.com/.well-known/acme-challenge/… must be reachable – rules in .htaccess that block files and folders starting with a dot must leave out the .well-known folder, see Protecting folders and files.
How Let's Encrypt validates the domain
- HTTP-01 – the ACME client stores a file on the website and Let's Encrypt downloads it from the address http://domain/.well-known/acme-challenge/token. The validation always starts on port 80 (HTTP). It follows redirects (at most ten, only to HTTP and HTTPS on ports 80 and 443), so redirecting the whole website to HTTPS does not matter. A certificate for all subdomains (*.example.com) cannot be obtained this way.
- DNS-01 – the client adds a TXT record _acme-challenge.example.com. The only way to get a certificate for *.example.com and for servers that are not reachable from the internet on port 80. The client must be able to change the DNS (through the API of the DNS provider).
- TLS-ALPN-01 – validation directly on port 443, used mainly by large hosting providers.
Your own server: certbot
On a VPS with Apache and Debian or Ubuntu, the most common ACME client is certbot. After installing the package, it issues a certificate and configures Apache right away:
sudo certbot --apache -d example.com -d www.example.com sudo certbot renew --dry-run
The second command tests the renewal against the Let's Encrypt staging server and renews nothing. The renewal itself is run automatically by the certbot package (a systemd timer or cron) – after installation, check that you have it and do not run the renewal by hand. Other clients (acme.sh, Caddy with built-in ACME) work the same way.
After turning on HTTPS
- Redirect HTTP to HTTPS and unify www – the rules are in the article Redirects in .htaccess.
- Turn on HSTS – the browser then opens the domain only over HTTPS, see Security headers and HTTPS.
- Fix mixed content – see below.
- Canonical addresses, the sitemap and links switch to https:// and in Google Search Console add the domain as a property of the Domain type (it covers both HTTP and HTTPS).
Mixed content
A page loaded over HTTPS that loads images, scripts or styles over http:// has mixed content. A sample page:
<img src="http://www.example.com/photos/cafe.jpg" alt="The café" width="600" height="400"> <script src="http://www.example.com/js/menu.js"></script>
We tested how browsers handle it in the engines of Chrome, Firefox and Safari (as of October 2026): the browser converts an image (and likewise audio and video) to https:// by itself and downloads it over HTTPS. A script (and likewise a style or a frame) is blocked completely, so part of the page stops working. Check the console in the developer tools (F12) – Chrome reports it as Mixed Content.
The fix:
- in templates, use paths from the root of the website (/photos/cafe.jpg) or full addresses with https://;
- in the texts of articles stored in the database, replace the addresses in bulk (after backing up the database, see Database backup and restore):
UPDATE articles SET text = REPLACE(text, 'http://www.example.com/', 'https://www.example.com/') WHERE text LIKE '%http://www.example.com/%';
- replace third-party services that do not support HTTPS with others;
- as a safeguard, the Content-Security-Policy: upgrade-insecure-requests header helps – the browser then loads all http:// addresses on the page over HTTPS, scripts and styles included. It does not replace fixing the addresses, though; the address must work over HTTPS.
Monitoring certificate validity
The expiry date of the certificate on the server is printed in Git Bash by the openssl program (the output is a sample, you will see a different date):
echo | openssl s_client -connect www.example.com:443 -servername www.example.com 2>/dev/null | openssl x509 -noout -enddate
notAfter=Dec 30 08:12:44 2026 GMT
The date is in UTC (GMT). A PHP script run by cron once a day checks the certificates of several websites and prints those that have fewer than 14 days left. Cron sends the output by email (see Cron and website backups):
<?php
// certificates.php – how many days are left until the certificates expire; run by cron
$sites = array('www.example.com', 'shop.example.com');
foreach($sites as $site)
{
$context = stream_context_create(array('ssl' => array('capture_peer_cert' => true, 'SNI_enabled' => true, 'peer_name' => $site)));
$connection = @stream_socket_client('ssl://'.$site.':443', $number, $error, 10, STREAM_CLIENT_CONNECT, $context);
if(!$connection) { echo $site.': cannot connect ('.$error.")\n"; continue; }
$certificate = openssl_x509_parse(stream_context_get_params($connection)['options']['ssl']['peer_certificate']);
$days = (int) floor(($certificate['validTo_time_t'] - time()) / 86400);
if($days < 14) echo $site.': the certificate expires in '.$days.' days ('.date('Y-m-d', $certificate['validTo_time_t']).")\n";
}
The connection verifies the certificate (the default behavior of PHP), so an invalid or expired certificate ends with a connection error – which is printed too. It needs the openssl extension. Services for monitoring website availability offer the same monitoring.
Related articles:
Redirects in .htaccess: 301, 302 and one address for the site
Protecting folders and files: deny, IP address and password
Security headers and HTTPS
Canonical URLs and duplicate content