Introduction
After the initial installation, the MediaWiki platform does not have a built-in application administration and configuration section. If you are self-hosting a MediaWiki instance, or changing web hosting companies or domains, then occasionally you may need to adjust the MediaWiki URL for the installation in order to keep the application functioning properly.
How to Change the MediaWiki URL
The MediaWiki URL setting is located in the application configuration file. It determines what URL that the pages will point the browser to when you click a link or button within the application.
Edit the LocalSettings.php File
The LocalSettings.php
file is a text file that is located in the root directory of your MediaWiki installation. We can use a terminal program to SSH into your server in order to access that file.
Once you are in the root directory of your MediaWiki installation you can use your favorite text editor to edit the file. I prefer to use the nano text editor by running the following command within the root directory.
nano LocalSettings.php
Once the nano editor opens the file, you will see a the contents of the LocalSettings.php
file. Scroll down a few lines until you see the $wgServer
line, your terminal should look similar to the image below:
The section you are looking for states the following:
## The protocol and server name to use in fully qualified URLs $wgServer = "https://yourdomain.com";
In order to change the Mediawiki URL of your installation, just replace https://yourdomain.com
with the domain that you would like to use in its place.
That’s it!
After you finish editing the file, type ctrl+X
to close the nano editor. Then, type y
to indicate that you would like to save the file. Next, restart your instance of MediaWiki.
Once MediaWiki comes back online you will be able to test your changes. It is important to clear your browser cache before you visit your installation. Once you clear your browser cache, visit your MediaWiki installation using the new URL. Then, go to the user login page and login. If you were successful, you will be able to login to your account without any issues.
How to change the path of your MediaWiki Installation
If you move the location of the MediaWiki script files from the current root directory to a different directory on your server, for example a directory named /wiki
you will need to make one other minor adjustment to the LocalSettings.php
file within your MediaWiki directory.
Edit the LocalSettings.php File
In the LocalSettings.php file you will need to find the following section:
## The URL base path to the directory containing the wiki; ## defaults for all runtime URL paths are based off of this. ## For more information on customizing the URLs ## (like /w/index.php/Page_title to /wiki/Page_title) please see: ## http://www.mediawiki.org/wiki/Manual:Short_URL $wgScriptPath = "/wiki";
In order to change the installation path of MediaWiki, edit the $wgScriptPath
to your new location. In the example above, you will see the patch is set to /wiki
.
That’s it!
After you finish editing the file, type ctrl+X
to close the nano editor. Then, type y
to indicate that you would like to save the file. Next, restart your instance of MediaWiki.
Once MediaWiki comes back online you can test out your changes. It is important to clear your browser cache before you visit your installation of MediaWiki.
Conclusion
In this article you learned how to change your MediaWiki URL and MediaWiki Script Path. As you can see, MediaWiki makes it easy to make adjustments to your installation if your domain or server ever changes. If you have any questions, please leave a comment below.
The post, How to change your MediaWiki URL, first appeared on Codeopolis.