First, resorting to editing the DB directly is never the first option – have learned that the hard way. http to https has a utility just for that specific purpose.
If using Moodle version 3.5.x, http://site/admin/tool/httpsreplace/
IF using any other version (lower <- 3.5) then the tool is
http://site/admin/tool/replace/
If the older one, search for http://site/ – including the trailing slash.
Replace with https://site/
If your site has moodle in a directory … like http://site/moodle/ … then include the directory.
Why use the tool … multiple tables – images for themes, for example, could be in mdl_config_plugins. Images inside courses used as icons for sections are uploaded files and reside in moodledata/filedir/ (those display because code builds from metadata contained in tables for generating course content).
One could, however, use an older method … do a mysql dump of the DB.
Open the sql dump in a text editor that has search and replace … on Linux, nano editor comes to mind.
nano nameofsqldump.sql
In nano [ctrl][w] (where) and in the dialog box for what to locate, use http://site/
Note what table that URL found in. Do another find [ctrl][w] leave the default … which is what you used the first time, and search again.
How many did you find that way?
Now to replace:
In nano, [ctrl][w], then [ctrl][r] first nano will ask for what to search for. After entering http://site/ and pressing enter, it will prompt for what to replace with:
https://site/ Pressing ENTER will begin the routine and take you to the first instanace it finds and ask if you want to replace that one. If you choose to do so, nano then goes the next instance and ask, etc..
OR if you are satisfied it’s finding what it should, look in the menu at the bottom of nano … there is an option to do them all.
When you choose that option, it might take some time. This to say be patient and wait for it to finish. If the sql file is large, they usually are, it will take some time and nano might appear to you as locked up/not doing anything … it is … just give it time.
Do NOT cancel.
Once finished, save the file. [cntrl][o] to write out the file.
Exit nano. [ctrl][x]
From the mysql client create another database for moodle … not the same one that was being used. Exit the client.
Then use command line mysql again only this time tell it to import the editedsql file into the new db you created for Moodle.
mysql -u [superuser[ -p'[superuserpass]’ [newmoodledb] < editedsql.sql
You replace [] items above.
Yet another … using sed.
sed -e “s/https:\/\/sos.sosoftexas.org\/moodle34\//http:\/\/sos.sosoftexas.org\/moodle34\//g” sedtest.sql > editedsedtest.sql
**NOTE**: the \’s around the URL’s ‘/’ are absolutely needed. In linux a ‘\’ command line environments,
like bash, is an escape character – meaning treat the next character as a literal.
Then import newmysqldump.sql into the new database created for the moodle.
Then, last step, edit config.php. file in Moodle code and point to the new DB.
There is also in 3.5.x a command line utility to do the same.
cd /path/to/moodle/code/admin/tool/httpsreplace/cli/
Issuing: php url_replace.php (the script found in that directory) will present you
with help – which says:
Examines DB for non-https src or data links, and lists broken links or replaces all links.
Options:
-h, --help Print out this help
-l, --list List of http (not https) urls on a site in the DB that would become broken.
-r, --replace List of http (not https) urls on a site in the DB that would become broken.
--confirm Replaces http urls with https across a site's content.
Example:
$ sudo -u www-data /usr/bin/php admin/tool/httpsreplace/cli/url_replace.php --list