Skip to content

Instantly share code, notes, and snippets.

@rutcreate
Created October 4, 2022 12:17
Show Gist options
  • Save rutcreate/c8ad5e8560d8290cf244a185cb4e45c3 to your computer and use it in GitHub Desktop.
Save rutcreate/c8ad5e8560d8290cf244a185cb4e45c3 to your computer and use it in GitHub Desktop.
Cloudflare SSL for WordPress

Prerequisite

  • http://yourdomain.com is accessible. (Make sure protocol is http)
  • Update Cloudflare DNS see topic Minimum DNS settings

Minimum DNS settings

Type Value Proxied Status
A 0.0.0.0 Proxied
CNAME @ Proxied

NOTE: Replace 0.0.0.0 with your host IP address.

WordPress's Server

1. Install WP CLI

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
wp --info

REF: https://wp-cli.org/

2. Back up database (Optional but recommended)

wp db export <filename.sql>

3. Replace http to https

wp search-replace 'http://yourdomain.com' 'https://yourdomain.com'

NOTE: Make sure no tailing slash.

4. Install Plugin Cloudflare Flexible SSL

Installing this plugin will fixed the redirect loop.

wp plugin install cloudflare-flexible-ssl
wp plugin activate cloudflare-flexible-ssl

Troubleshooting

  • If you encounter error cannot create file or directory, make sure your logged in user has rights to do it.
  • Plugin name may be changed in the future, you may use wp plugin search cloudflare and use slug instead.

Cloudflare

1. Turn on SSL

  1. Go to menu SSL/TLS -> Overview
  2. Check option Flexible

This step tell to make encryption only between browser and cloudflare. Cloudflare and server use http communication as before.

2. Force use https://

  1. Go to menu SSL/TLS -> Edge Certificate
  2. Turn on option Always Use HTTPS

DONE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment