{"id":33,"date":"2019-04-19T17:32:14","date_gmt":"2019-04-19T22:32:14","guid":{"rendered":"https:\/\/scythk.com\/?p=33"},"modified":"2019-04-19T17:32:14","modified_gmt":"2019-04-19T22:32:14","slug":"enable-ssl-for-wordpress","status":"publish","type":"post","link":"https:\/\/scythk.com\/index.php\/2019\/04\/19\/enable-ssl-for-wordpress\/","title":{"rendered":"Enable SSL for WordPress"},"content":{"rendered":"<p>I spent 4 hours on setup the SSL of my website. I&#8217;ve search a lot of posts about how to enable SSL but nobody mentioned that you need to setup Apache fist. Here I&#8217;m sharing the whole process I&#8217;ve been using.<\/p>\n<p>Some VPS hosts, like DigitalOcean that I&#8217;ve been using, require that your domain must be managed on DigitalOcean to enable the SSL feature. Check their website first for instructions.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Get_a_SSL_certification_from_Lets_encrypt\"><\/span>Get a SSL certification from Let&#8217;s encrypt<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Visit <a href=\"https:\/\/certbot.eff.org\/\">Certbot website<\/a>, choose your software and system and it&#8217;ll show you a complete guide.<\/p>\n<p>Here it&#8217;s Apache and Ubuntu 16.04. The default is like this.<\/p>\n<pre><code class=\"language-bash\">sudo apt-get update\nsudo apt-get install software-properties-common\nsudo add-apt-repository universe\nsudo add-apt-repository ppa:certbot\/certbot\nsudo apt-get update\nsudo apt-get install certbot python-certbot-apache\n<\/code><\/pre>\n<p>Since they provide plugin for DigitalOcean, here I used<\/p>\n<pre><code class=\"language-bash\">sudo apt-get install certbot python3-certbot-dns-digitalocean\n<\/code><\/pre>\n<p>instead of\n<em>python-certbot-apache<\/em>.\nThen<\/p>\n<pre><code class=\"language-bash\">sudo certbot --apache\n<\/code><\/pre>\n<p>And an addition step for my dns plugin.<\/p>\n<pre><code class=\"language-bash\">sudo certbot -a dns-digitalocean -i apache -d &quot;*.example.com&quot; -d example.com --server https:\/\/acme-v02.api.letsencrypt.org\/directory\n<\/code><\/pre>\n<p>The SSL certs are store in \/etc\/letsencrypt\/live\/example.com\/, where\n<em>cert.pem<\/em> is the public key and <em>privkey.pem<\/em> is the private.<\/p>\n<p>You might need to add those files to your host&#8217;s website.<\/p>\n<p>The Let&#8217;s encrypt license need to be renewed every 90 days and certbot will add a schedule using cron to do so.<\/p>\n<pre><code class=\"language-bash\">ls \/etc\/cron.d\n<\/code><\/pre>\n<p>You should be able to see a\n<em>certbot<\/em> file and you don&#8217;t need to worry about the renewal.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Setup_Apache\"><\/span>Setup Apache<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The most tricky yet most important part that I&#8217;ve been struggled to.\nEdit the apache configuration file.<\/p>\n<pre><code class=\"language-bash\">sudo nano \/etc\/apache2\/sites-available\/000-default.conf\n<\/code><\/pre>\n<p>I&#8217;ve added port 80 in previous post and now let&#8217;s add the 443.<\/p>\n<pre><code class=\"language-apache\">&lt;VirtualHost *:443&gt;\n    ServerName 138.197.203.187\n    ServerAdmin scythk@gmail.com\n    DocumentRoot \/var\/www\/html\n\n    ErrorLog ${APACHE_LOG_DIR}\/error.log\n    CustomLog ${APACHE_LOG_DIR}\/access.log combined\n\n    SSLEngine On\n    SSLCertificateFile \/etc\/letsencrypt\/live\/scythk.com\/cert.pem\n    SSLCertificateKeyFile \/etc\/letsencrypt\/live\/scythk.com\/privkey.pem\n    SSLCertificateChainFile \/etc\/letsencrypt\/live\/scythk.com\/chain.pem\n\n&lt;\/VirtualHost&gt;\nSSLProtocol all -SSLv3 -TLSv1 -TLSv1.1\nSSLCipherSuite ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS\nSSLHonorCipherOrder on\nSSLCompression off\nSSLSessionTickets off\n<\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Setup_wp-configphp\"><\/span>Setup wp-config.php<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Open wp-config.php<\/p>\n<pre><code class=\"language-sh\">sudo nano \/var\/www\/html\/wp-config.php\n<\/code><\/pre>\n<p>Find this part<\/p>\n<pre><code class=\"language-php\">\/** Absolute path to the WordPress directory. *\/\nif ( ! defined( &#039;ABSPATH&#039; ) ) {\n        define( &#039;ABSPATH&#039;, dirname( __FILE__ ) . &#039;\/&#039; );\n}\n<\/code><\/pre>\n<p>Insert the following part in front of it.<\/p>\n<pre><code class=\"language-php\">$_SERVER[&#039;HTTPS&#039;] = &#039;on&#039;;\ndefine(&#039;FORCE_SSL_LOGIN&#039;, true);\ndefine(&#039;FORCE_SSL_ADMIN&#039;, true);\n<\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Setup_Wordpress\"><\/span>Setup Wordpress<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Don&#8217;t bother with the .htaccess setting, install Really Simple SSL in WordPress plugin page, let it do the job.<\/p>\n<figure id=\"attachment_mmd_34\" class=\"wp-block-image alignnone\"><img width=\"300\" height=\"150\" src=\"https:\/\/i0.wp.com\/scythk.com\/wp-content\/uploads\/2019\/04\/simplessl1.png?fit=300%2C150&#038;ssl=1\" class=\"attachment-300x150 size-300x150\" alt=\"\" decoding=\"async\" loading=\"lazy\" align=\"none\" srcset=\"https:\/\/i0.wp.com\/scythk.com\/wp-content\/uploads\/2019\/04\/simplessl1.png?w=938&#038;ssl=1 938w, https:\/\/i0.wp.com\/scythk.com\/wp-content\/uploads\/2019\/04\/simplessl1.png?resize=300%2C150&#038;ssl=1 300w, https:\/\/i0.wp.com\/scythk.com\/wp-content\/uploads\/2019\/04\/simplessl1.png?resize=768%2C383&#038;ssl=1 768w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/figure>\n<figure id=\"attachment_mmd_35\" class=\"wp-block-image alignnone\"><img width=\"214\" height=\"300\" src=\"https:\/\/i0.wp.com\/scythk.com\/wp-content\/uploads\/2019\/04\/simplessl2.png?fit=214%2C300&#038;ssl=1\" class=\"attachment-214x300 size-214x300\" alt=\"\" decoding=\"async\" loading=\"lazy\" align=\"none\" srcset=\"https:\/\/i0.wp.com\/scythk.com\/wp-content\/uploads\/2019\/04\/simplessl2.png?w=942&#038;ssl=1 942w, https:\/\/i0.wp.com\/scythk.com\/wp-content\/uploads\/2019\/04\/simplessl2.png?resize=214%2C300&#038;ssl=1 214w, https:\/\/i0.wp.com\/scythk.com\/wp-content\/uploads\/2019\/04\/simplessl2.png?resize=768%2C1075&#038;ssl=1 768w, https:\/\/i0.wp.com\/scythk.com\/wp-content\/uploads\/2019\/04\/simplessl2.png?resize=732%2C1024&#038;ssl=1 732w\" sizes=\"auto, (max-width: 214px) 100vw, 214px\" \/><\/figure>\n<p>Now try to visit <a href=\"https:\/\/yoursite.com\">https:\/\/yoursite.com<\/a>, if succeed, go to WordPress Settings, change the\n<strong>WordPress Address (URL)<\/strong> and <strong>Site Address (URL)<\/strong> to the https address.<\/p>\n<figure id=\"attachment_mmd_38\" class=\"wp-block-image alignnone\"><img width=\"300\" height=\"62\" src=\"https:\/\/i0.wp.com\/scythk.com\/wp-content\/uploads\/2019\/04\/wordpressurl.png?fit=300%2C62&#038;ssl=1\" class=\"attachment-300x62 size-300x62\" alt=\"\" decoding=\"async\" loading=\"lazy\" align=\"none\" srcset=\"https:\/\/i0.wp.com\/scythk.com\/wp-content\/uploads\/2019\/04\/wordpressurl.png?w=1222&#038;ssl=1 1222w, https:\/\/i0.wp.com\/scythk.com\/wp-content\/uploads\/2019\/04\/wordpressurl.png?resize=300%2C62&#038;ssl=1 300w, https:\/\/i0.wp.com\/scythk.com\/wp-content\/uploads\/2019\/04\/wordpressurl.png?resize=768%2C160&#038;ssl=1 768w, https:\/\/i0.wp.com\/scythk.com\/wp-content\/uploads\/2019\/04\/wordpressurl.png?resize=1024%2C213&#038;ssl=1 1024w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/figure>\n<p><strong>DON&#8217;T<\/strong> change this unless you could access to the https, or you won&#8217;t be able to connect to your admin page and change that setting back.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Oh_its_too_late\"><\/span>Oh it&#8217;s too late<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<details>\nNot yet, login to MySQL\n\n<pre><code class=\"language-bash\">sudo mysql -u root -p\n<\/code><\/pre>\n\n<pre><code class=\"language-sql\">USE wordpress;\nUPDATE wp_options SET option_value=&#039;http:\/\/yoursite.com&#039; WHERE option_id=1;\nUPDATE wp_options SET option_value=&#039;http:\/\/yoursite.com&#039; WHERE option_id=2;\n<\/code><\/pre>\n\nNow you can access through http and setup everything else.\n<\/details>\n<h2><span class=\"ez-toc-section\" id=\"References\"><\/span>References<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><a href=\"https:\/\/www.sizuo.org\/wordpress-https.html\">Wordpress\u4f7f\u7528SSL\u8bc1\u4e66\u5f00\u542fHTTPS\u6700\u7b80\u5355\u7684\u529e\u6cd5<\/a><\/p>\n<p><a href=\"https:\/\/www.centos.bz\/2018\/06\/wordpress%E4%B8%80%E6%AC%A1%E6%80%A7%E6%90%9E%E5%AE%9Assl%E5%85%A8%E5%B1%80%E8%AE%BE%E7%BD%AE%E4%BB%A5%E5%8F%8A%E6%BD%9C%E5%9C%A8%E9%97%AE%E9%A2%98%E8%A7%A3%E5%86%B3\/\">WordPress\u4e00\u6b21\u6027\u641e\u5b9assl\u5168\u5c40\u8bbe\u7f6e\u4ee5\u53ca\u6f5c\u5728\u95ee\u9898\u89e3\u51b3<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>I spent 4 hours on setup the SSL of my website. I&#8217;ve search a lot of posts about how to enable SSL but nobody mentioned that you need to setup Apache fist. Here I&#8217;m sharing the whole process I&#8217;ve been using. Some VPS hosts, like DigitalOcean that I&#8217;ve been using, require that your domain must [&hellip;]<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-33","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/paTSGz-x","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/scythk.com\/index.php\/wp-json\/wp\/v2\/posts\/33","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/scythk.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/scythk.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/scythk.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/scythk.com\/index.php\/wp-json\/wp\/v2\/comments?post=33"}],"version-history":[{"count":3,"href":"https:\/\/scythk.com\/index.php\/wp-json\/wp\/v2\/posts\/33\/revisions"}],"predecessor-version":[{"id":39,"href":"https:\/\/scythk.com\/index.php\/wp-json\/wp\/v2\/posts\/33\/revisions\/39"}],"wp:attachment":[{"href":"https:\/\/scythk.com\/index.php\/wp-json\/wp\/v2\/media?parent=33"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/scythk.com\/index.php\/wp-json\/wp\/v2\/categories?post=33"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/scythk.com\/index.php\/wp-json\/wp\/v2\/tags?post=33"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}