Skip to content

Configuring Certbot for Auto-Renew

Current Cloudflare API Token

Owner: Marc North

API Token: KCglokSaB78ApfrD_snuzPwSH16y5TCzVWM6jJd9

Install Certbot and the Cloudflare Plugin

sudo apt update
sudo apt install certbot python3-certbot-dns-cloudflare

Generate a Cloudflare API Token

  1. Log in to Cloudflare and navigate to API Tokens:
  2. Go to My Profile > API Tokens > Create Token

  3. Create a Custom Token with limited permissions:

  4. Under Permissions, select:
    • Zone: DNS -> Edit
  5. Under Zone Resources, choose:

    • Include > Specific Zone > methodgrid.com
  6. Generate and Save the Token for later use

Store the Cloudflare API Token on Your Server

To keep your API token secure, store it in a file with restricted permissions.

Create the configuration file

Create a file called cloudflare.ini in the /etc/letsencrypt directory:

vim /etc/letsencrypt/cloudflare.ini

Add the API token to the file

Paste the following content, replacing YOUR_API_TOKEN with your actual API token:

dns_cloudflare_api_token = YOUR_API_TOKEN

Secure the file

Set permissions so only root can access it:

chmod 600 /etc/letsencrypt/cloudflare.ini

Obtain the Wildcard SSL Certificate

certbot certonly --dns-cloudflare --dns-cloudflare-credentials /etc/letsencrypt/cloudflare.ini -d '*.methodgrid.com'

Restart Apache

systemctl restart apache2

Automate Certificate Renewal

Test renewal:

certbot renew --dry-run

Set up a cron job for daily renewal checks

crontab -e

Add a line to check for renewal daily at 2 AM. My suggestion (Ian), is that each webserver has their cron run 30 minutes apart, 2am for web1, 2.30am for web2, etc.

0 2 * * * /usr/bin/certbot renew --quiet
Last modified by: Unknown