Convert http to https

Convert http to https

by Chris Nelson -
Number of replies: 6

We are running moodle 2.4 and we are converting from http to https for the whole course site. I have the cert set up and have tested https to see if I can see the site. I know the changes in moodle administration and config.php file to make, the issue I am having is what to change in the database so all items are converted from http to https. I am unable to find much on moodle 2.4. If I search I find mostly 3.x info. Which has a search and replace option. I can do a mysql dump of the database and change references for http to https or as I understand there is an option in 2.4 to do something similar. In the past folk recommend making changes to the back up database file. I am asking 2 things:

1. what should I be using to make the changes?

2. what needs to be changed in the database file? i.e. http:\\website to https:\\website? Are there other things that need changing as well? Or do I change all references of Http to https?

Thanks for any insight

Average of ratings: -
In reply to Chris Nelson

Re: Convert http to https

by Ken Task -
Picture of Particularly helpful Moodlers

First, just before you pull the trigger on converting the URL contained in the DB, *** make a backup ... sql dump ... of the database.

Two methods ... have used both ...

IF the site is large with many internal links, the tool to convert isn't in the menus of a 2.4 (from what I re-call).

With browser go to http://site/admin/tool/replace/

Simple search and replace tool.   Uhhhh ... the slashes lean to the right, BTW ...

Search for http://yoursite/

Replace with https://yoursite/

I would include the http:// in front and the trailing slash.

You already about changing config.php file.

One other step ... in moodledata/ manually remove the **contents** of cached directories.

(consider making a tar ball of moodledata as well).

Also remove any files contained in moodledata/sessions/

The other way ... make a copy of that mysql dump backup you made at the beginning, and use that copy to search and replace with an editor ... nano is a good one for that purpose.

Again: search for http://yoursite/ and replace with https://yoursite/ using the trailing slash.

Then import that edited sql file to a new database ... if you had moodle as the DB before, use 'moodle2' as the new database name and import the edited sql dump to the  moodle2 DB.

Thjs also has an additional affect ... new database is cleaner and not as 'loose' as your old DB might be ... ie, more optimized.

Since using a different DB now, edit the config.php file for DB name.

Advantage in doing this ... IF something really messes up ... not likey ... you can quickly get your site back simply by editing the config.php file.

Also, consider setting apache server to auto redirect any http:// traffic headed to your server  to https://

Also consider that 2.4.x is very very old.   Think I'd do the http to https thang first, get that working, then work on upgrading the site rather than trying to do it all at once, BTW.

'spirit of sharing', Ken


In reply to Ken Task

Re: Convert http to https

by Chris Nelson -

Many thanks Ken. I forgot to mention we are windows and not linux. having said that a lot of the things you have said apply. You added new items which I was not familiar with.

Is the trailing slash required in Windows?

You also mention "...moodledata/ manually remove the **contents** of cached directories." are you referring to the cache folder at the root of moodledata folder? Or are you referring to the sub folder called cachestore_file dir under the cache directory? In the cache folder I see 4 other folders - cachestore_file, editor_tinymce,tcpdf  and theme.

I assume "(consider making a tar ball of moodledata as well)." applies only to linux?

Did not know about this "...Then import that edited sql file to a new database ..."

The plan is to move 2.4 to 2.7, then 3.1 and 3.5.

I have also considered moving to linux (Ubuntu LT). But biggest hesitation is making it is secure when facing the internet.


In reply to Chris Nelson

Re: Convert http to https

by Ken Task -
Picture of Particularly helpful Moodlers

Ahhhh Windoze ... no offense, but had I known that ... probably wouldn't have responded ... see lower down.

Backup (sql dump) the database first.   Still do that.   phpmyadmin?

Pardon the mini-rant! smile 

You mean Windows is 'special' .... well, yeah it is ... has always been 'special'.   As you can tell, I don't work with 'special' anymore .... haven't since I compared Linux vs Windows NT 4.0 for internet services.   Gee, really ... Windows servers are more secure right out of the shrink wrap (new install) .... Gee ... how many providers offer Windows servers to customers that want to lease a server for internet?  Answer: fewer than those that offer Linuxes ... end mini-rant!

2.4 is old ... period ... wonder how many folks in these forums remember any quirks that version had?

Trailing slash .... if one were to inspect moodle code one will find many $CFG-->wwwroot's in it.  So your config file is important there but note there is no trailing slash for that variable in config.php.  Is your code in a directory ... ie http://site/moodle/ or at the document root of your web service.

In the past I used trailing slash and there were no issues.

Caches should rebuild ... so only moodledata/cache/**contents** and moodledata/session/**contents**  From what I **re-call** (many moons ago) of earlier versions of Moodle those two and all subfolders used to create some issues with conversion of http to https for some folks.

tar ball is a backup. tar = tape archiver ... the way all servers were backed up at one time - even 'special machines' ... many moons ago ... can still use tar for files to disk.  What do you have to make an archive of a folder?

importing an SQL file into a MySQL DB server is pretty basic stuff.   Does your 'special' server have a command line mysqldump command you can run from (shudder) DOS?

Uhhh ... might want to start reading up on MySQL ... IF that's the DB you are using:

https://dev.mysql.com/doc/refman/5.7/en/mysqldump-sql-format.html

Or are you running MSSQL?   Sorry ... can't help ya there.

What I was suggesting to you about the DB stuff, if you re-read it and think about it ... was a way to have yet another fall back position for the database if there is a hickup or operator error.

Please read the 'official docs from Moodle':

https://docs.moodle.org/35/en/Transitioning_to_HTTPS

https://docs.moodle.org/35/en/Upgrading

'spirit of sharing', Ken


In reply to Ken Task

Re: Convert http to https

by Chris Nelson -

Yes, I use a "special " server. I am glad you responded though. thanks for that.

code is in directory https:\\website\moodle.

I can use 7-zip to create a tar file.

when I refer to sql I am referring to MySQL - is this not recommended database anymore? I have heard of either going to MariaDB or postgres,

Yes, I can run MySQL dump from the cmd. prompt. I tested creating a MySQL dump file. Just did not try going the other way. Not running mssql.

thanks, Chris


In reply to Chris Nelson

Re: Convert http to https

by Ken Task -
Picture of Particularly helpful Moodlers

Uhhh ... do you see anything wrong with ... and this is a quote ... "https:\\website\moodle" ... that's not really a question to answer unless you really see nothing wrong with that!!!!

The link for how to upgrade should lead you to investigating what one has to do to upgrade 2.4 to 3.5.

Version requirements ... PHP, MySQL or MariaDB.   Good question if MariaDB is now the recommendation .... can tell you this ... CentOS 7 (LTS) and I think Ubuntu 16.04 another LTS using MariaDB as their (makers of the operating system)  'blessed' database.    But, don't think there is anything coded in Moodle that takes advantage of anything MariaDB has that supposed to be improved/etc.   So?

In your current moodle go to server -> environment ... update the component ... then choose each version from 2.4 all the way up to 3.5 *and note* which item checks turn yellow or red.

You will get or should get lots of practice at full site backups.

What is it 'they' say .... "plan your work ... work your plan"?

'spirit of sharing', Ken


In reply to Ken Task

Re: Convert http to https

by Chris Nelson -

Success. I was able to move from http to https  - thanks for the tips Ken.

Now I look forward to the upgrade process to version 3.5.