Moving whole site from http to https on LAMP virtual host

Moving whole site from http to https on LAMP virtual host

by Peter DeBruyn -
Number of replies: 4

I have an account with virtual hosting, LAMP/Cpanel, and just had an SSL certificate installed.  When I asked them for instructions on how to move moodle from http to https they suggested adding the following to the .htaccess file:

===========

# Always use https for secure connections
# Replace 'www.example.com' with your domain name
# (as it appears on your SSL certificate)
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]

============

That seems like a reasonable thing to do, and then I'm thinking I would edit the wwwroot in config.php from http to https.


I'm wondering if I do those two things would that be complete or would I need to change HTTP security setting for Use HTTPS for logins to yes?


I can't seem to find instructions on this in the documentation or my forum searches, if anybody has a good reference for me I would appreciate that and do you think the above will work for me?


Thanks

Average of ratings: -
In reply to Peter DeBruyn

Re: Moving whole site from http to https on LAMP virtual host

by John Okely -

Yeah you will need to change the wwwroot to use https. Note that you should leave HTTPS for logins on 'no'. That is used when you want people to access the site via http but you want to use https for logins only (use of the setting is not recommended)

From memory I think that might be all that is needed

In reply to Peter DeBruyn

Re: Moving whole site from http to https on LAMP virtual host

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Since you will have moved the site to a new URL (even if the only change is http -> https) you should do this bit of the Moodle migration process: https://docs.moodle.org/29/en/Moodle_migration#Update_links_containing_wwwroot_in_the_databse

In reply to Tim Hunt

Re: Moving whole site from http to https on LAMP virtual host

by Peter DeBruyn -

I run that script and it seems fine through UPDATE mdl_pma_history and then it produces the following error:

======

Debug info: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table = SUBSTRING(REPLACE(table, 'http://www.mysite.org', 'https://www.mysi' at line 2
UPDATE mdl_pma_history
SET table = SUBSTRING(REPLACE(table, ?, ?), 1, 64)
WHERE table IS NOT NULL
[array (
0 => 'http://www.mysite.org',
1 => 'https://www.mysite.org/',
)]
Error code: dmlwriteexception
Stack trace:
line 446 of /lib/dml/moodle_database.php: dml_write_exception thrown
line 908 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
line 2271 of /lib/dml/moodle_database.php: call to mysqli_native_moodle_database->execute()
line 7008 of /lib/adminlib.php: call to moodle_database->replace_all_text()
line 60 of /admin/tool/replace/index.php: call to db_replace()
======

Any help with that is appreciated.

In reply to Peter DeBruyn

Re: Moving whole site from http to https on LAMP virtual host

by Peter DeBruyn -

The site seems ok, EXCEPT, when I go to add a resource / file the "content" section of the add page shows a working icon but never loads...  No idea what is causing that problem.  My dataroot is '/home/myst/moodledata'


Any ideas?