Last active
May 1, 2017 17:17
-
-
Save acbilimoria/490ac934a071772a823b3e33b0dcb997 to your computer and use it in GitHub Desktop.
WordPress on Ubuntu 16: Add LetsEncrypt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install the Let's Encrypt Client | |
sudo apt-get update | |
sudo apt-get install python-letsencrypt-apache | |
# Set up the SSL Certificate for ServerName and ServerAlias | |
# select force SSL if desired | |
# add email | |
# accept terms and conditions | |
# select appropriate .conf file if applicable | |
sudo letsencrypt --apache -d example.com -d www.example.com | |
# Modify apache2.conf | |
sudo vim /etc/apache2/apache2.conf | |
Navigate to below the closing Directory tag: | |
<Directory /var/www/> | |
Options Indexes FollowSymLinks | |
AllowOverride None | |
Require all granted | |
</Directory> | |
Add the following: | |
<Directory /var/www/html/> | |
Options Indexes FollowSymLinks MultiViews | |
AllowOverride All | |
Order allow,deny | |
allow from all | |
</Directory> | |
# Create or modify .htaccess | |
At the top of the file, add this: | |
RewriteEngine On | |
RewriteBase / | |
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] | |
RewriteRule ^(.*)$ https://%1/$1 [R=301,L] | |
# Install WP CLI and run DB find and replace | |
# http://wp-cli.org | |
cd /var/wwwh/html | |
wp search-replace "http://example-alias.example-url" "https://example-alias.example-url.com"; | |
# Multi-File find and replace | |
cd /var/www/html/wp-content/themes/example-theme/ | |
# Move Libraries out of harm's way | |
sudo mv _includes/PHPMailer/ .. | |
# find http: and replace it with https: | |
sudo find ./ -type f -exec sed -i 's/http:/https:/g' {} \; | |
# Change specific URLs back to http (optional) | |
sudo find ./ -type f -exec sed -i 's/https:\/\/url-example/http:\/\/url-example/g' {} \; | |
# move libraries back | |
sudo mv ../PHPMailer _includes/ | |
# Reload the server | |
sudo service apache2 reload | |
# Automate SSL cert renewal | |
sudo crontab -e | |
# Add this line: | |
30 2 * * 1 /usr/bin/letsencrypt renew >> /var/log/le-renew.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment