A Step-by-Step Guide to Installing MediaWiki on an Nginx Server in Ubuntu Linux

A Step-by-Step Guide to Installing MediaWiki on an Nginx Server in Ubuntu Linux

Hey there, tech enthusiasts! Today, we’re embarking on an exciting journey into the world of wikis. We’ll be setting up our very own MediaWiki instance on an Nginx server running Ubuntu Linux. It might sound daunting, but don’t worry; we’ll break it down into simple, easy-to-follow steps. By the end of this guide, you’ll have a fully functional wiki ready to store and share knowledge. Let’s get started!

Why MediaWiki and Nginx?

Before we dive into the installation process, let’s quickly understand why we’re choosing MediaWiki and Nginx. MediaWiki is the powerhouse behind Wikipedia and countless other wikis. It’s open-source, incredibly flexible, and packed with features perfect for collaborative knowledge management. Nginx, on the other hand, is a high-performance web server known for its speed and efficiency. Together, they form a fantastic duo for hosting your wiki.

Prerequisites

Before we start, make sure you have the following:

  • A fresh Ubuntu Linux server (version 20.04 or later is recommended)
  • Root access to your server
  • A basic understanding of the Linux command line
  • A domain name (optional, but recommended for easier access)

Step 1: Update Your System

The first step is to ensure your Ubuntu server is up-to-date. Open your terminal and run the following commands:

sudo apt update
sudo apt upgrade

This will fetch the latest package lists and upgrade any outdated software on your system.

Step 2: Install Nginx

Next, let’s install Nginx. It’s available in the default Ubuntu repositories, so installation is a breeze:

sudo apt install nginx

Once installed, Nginx should start automatically. You can verify it’s running by visiting your server’s IP address in a web browser. You should see the default Nginx welcome page.

Step 3: Install PHP and Required Extensions

MediaWiki relies on PHP to run. We also need to install some specific PHP extensions that MediaWiki requires. Let’s install them all at once:

sudo apt install php php-fpm php-mysql php-xml php-intl php-mbstring php-gd php-curl

This command installs PHP, the FastCGI Process Manager (FPM) for handling PHP requests, and the necessary extensions for interacting with databases, handling XML, internationalization, multibyte strings, image processing, and making HTTP requests.

Step 4: Install MariaDB (or MySQL)

MediaWiki needs a database to store its data. We’ll use MariaDB, a popular open-source database server that’s fully compatible with MySQL. Let’s install it:

sudo apt install mariadb-server

After installation, it’s a good practice to secure your MariaDB installation:

sudo mysql_secure_installation

Follow the prompts to set a root password, remove anonymous users, disable remote root login, and remove the test database.

Step 5: Create a Database for MediaWiki

Now, let’s create a dedicated database for MediaWiki. Log in to the MariaDB console:

sudo mysql -u root -p

Enter your root password when prompted. Once inside the console, execute the following SQL commands:

CREATE DATABASE mediawiki CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'mediawikiuser'@'localhost' IDENTIFIED BY 'your_strong_password';
GRANT ALL PRIVILEGES ON mediawiki.* TO 'mediawikiuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Replace your_strong_password with an actual strong password. These commands create a database named mediawiki, a user named mediawikiuser, and grant that user full access to the mediawiki database.

Step 6: Download and Extract MediaWiki

Head over to the MediaWiki website and download the latest stable release. At the time of writing, it’s version 1.39.2. You can download it directly to your server using wget:

wget https://releases.wikimedia.org/mediawiki/1.39/mediawiki-1.39.2.tar.gz

Once downloaded, extract the archive:

tar -xzvf mediawiki-1.39.2.tar.gz

This will create a directory named mediawiki-1.39.2. Let’s move it to a more suitable location and rename it for convenience:

sudo mv mediawiki-1.39.2 /var/www/html/mediawiki

Step 7: Configure Nginx

We need to tell Nginx how to handle requests for our MediaWiki instance. Create a new Nginx configuration file:

sudo nano /etc/nginx/sites-available/mediawiki

Paste the following configuration into the file:

server {
    listen 80;
    server_name your_domain_or_IP;
    root /var/www/html/mediawiki;
    index index.php;

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php-fpm.sock;   
    }

    location ~ /\.ht {
        deny all;
    }
}

Replace your_domain_or_IP with your actual domain name or server IP address. Save the file and exit the editor.

Now, create a symbolic link to enable this configuration:

sudo ln -s /etc/nginx/sites-available/mediawiki /etc/nginx/sites-enabled/

Finally, test your Nginx configuration and reload it if there are no errors:

sudo nginx -t
sudo systemctl reload nginx

Step 8: Set File Permissions

We need to adjust file permissions to ensure MediaWiki can write to certain directories.

sudo chown -R www-data:www-data /var/www/html/mediawiki
sudo chmod -R 755 /var/www/html/mediawiki

These commands change the ownership of the mediawiki directory to the www-data user and group, and set permissions to allow read and execute access for everyone, and write access for the owner.

Step 9: Run the MediaWiki Installation Script

Now comes the exciting part—running the MediaWiki installation script! Open your web browser and navigate to http://your_domain_or_IP/. You should see the MediaWiki installation wizard.

Follow the on-screen instructions. You’ll be asked to:

  • Select your language: Choose your preferred language for the wiki interface.
  • Check environment: The wizard will check if your server meets all the requirements. If everything is green, you’re good to go!
  • Connect to the database: Enter the database name (mediawiki), username (mediawikiuser), and password you created earlier.
  • Set up the wiki: Provide a name for your wiki, create an admin account, and configure other settings like email notifications.
  • Install: Click the “Install” button, and MediaWiki will set up the database tables and configuration files.
  • Download LocalSettings.php: The final step is to download the LocalSettings.php file and place it in the root of your MediaWiki installation directory (/var/www/html/mediawiki).

Step 10: Configure MediaWiki (Optional)

Once the installation is complete, you can log in to your wiki using the admin account you created. From there, you can explore the various settings and customize your wiki to your liking. Here are a few things you might want to consider:

  • Skins: MediaWiki offers a variety of skins to change the look and feel of your wiki.
  • Extensions: Extend the functionality of your wiki with countless extensions available.
  • User rights: Manage user permissions and access levels.
  • Logo: Upload a custom logo for your wiki.

SEO Optimization for Your MediaWiki

Now that your MediaWiki is up and running let’s explore how to make it more search engine friendly.

1. Enable SEO-Friendly URLs

By default, MediaWiki URLs can be a bit messy. Let’s clean them up to make them more readable and appealing to search engines.

  • Open your LocalSettings.php file.
  • Add the following lines:
$wgUsePathInfo = true;
$wgArticlePath = "/wiki/$1";
  • Save the file.

Now, your article URLs will look like this: http://your_domain/wiki/Article_Title instead of http://your_domain/index.php/Article_Title.

2. Create a Sitemap

A sitemap helps search engines discover and index your wiki’s content more efficiently.

  • Install the Sitemap extension. You can do this through the MediaWiki interface by going to Special:Version and clicking on the “Manage extensions” link.
  • Once installed, go to Special:Sitemap to generate your sitemap.
  • Submit your sitemap to search engines like Google and Bing through their webmaster tools.

3. Optimize Page Titles and Descriptions

  • Each page on your wiki should have a clear and descriptive title that accurately reflects its content.
  • Use the <meta> tag to add a concise and informative description to each page. This description will often appear in search engine results.

4. Use Internal Linking

  • Link relevant pages within your wiki to each other. This helps search engines understand the structure of your wiki and the relationships between different pages.
  • Use descriptive anchor text for your internal links.

5. Encourage High-Quality Content

  • The most important factor for SEO is high-quality, informative content. Encourage your users to create and contribute valuable content to your wiki.
  • Regularly update and expand your wiki’s content to keep it fresh and relevant.

Congratulations! You’ve successfully installed MediaWiki on an Nginx server in Ubuntu Linux. You now have a powerful platform for creating and managing your own wiki. Remember to keep your MediaWiki and its extensions up-to-date, and don’t hesitate to explore the vast world of customization options available. Happy wiki-ing!

Disclaimer: While every effort has been made to ensure the accuracy of this guide, the rapidly evolving nature of technology means that some steps or commands might become outdated. If you encounter any inaccuracies or issues, please report them so we can correct them promptly. Your feedback is invaluable in helping us maintain the quality of this guide.

If you have any further questions, or if you get stuck at any point feel free to leave a comment below!

Leave a Reply

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


Translate »