Setting up MediaWiki with Nginx on Ubuntu 24.04 allows you to run a powerful, customizable wiki platform optimized for performance and security. This guide walks you through installing and configuring MediaWiki on a fresh Ubuntu 24.04 server, ensuring you have a robust environment for collaborative documentation or knowledge sharing. Before starting, ensure your server has a clean Ubuntu 24.04 installation, a static IP address, and root or sudo privileges to install and configure software.
What You’ll Need
- Ubuntu 24.04 server (freshly installed and updated)
- Root or sudo access
- Domain name pointing to your server’s IP (optional but recommended)
- Basic knowledge of Linux command line
- Access to a terminal or SSH client
Step-by-Step
- Update your system:
Open your terminal and run:sudo apt update && sudo apt upgrade -y
This ensures all packages are current and security patches are applied.
- Install necessary packages:
Install Nginx, PHP, MariaDB (MySQL), and other required PHP extensions:sudo apt install nginx php-fpm php-mysql php-xml php-mbstring php-intl php-gd php-zip mariadb-server unzip wget -y
- Secure MariaDB:
Run the security script:sudo mysql_secure_installation
Follow prompts to set root password, remove anonymous users, disallow root login remotely, and remove test database.
- Create a database and user for MediaWiki:
Log into MariaDB:sudo mariadb
Then execute:
CREATE DATABASE mediawiki_db DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE USER 'mediawikiuser'@'localhost' IDENTIFIED BY 'your_password_here'; GRANT ALL PRIVILEGES ON mediawiki_db.* TO 'mediawikiuser'@'localhost'; FLUSH PRIVILEGES; EXIT;
- Download and extract MediaWiki:
Navigate to your web root (e.g., /var/www):cd /var/www
Download MediaWiki latest stable release:
wget https://releases.wikimedia.org/mediawiki/1.39/mediawiki-1.39.4.tar.gz
Extract it:
sudo tar -xzf mediawiki-1.39.4.tar.gz
Rename and set permissions:
sudo mv mediawiki-1.39.4 mediawiki sudo chown -R www-data:www-data /var/www/mediawiki
- Configure PHP for MediaWiki:
Edit PHP-FPM pool:sudo nano /etc/php/8.2/fpm/pool.d/www.conf
Ensure user and group are www-data, then restart PHP-FPM:
sudo systemctl restart php8.2-fpm
- Configure Nginx server block:
Create a new config file:sudo nano /etc/nginx/sites-available/mediawiki
Add the following configuration:
server { listen 80; server_name your_domain_or_IP; root /var/www/mediawiki; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php8.2-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~ /\.ht { deny all; } }Enable the site and restart Nginx:
sudo ln -s /etc/nginx/sites-available/mediawiki /etc/nginx/sites-enabled/ sudo nginx -t sudo systemctl restart nginx
- Complete MediaWiki installation via web interface:
Open your browser and navigate to http://your_domain_or_IP.
Follow the on-screen instructions to connect to your database, configure admin account, and finalize setup.
Once completed, delete the install script for security:
sudo rm /var/www/mediawiki/mw-config/initialise.php
Common Mistakes
- Not updating the system packages before starting, leading to compatibility issues.
- Forgetting to set correct permissions on the MediaWiki directory, causing web server access errors.
- Using incorrect database credentials during setup, which prevents MediaWiki from connecting to the database.
- Failing to secure MariaDB with mysql_secure_installation, leaving your database vulnerable.
- Misconfiguring Nginx server block, resulting in 404 errors or misrouted requests.
- Not deleting the install.php script after setup, which can pose security risks.
Tips
- Use a domain name with SSL certificates (via Let’s Encrypt) for secure access.
- Regularly update MediaWiki and server packages for security patches.
- Configure backups for your database and MediaWiki files regularly.
- Enable caching and optimize PHP settings for better performance.
- Use strong passwords for database and admin accounts.
- Configure proper file permissions to prevent unauthorized access.
Troubleshooting
If you encounter issues during setup or after installation, here are some common troubleshooting steps:
- Web page not loading or showing 404 errors: Check your Nginx configuration syntax with
sudo nginx -tand ensure the site is enabled. - Database connection errors: Verify database credentials in the setup and ensure MariaDB service is running (
sudo systemctl status mariadb). - Permissions issues: Ensure web server user (www-data) has correct permissions on /var/www/mediawiki.
- PHP errors or 500 Internal Server Error: Check PHP-FPM logs at
/var/log/php8.2-fpm.logand Nginx error logs at/var/log/nginx/error.log. - SSL issues if using HTTPS: Confirm SSL certificates are correctly installed and configured in Nginx.
Frequently Asked Questions
1. Can I install MediaWiki without a domain name?
Yes, you can access MediaWiki via your server’s IP address, but using a domain name with SSL is recommended for security and ease of access.
2. How do I enable HTTPS for my MediaWiki site?
Use Certbot with Let’s Encrypt to obtain free SSL certificates and configure your Nginx server block to use SSL.
3. Is it necessary to install a caching system?
While not mandatory, enabling caching (like Redis or Memcached) can significantly improve MediaWiki performance, especially on high-traffic sites.
4. How often should I update MediaWiki?
Regularly check for updates and apply security patches promptly to keep your wiki secure and functional.
5. Can I run MediaWiki in a Docker container instead of directly on Ubuntu?
Yes, Docker offers an alternative way to deploy MediaWiki with isolated environments, but this guide focuses on direct installation for clarity.
6. What should I do if MediaWiki is not displaying correctly after setup?
Double-check your permissions, verify your Nginx configuration, ensure PHP-FPM is running, and review error logs for clues.
Following these steps will help you successfully install and run MediaWiki with Nginx on Ubuntu 24.04, providing a reliable and scalable wiki platform tailored to your needs.
Related
- How to Hide the App & Browser Control Section in Windows 11 Security
- How to Hide the Apple Watch Icon on an iPhone 6 Easily
- How to Hide the Bookmark Bar in Google Chrome Easily