MediaWiki Logo

Moving MediaWiki to a new server

Spread the love

MediaWiki Logo

 

The process of moving MediaWiki to a new server is essentially the process of backing up and restoring backups so its a good process to be done now and again to test your backups and documentation are fully functional.

1. Backup MariaDB

The MariaDB will be backed up using the mysql tool to backup the database contents into a .sql file by running the following commands on the old wiki server:

mysqldump -u wikiuser -pwikipassword wikidb -c > /backups/mysql/wikidb.sql

Obviously the details will need to be changed to the correct details for your db. You will also have to create the /backups and /mysql folders if you want to save the dump there.

If the file is quite large then compact it by running the following command from inside /backups/mysql:

gzip wikidb.sql

My db is tiny so I didn’t bother with this step for now.

2. Backup the wiki’s media files

Now that the database is backed up, the next step is to back up the media files. Other than the database the only other folder that needs backing up is the /var/www/html/wiki/images/ folder. This can easily be done by running:

cd /var/www/html/wiki/
tar czvf /backups/www/images.tgz images/

This compacts and moves the images folder to /backups/www/images.tgz ready to copy off.

2a. Backup LocalSettings.php

This is not in any of the documentation that I have seen online but you need to copy the localSettings.php to the new server if you have made any custom changes like Custom logo of custom favicons (which I have).

To back up the file run the following command:

cp /var/www/html/wiki/LocalSettings.php /backups/www/

Now copy the /backups folder from the old server to the new server.

3. Restoring the database

On the new server go to the folder with the database backup in it (/backups/mysql in my case) and run the following command to unzip the file:

gunzip -c wikidb.sql.gz 

We then import the sql file into our database with:

mysql -u wikiuser -p wikidb < /backups/mysql/wikidb.sql

The database is now in the same state as the old server.

4. Restoring the media files

On the new server go to the folder containing the backup from step 2. Extract the file by running:

sudo tar xzvf images.tgz

Next we need to copy the contents of the folder to the web directory:

sudo cp -r /backups/www/images /var/www/html/wiki/

We then have to change the permissions on the /var/www/html/wiki/images folder by running:

sudo chown -R www-data-www-data /var/www/html/wiki/images/

5. Restoring LocalSettings.php

Before copying the LocalSettings.php from the old server to the new server, on the new server rename the current LocalSettings.php just in case you need to revert the process if it all goes wrong by running:

mv /var/www/html/wiki/LocalSettings.php /var/www/html/wiki/LocalSettings.php

Then copy the LocalSettings.php from the old server to the new server

cp /backups/www/LocalSettings.php /var/www/html/wiki/

That is the entire process of moving MediaWiki to a new server. You will now have 2 identical MediaWiki servers.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top