Wednesday, August 31, 2011

Migrating MediaWiki from one server to another

I had a frustrating time migrating an old MediaWiki from one server to another. The old MediaWiki was quite old (1.6.3) and it was working fine, so I had never got around updating it. In the meantime, the world had changed: hurricanes came and went, comets flew over and MediaWiki software also got upgraded. But I was blissfully unaware of all that; till I had to finally shut down the server (couldn't afford it anymore ... possibly the comet had something to do with it) but I also needed to keep the Wiki alive.

I finally decided to shift it to a Dreamhost server that I had. And therein the problems started. I then tried it on another server, and the problems were the same. I could see the title of pages, but not the contents. It kept saying that "There is currently no text in this page, you can search for this page in other pages or edit this page"

Though, at the same time, I could see the titles... Hmmm

Finally I got the solution and here it is:

Firstly, export all the contents of the old website by running the maintenance/dumpBackup.php script from the shell of the old server. Give the --full command line parameter too ... thus

php maintenance/dumpBackup.php --full >wikiexportedcontents.xml

Note that this exports only the mediawiki contents and not users. You will have to re-create your users later separately. Sorry about that. But that may be not much of a problem.

FTP that XML file to your new site.

Use a favorite MySQL tool (PhpMyAdmin is available in most servers) and dump the SQL of two specific tables in your old Wiki. One is called "wiki_images" and the other is called "wiki_image_links" (This is assuming that the prefix that you had used for the tables was "wiki_" If not, substitute whatever else you may have used) FTP these SQL dumps also into your new server.

Now FTP all the files of the old site to the new site and place it in the correct web-path you plan to use. Make sure the "config" folder is R/W. Rename "LocalSettings.php" to something else (you may need some details from it later)

Create an empty database and a database user to work on that database. Your favorite CPanel (or whatever else poison you use to manage your website) should have PhPMyAdmin (or some other such tool) to make the database, and the user and set privileges for the user.

Now, point the DNS to the new site.

Go to your browser and ask it to load your new site. Since MediaWiki does not have the LocalSettings.php file (remember you renamed it), it will assume that you need to create a new Wiki and will ask you to do the initial setup. Follow all the steps and create a brand new Wiki with empty contents, excepting for the default front page. If the "config" folder was not made writable, the setup would fail.

Now login into the new, squeaky clean Mediawiki website in the new site as the SysOp ... and promptly delete the old front default page (Main_page) that was created. Now you truly have no pages whatsoever in your new wiki at the new site.

Go to the shell of the new server. Go to the maintenance section of the new MediaWiki site. Give the following command:

php importDump.php wikiexportedcontents.xml

(The above command assumes that you had placed the xml file "wikiexportedcontents.xml" into the same folder)

Viola, the old contents would now appear in the new site... but the images would not be seen because those tables are not recreated (at least in Mediawiki version 1.6.3 that was the problem. Not sure whether the later XML versions did a better job) Now load the MySQL manager (PhpMyAdmin usually) of your new site, and empty the contents of the "wiki_images" and "wiki_image_links" tables. Into those tables, import the two SQL dumps that you had FTP'd to your new site

Play around with your new MediaWiki. Edit a page or two , and somewhere (when the cache gets cleaned up, possibly) you would find that the images also turn up on your new site

Now painfully recreate your users (!) But wait a minute... possibly you could export an SQL dump of the users table and use that in your new site. Haven't tried that

All the best



No comments:

Post a Comment