Going from https to http using 2.8.3

Going from https to http using 2.8.3

by Brian Amesse -
Number of replies: 22

Good day everyone,

I have been moving my site over from an old domain to a new domain. I transferred everything over and did all major changes (well I thought all major changes) and so my site is up and looked good, until someone tried to log in and I realized it is always pointing to https://mysite when I try to login so I can't log in. I was wondering what I have to do to fix this. I followed the latest documentation and did a sed argument to change from one domain to the other... which worked but it kept it https. I changed the CFG->www root so I can get to the main page of my site but anything passed that gets changed to https and no longer works.


I appreciate all the input.


Brian

Average of ratings: -
In reply to Brian Amesse

Re: Going from https to http using 2.8.3

by Bret Miller -
Picture of Particularly helpful Moodlers

did you sed from https://olddomain.com to http://newdomain.com? Is $CFG->wwwroon set to http:?

In reply to Bret Miller

Re: Going from https to http using 2.8.3

by Brian Amesse -

I maually entered the CFG->wwwroot to http... but I could not sed -e 's/https:/oldserver/http/newserver.com/g' oldmysqldump.sql > newmysqldump.sql it didn't work and I figured that is where my issue was I appreciate you already pointing me somewhere.

Also I can go to http://mymoodlesite.ca

but as soon as I select login it's trying to go to https/mysite/login

excuse the url's they are all flagged as spam lol


In reply to Brian Amesse

Re: Going from https to http using 2.8.3

by Bret Miller -
Picture of Particularly helpful Moodlers

You have to escape the slashes:

sed -e 's/https:\/\/oldserver/http:\/\/newserver.com/g' oldmysqldump.sql > newmysqldump.sql

Average of ratings: Useful (1)
In reply to Bret Miller

Re: Going from https to http using 2.8.3

by Brian Amesse -
After doing this I again am not sure I am doing something right.


I do a search of the .sql file and I really find nothing that has https://mysite nor even http... I do see of course find a bunch of entries of mysite.ca 

I feel like it should be simple and I can't figure out why it forces to https for the whole site except for the home page which seems to be because I manually put it in the config file... 

Thanks for at least having a place for me to vent as I feel pretty lost right now and so close to making this work.


In reply to Brian Amesse

Re: Going from https to http using 2.8.3

by Bret Miller -
Picture of Particularly helpful Moodlers

I am not sure what to tell you. Grep says I have 122 occurrences of https: in my database dump. But it seems they're all references to resources on the site. None of them are in the config tables. So that brings us back to config.php I guess. Are you sure the $CFG->wwwroot matches the URL that you'd type into a browser to access the site? In other words, it should be http://mysite.ca and not http://mysite.ca/httpdocs/ or whatever the internal directory is unless you use that directory in the base URL of the site.

Also, if you have access to the command line, I'd try purging the cache:

php admin/cli/purge_caches.php

from the root directory of the site.

In reply to Brian Amesse

Re: Going from https to http using 2.8.3

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
In reply to Visvanath Ratnaweera

Re: Going from https to http using 2.8.3

by Brian Amesse -

I have followed the documentation. If you can say a step you think I missed I would appreciate it but obviously before coming to the forums I have gone through the moodledocs. Not to mention I am also on IRC talking to people about it. Everyone has come to the same conclusion and can't tell me why when I change the wwwroot that the whole site doesn't use http instead of https.

If you read the comments above you will know that the only part that deals with my issue is modifying the config.php and using this tool  {wwwroot}/admin/tool/replace/index.php or the sed statement... which is not working.

So frustrating... I am thinking I am going to start from scratch and just backup courses and put them into the new moodle site...

In reply to Brian Amesse

Re: Going from https to http using 2.8.3

by Ken Task -
Picture of Particularly helpful Moodlers

If all was followed correctly, it could be the configuration of your new Apache server.  It is possible to have a re-write rule in apache config that forces all http traffic to https.   There is also a setting in Moodle to use https for login only ... then it flips back to http.   Found in mdl_config table.   Check:

select * from `mdl_config` where `name` like "%https%

loginhttps is set to 0 if using http and 1 if using https.

Can force http via config.php file by adding a line:

$CFG-> loginhttps = 0;

One can check how Apache is behaving via command line curl:

curl -I http://yoursite [ENTER]

If it's set to auto-re-direct one will see a line in the response that shows:

Location: https://

'spirit of sharing', Ken

In reply to Brian Amesse

Re: Going from https to http using 2.8.3

by Ken Task -
Picture of Particularly helpful Moodlers

Still have the original SQL dump from the old site?

An sql dump is an ascii file - it's text.   Download the .sql file an open it with a text editor on local host ... or since you have linux, if you have command line access, use a text editor in Linux.   I like to use nano which is an old 'wordstar' like text editor.   One can do a search and replace (in nano the search part is under 'where') just to see if there is any reference to the old site by 'https://oldsite/' ... notice here you don't have to escape the '/' characters.

It might be that the search and replace failed before the import and that you may not have the full links that have http:// or https:// in front of them but only /moodle/ (relative addressing) and that won't work with Moodle.

Just a guess in reading over this thread ...

'spirit of sharing', Ken


In reply to Ken Task

Re: Going from https to http using 2.8.3

by Brian Amesse -
I have the .sql file and I did a search via grep and found no https://mysite.ca nor http://mysite.ca I did of course find mysite.ca.

In my config.php I have set 

$CFG->loginhttps = 0;

$CFG->loginhttps= 'false';

which seems to make it half work.

Maybe I will just show you what I mean...

my site is http://trafmoodle.ca

when you try to log in it's trying to use https... so it's like it's only half https still if that makes sense.

Thank you for taking time to help



In reply to Brian Amesse

Re: Going from https to http using 2.8.3

by Ken Task -
Picture of Particularly helpful Moodlers

You only need this one:
$CFG->loginhttps = 0;
remove the other (redundant)

Apache on your server is not configured to use https at all ... http ONLY.
Keep that in mind should you decide later to try https again.  So forget my
suggestion to look for a rewrite rule.

Sounds like you attempted the sed command on the original .sql dump file and
somehow messed it up.  Every Moodle I've ever worked with used full http://site/ links
to anything internal to Moodle.  You say now that a grep shows references for your FQDN but NO http:// in front of them.  (BTW, there are many of them.)

*** Do you have a copy or can you re-acquire ANOTHER sql dump of the **original** DB?

If so, do the SQL dump again.

This time, before we attempt to change the https:// to http:// references in the SQL file, copy the sql dump file to a work copy.   Use the work copy to edit and import.
Example: moodle29.sql is the sql file created by the mysqldump command.
cp moodle29.sql moodle29toedit.sql

We then edit the copy (moodle29toedit.sql) and use it to import into the **new DB** for the site.

Ubuntu does have or one can acquire the text editor 'nano'.  It probably should already be installed but if not one should be able to install.  Quickie to help with that:
http://ubuntu-for-humans.blogspot.com/2009/11/installing-and-using-terminal-editor.html

Why use nano?  You CAN SEE what you are replacing and do replacing one at a time or once one is sure it's finding what it should find, replace all the remaining items.  Sed method just does it.

If you can't re-acquire a SQL dump of the original DB, then there are two options:

1. you'll have to proceed with discovering what you have in the SQL dump you have in order to determine what it is you need to add back or replace/edit.   This is the longer more complicated process.

2. ask Amazon (your hosting provider) IF they have a recent backup of your DB for Moodle.
You might have to restore that one to get a mysqldump to be able to edit it correctly.

'spirit of sharing', Ken

In reply to Ken Task

Re: Going from https to http using 2.8.3

by Bret Miller -
Picture of Particularly helpful Moodlers

I actually think this is going the wrong direction. I don't think the "sed" replace is an issue here. The login link is generated by Moodle. So that leaves us with just a few configuration options that are possibilies:

  1. $CFG->loginhttps = 0; He has it set to 'false' (a string) which if Moodle tests if ($CFG->loginhttps)... is going to return TRUE instead of FALSE. That alone is probably the problem.
  2. $CFG->httproot = 'xxxx'; If this is https://... then it would also explain it. However, the fact that other links like "Courses" in the Navigation block show as http:// would be evidence that this is set correctly.
  3. Cache. If the front page was cached when #1 wasn't set correctly, it could result in the same symptom.
That said, my guess is that fixing #1 will fix it.
Average of ratings: Useful (1)
In reply to Bret Miller

Re: Going from https to http using 2.8.3

by Ken Task -
Picture of Particularly helpful Moodlers

I just tried a curl -I  to your site for both http:// and https:// ... the https:// didn't respond at all, so you probably do NOT have a re-write rule to force ANY/ALL traffic to your site to one or the other ... that was another possible for seeing this 'behavior'.

Ok, if you think that adding that line to config.php is the issue, comment it out using // in front of that line.  The only reason I suggested was knowing some sites may have set use https for login only and you hadn't mentioned that.  In the actual mdl_config table for that variable set to use https on login the value is a '1' (ON).   In the actual mdl_config table for that variable set NOT to use https on login the value is '0' (OFF).   I checked the tables of two sites.    I do NOT know if Moodle will see '0' the same as 'FALSE' or not.

So do we know what the errant sed command did replace?

Here's my latest contribution ...

Docs at:
https://docs.moodle.org/28/en/Moodle_migration
show this:
sed -e 's/oldserver.com/newserver.com/g' oldmysqldump.sql > newmysqldump.sql

which is proper of moving a server from old domain name to new domain.
What you were attempting to do is not only move to another domain but also change
the 'protocol' ... from https:// to http:// thus, got caught in a 'catch 22' due to
usage of sed.

Your posting said this command didn't take:

sed -e 's/https:/oldserver/http/newserver.com/g' oldmysqldump.sql > newmysqldump.sql

So your sed command found stuff but incorrectly.
In your line above: https:/ is missing the second '/'.

Yours: https:/oldserver

should have been

https://oldserver ... note the //.

One of the things I don't like about using 'sed' is the delimiter between the search term and the replace value .... which, according to the docs is a '/'.
But, IF one had the original site at: http://sites/moodle/
one would want to search for http://oldsite/moodle/ and replace with https://newsite/moodle/
note the slashes and the trailing slash in the search/replace might confuse sed as a '/' character is the delimiter between the search text string and the replace with text string.

According to sed manual:

`/REGEXP/'
     This will select any line which matches the regular expression
     REGEXP.  If REGEXP itself includes any `/' characters, each must
     be escaped by a backslash (`\').

Translation:
Sed uses regexp which in itself is somewhat difficult for 'rookies' to use.
(PS, I'll include myself in that category).

Another poster has already spotted the error and relayed the correction.

So your sed command should have used \ in front of every / ... which means the suggested use of sed had to be modified for what you wanted to do ... replace https:// with http://
should have looked like:

https:\/\/oldsite\/

and replaced with

http:\/\/newsite\/

That's why I like nano editor ... no need to 'escape' anything like '/''s.

Now that you've run through sed incorrectly, what do we have in the .sql file?
The same https.

You can reach your site ok with http intiially cause Apache can handle the mis-information contained in the DB but any click to login (even if going directory to the form to login) will result in Moodle attempting to use https:// which isn't configured in your apache at all.  Thus fail.

So, using nano, load up a fresh sql dump of the DB.
After it comes up, do [ctrl][w] for a search of the sql file.
Search for parameter: https:// [ENTER]
Check to see what it finds ... is it finding the URL to your site?
Check for the next instance: [ctrl][w] again - [ENTER]
Did it find the next instance correctly?

If those check out, then do a find and replace.
[CTRL][W]
[CTRL][R]
First dialog box ask for what to find to replace.

and search for 'https://yoursite/'

Why not just https?  You probably have 100's if not 1000's of resource links.
And you want to replace ONLY the links that point back to your own Moodle.

Then replace with 'http://yoursite/'
 
Rather than doing every instance in single fashion, once you are sure it's finding and replacing correctly, use the 'All' switch for the remaining items to replace.
That might be slow and appears to hang ... give it time.  Be patient.
When it finishes, SAVE the .sql file:
[CTRL[[X] you will be prompted to save the changed file.
Keep same file name.
Once that's done, then do the import of that edited sql file into a
**new** database for the moodle.

Change config.php file for the new DB name.

Now try your site.

Also a word of caution about these directions ... I've tried to provide specific
directions but am doing so from memory - at 67 now I find that sometimes the synapses/links have
gone a-stray. ;)

'spirit of sharing', Ken

Average of ratings: Useful (1)
In reply to Bret Miller

Re: Going from https to http using 2.8.3

by Brian Amesse -

Oh my goodness!!!


Thank you!! All of you!!


In the end it was the stupid string... 

$CFG->loginhttps = 'false';

removed it!

My site is back up!!

THANK YOU!!!

In reply to Brian Amesse

Re: Going from https to http using 2.8.3

by Ken Task -
Picture of Particularly helpful Moodlers

Good!  Glad to hear it.  A long the way you've learned some valuable lessons in administering a Moodle.

One take away might be ... use the mdl_config table to discover what variable data entries are valid when the strategy is to add lines to the config.php file (the infamous 'stupid line' ... 'false'). ;)   Have noticed that all the config items that have on/off options use '1' for 'on' and '0' for 'off'.

Another take away might be ... Moodle docs/faqs try to provide ways/means/how-2's, but sometimes cannot be taken literally IF user is not doing 'exactly' the same thing.   In any blog/web site/page that offers how 2 always take the time to investigate usage help when running across something like 'sed'.   A lot depends upon the Operating system AND what am trying to accomplish.   Simple copy from doc paste to command line without really understanding could lead to confusion and error.

'spirit of sharing', Ken


Average of ratings: Useful (1)
In reply to Brian Amesse

Re: Going from https to http using 2.8.3

by Brian Amesse -

Alright so after all this I still have one issue!

One of the courses the teachers made when I click on a link it gives me the message I am attaching screenshots

I am so confused as to how one course works fine and points to the right place but the other does not.

okay so after I did a bit of research there are links and pictures that are broken I attach the working local site vs the actual online site...

The links that don't work point to youtube videos. Why are my pictures and youttube links broken?

Thanks again!!!!

Brian

Attachment Nonworking.png
Attachment working.png
In reply to Brian Amesse

Re: Going from https to http using 2.8.3

by Ken Task -
Picture of Particularly helpful Moodlers

Top screen snap is from non-working production server - the one you migrated to ... bottom screen snap is from dev (localhost) - the one from which you migrated.

Is that right?

Don't all links to YouTube use https://

Links to images, depending upon where the resource (the image file itself) is located could be http:// OR https://

Have you clicked on broken image ... ie, attempt to edit them ... to see what the URL to the images have?

No one on these forums can tell by looking at a screen snap of a broken image link.

Now how did that happen?   Dunno but willing to guess operator error ... when attempting to do global search and replaces.   How did that happen?  Dunno ... can't see command line history of the sed commands used and certain cannot see the search/replace parameters of a vim editor session a week old or so.

Maybe the easiest 'fix' is to take a backup of that course on dev and restore it to the production server.   Images/Links to YouTube won't have to undergo any change of http:// https:// then.

If that works, then no reason to address the issue of editing the course that has errors in it, just remove the course.

'spirit of sharing', Ken

In reply to Ken Task

Re: Going from https to http using 2.8.3

by Brian Amesse -

Thank you for your words as usual Ken.

I restored the course from a backup and it works wonderfully!


Thanks again!


Brian

In reply to Brian Amesse

Re: Going from https to http using 2.8.3

by Ken Task -
Picture of Particularly helpful Moodlers

Great!  Glad to hear it.   Nice to figure out more than one way to 'skin a cat' ... no offense to cat lovers out there! smile

'spirit of sharing', Ken

In reply to Brian Amesse

Re: Going from https to http using 2.8.3

by Brian Amesse -

Also some more fun...

When I try to edit the course in question this is what I get (see attachment)

Attachment cant edit course.png
In reply to Brian Amesse

Re: Going from https to http using 2.8.3

by Brian Amesse -

Maybe one last thing... maybe not but I am very good with terminal and checked my sqldb.sql with vim and found no data pointing to the old URL... but in the course it clearly seems to be wanting that URL...

I tried the search and replace tool but I assume it did what we did with sed so obviously it's not fixing anything.

Hoping for some help in all this confusion smile