Enable SSL in OpenCart

  • Install SSL
  • Enable SSL in Admin
  • Edit config.php files

Install SSL

On an Apache (Ubuntu) system where you have SSH access, you can run the following commands to install an SSL (Let’s Encrypt)

sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:certbot/certbot # add certbot repo
sudo apt-get update
sudo apt-get install python-certbot-apache # install certbot
sudo certbot --apache # run certbot

Don’t forget to add certbot renew to cron

sudo crontab -e
# @daily certbot renew # Check SSL certificates for renewal

Enable SSL in Admin

Admin > System > Settings (Edit) > Server > Use SSL (Yes) > Save

Edit config files

Edit config.php

// HTTPS
define('HTTPS_SERVER', 'https://yourdomain.com/');

Edit admin/config.php

// HTTPS
define('HTTPS_SERVER', 'https://yourdomain.com/admin/');
define('HTTPS_CATALOG', 'https://yourdomain.com/');

Troubleshooting

If you forgot to edit the system settings, and are now unable to login at the Admin login page, you’ll have to edit the setting in the database via PHPMyAdmin

Open your OpenCart database (find out from config.php if you’re not sure which one it is) and go to the oc_settings table, run the following SQL query

UPDATE `oc_setting` SET `value` = '1' WHERE `key`='config_secure'

  • Site looks broken, getting the following error in console
Failed to load resource: net::ERR_INSECURE_RESPONSE

This can happen when you have transferred the site to a new server/domain and SSL is not installed on the new server/domain. Installing an SSL will fix the issue.
{"cc_re__cc_re__cc_by_sa_4_0": ["e posts on it are, and will always be, a work in progress. If i waited for perfection, i\u2019d never get anything done.\n    </section>\n    <span class=\"copyright\">A project of <a href=\"https://29concepts.com\">29 CONCEPTS SMC-PVT LTD</a>. Created with <i class=\"fas fa-heart\"></i> by <a href=\"https://aamnah.com\">Aamnah</a>. <br> All content is licensed under Creative Commons <i class=\"fab fa-creative-commons\"></i> <i class=\"fab fa-creative-commons-by\"></i> <i class=\"fab fa-creative-commons-sa\"></i> <a href=\"https://creativecommons.org/licenses/by-sa/4.0/\">CC BY-SA 4.0</a></span>\n  </footer>\n\n  </div>\n\n</div>\n\n<script src='/prism/prism.js'></script>\n\n\n<script async src=\"https://www.googletagmanager.com/gtag/js?id=UA-51214502-1\"></script>\n<script>\n  window.dataLayer = window.dataLayer || [];\n  function gtag(){dataLayer.push(arguments);}\n  gtag('js', new Date());\n\n  gtag('config', 'UA-51214502-1');\n</script>\n\n\n<script defer src=\"https://use.fontawesome.com/releases/v5.6.3/js/all.js\" integrity=\"sha384-EIHISlAOj4zgYieurP0SdoiBYfGJKkgWedPHH4jCzpCXLmzVs"], "copyright__copyright__copyright": ["in\n\nOpen your OpenCart database (find out from config.php if you\u2019re not sure which one it is) and go to the oc_settings table, run the following SQL query\n\nUPDATE `oc_setting` SET `value` = '1' WHERE `key`='config_secure'\n\n  \u2022 Site looks broken, getting the following error in console\nFailed to load resource: net::ERR_INSECURE_RESPONSE\n\nThis can happen when you have transferred the site to a new server/domain and SSL is not installed on the new server/domain. Installing an SSL will fix the issue."]}