Changing moodle URL - lost all pictures and files

Changing moodle URL - lost all pictures and files

by Graeme Forrester -
Number of replies: 24

I recently changed my moodle install to another server and hence a different URL

eg www.domain.com/moodle to moodle.domain.com

All of the pictures and files that have been added using the wysiwyg editor still refer to www.domain.com/moodle even though I have changed the settings in the config.php file and the admin pages to reflect the new server settings.

I don't want to have to upload all of the files and change URLs for each one.

Is there an easy way to accomplish this?

Average of ratings: -
In reply to Graeme Forrester

Re: Changing moodle URL - lost all pictures and files

by John Isner -
There are a number of ways to repair broken links after a move. They all involve making changes directly in your database. See this discussion: http://moodle.org/mod/forum/discuss.php?d=57477 Toward the end of the discussion, you'll see a link to a script called replace.php, together with some very good advice: MAKE A BACKUP FIRST!!
----
I have never understood why, when you insert an image from your course files in the HTML editor, the editor uses an absolute URL () rather than a relative one (../file.php/10/foo.gif). The relative one would be portable to a new server. Anybody know why it's done this way?
In reply to John Isner

Re: Changing moodle URL - lost all pictures and files

by Graeme Forrester -
Thanks - that worked perfectly. I used the sql dump and search and replace.
In reply to Graeme Forrester

Re: Changing moodle URL - lost all pictures and files

by John Isner -
Great! I'm curious: did you use the replace.php script, or do a manual search-and-replace? I have never used the script myself, and I was curious about it.
In reply to John Isner

Re: Changing moodle URL - lost all pictures and files

by Graeme Forrester -

I took the site off line.

Backed up first.

Did a sql dump

In wordpad I used find and replace (took a couple of minutes).

Dropped the  moodle DB and then recreate with the altered sql file.

All up about 15 minutes - completely painless and all links repaired.

Average of ratings: Useful (1)
In reply to Graeme Forrester

Re: Changing moodle URL - lost all pictures and files

by D. S. -

Hi all,

I am very new to Moodle and am trying to develop a course. I have set up my course on local machine using XP.  Now all of my links are http://127.0.0.1/whatever

 This is fine for developing but I tried accessing my course through another computer and, of course, all of the links are broken.  I have read through this discussion and the one referred to above but I am having trouble following some of it.

Could you explain in more detail how to perform an sql dump.  I get the idea but I have no idea how to start it. Is this another program I have to download? Do I open the command interface in XP?  What about all of the arguements to use if I do use the command interface?  Is there a better way for a newbie? 

I tried using http://127.0.0.1/admin/replace.php which was referred to but even though I got a long list of replacements ("yadda yadda yadda ... Success!")every link I looked at was still broken.

I would also like to reiterate the question, why does moodle not use ../linkgoes here.php instead of http://whatever.org/linkgoeshere.php  so that it would be more easily portable to a new server? Could there not be an administrator option like 'Port to new server'?

Thanks in advance for somebody taking their time.

Doug

In reply to D. S.

Re: Changing moodle URL - lost all pictures and files

by D. S. -

Hi,

I'm answering my own question here.  Using http://olddomain.org/admin/replace.php to replace "olddomain.org" with "newdomain.org" didn't work but then after I edit config.php using notepad to relflect the newdomain, everything worked out.  (Which I think is actually what was recommended above)

Thanks,

Doug

P.S. Hey Doug next time RTFM.smile

In reply to D. S.

Re: Changing moodle URL - lost all pictures and files

by John Isner -
I'm glad to hear replace.php worked for you. I will use it next time I'm in the same situation (I have only done it manually).

I checked the HTML Editor forum for an answer to the question "why are absolute links used instead of relative ones?" The answer is found in this discussion.

Average of ratings: Useful (1)
In reply to Graeme Forrester

Re: Changing moodle URL - lost all pictures and files

by A. H. -
Hi Graeme,

How did you do sql dump?Am afraid i dont know whats that, where to go and do it.Can you help plz by specifying how did you do this step?

thank you,
amer
In reply to A. H.

Re: Changing moodle URL - lost all pictures and files

by John Isner -
Hi Amer,
Please read the rest of the discussion, specifically the two posts by Douglas Sirkka. You will see that it is unnecessary to dump and edit the sql. It is much easier and safer to use the replace.php script
In reply to John Isner

Re: Changing moodle URL - lost all pictures and files

by A. H. -
Dear John,

Notice that the replace.php does NOT change all links. Forexample, links for picture wont be replaced by the new link. I tested replace.php and found that it will leave links unaltered here and there.

regards,
amer
In reply to A. H.

Re: Changing moodle URL - lost all pictures and files

by Graeme Forrester -

Sorry I only caught this post now.

Do you use phpmyadmin or mysql administrator? phpmyadmin is the easiest.

If phpmyadmin - go to the moodle db and export.

Select all tables in the select all option.

Select as file and it will dump a moodle.sql file (you just need to select the location).

Right click the file and go to open with wordpad (better than notepad for this) and is available on any windows desktop or server.

In the Find what box add http://www.moodleold.com

In the replace box add http://www.moodlenew.com

Depends on your domain name.

When done save it.

Then dump your old moodle database.

Create a new moodle database using phpmyadmin with the same name.

Select upload and find the newly changed sql and upload it.

You only need to alter your moodle config.php file and then you are done.

big grin Happy days - job is done.

In reply to Graeme Forrester

Re: Changing moodle URL - lost all pictures and files

by A. H. -
Thank you Graeme!
Will follow the steps but at least things got way clearer to me.Am using phpmyadmin but i was searchin for dump command for mysql coz didnt know thats how its done using phpmyadmin. I'll try it.

regards,
amer
In reply to A. H.

Re: Changing moodle URL - lost all pictures and files

by John Isner -
Amer,
Are ALL image links unchanged, or just some of them? If just some of them are unchanged, are those links coded differently from the ones that get changed? If they look the same, there must be a bug in replace.php and you should report a bug in the tracker.
In reply to John Isner

Re: Changing moodle URL - lost all pictures and files

by Graeme Forrester -

Hi John,

If you use the metod that I described then all images are changed - images and docs. I saw in a post in the linked forum that I used to do this that replace.php doesn't do this properly and it was a known issue.

It does depend on which method you are most comfortable with.

In reply to John Isner

Re: Changing moodle URL - lost all pictures and files

by angeline foon -

Hi,

I changed my moodle URL using the replace.php, all the link of the resources works fine after that. But the logos,icons & images of the whole site are gone, I have no idea how to resolve this issue.

Anyone can help?

Attachment screenshot.jpg
In reply to angeline foon

Migrating from Windows 2003 to Linux

by Steve Squires -

Hello,

Our school is trying to move moodle from a windows 2003 server, using an IP address, to a Debian Linux server, using a Domain Name and I would appreciate some help.

The problem is that: When the "new" moodle is run it retains some of the links to the "old" website using the IP address instead of the new Domain Name.

Attempted:

  • It does not seem to matter whether I use PHPMyAdmin or Mysqldump to extract the database and then search and replace using various text editors (allways carefull to output in UTf-8) and then import (into a new database). 
  • Replace.php reported sucess but in fact did not work. Changes to config.php, were also made and have had no effect.

Has anyone moved a site from an IP address to a Domain Name?

Thanks in anticipation.

In reply to Steve Squires

Re: Migrating from Windows 2003 to Linux

by Dale Davies -
Yes several times, the procedure I generally follow is to...

  • Ensure domain name resolves correctly to new webspace/server.
  • Export the database from old server using MYSQLdump.
  • Perform a search and replace in the SQL file.
  • Change settings in config.php to reflect new domain name.
  • Check any custom themes and plugins.
  • Upload files to new web space.
  • Import edited SQL dump file into database on new server.
  • Open Moodle at new location and check thoroughly.
So far this has never failed me.

However, you may find when you search and replace in the SQL dump file that you may need to search for several different strings. For example, "http://192.168.220.130" and "192.168.220.130".

You'd think just searching for the latter would catch everything, but I have found that sometimes (depending on what editor you're using) you may have to search and replace several permutations of the IP address string to catch everything.
In reply to Dale Davies

Re: Migrating from Windows 2003 to Linux

by Steve Squires -

Thanks Dale,

When replacing just the IP, as in your latter example, should the replacement be:

  1. http://www.mydomain.ac.uk, or
  2. www.mydomain.ac.uk

In reply to Steve Squires

Re: Migrating from Windows 2003 to Linux

by Dale Davies -
I would first start by trying number 2, which you would think should catch all instances. However, it's worth trying everything you can think of just in case!
In reply to Dale Davies

Re: Migrating from Windows 2003 to Linux

by Steve Squires -

Well, the migration seems to have gone well; inasmuch as the links are pointing to the new Domain Name and I can navigate around the site - thank you.  I exported the MySQL database from the Windows machine, imported it into the Linux installation and then ran replace.php to fix the links. 

But, when I check the plugins I see, for example, "Block mrcutejr is not compatible with the current version of Moodle and needs to be updated by a programmer".

I checked the versions of Moodle and they are the same.

How do I update mrcutejr? (I did not install the original).

In reply to Graeme Forrester

Re: Changing moodle URL

by Colin Wheelhouse -

I would like to change the directory/folder in which my moodle is installed. Currently the installation is in the root directory of my server i.e. mydomain.com I would like to move the installation to mydomain.com/moodle but think I have to do some editing of config.php and lib.php files which I have no idea of how to do or even if that's all. I created a moodle folder inside my root folder and copied all files into it however I got messages about config.php and lib.php errors when I tried to open mydomain.com/moodle.

The reason for this is so that my existing domain www.mydomain.com will now serve as a website which links to the login of my moodle.

Can anybody give me a walkthrough of how to do this if possible?

Cheers

Wheelie

In reply to Colin Wheelhouse

Re: Changing moodle URL

by Paulo Roberto Santos -

Hi, all.

 

i'm transferring to new url, but same webserver and data base.

I'm using Moodle 2.0. Any diferent about how transfer?

Because i cant found replace.php file.

Best regards.

Paulo