Command line interface
Command Line Interface (CLI) for MediaWiki Administrators
The Command Line Interface (CLI) is a powerful tool for managing a MediaWiki installation, particularly for server administrators. While the web-based interface provides many administrative functions, the CLI allows for automation, scripting, and access to features not available through the web interface. This article will cover the basics of using the CLI with MediaWiki 1.40, focusing on common tasks and providing examples.
Accessing the CLI
The primary method for accessing the MediaWiki CLI is through SSH (Secure Shell) access to the server hosting your MediaWiki installation. You'll need a user account with appropriate permissions. Once logged in via SSH, you'll typically navigate to the directory containing `maintenance/`, which is located within your MediaWiki installation directory.
For example, if your MediaWiki installation is in `/var/www/mediawiki`, you would use the following command:
```bash cd /var/www/mediawiki/maintenance ```
From this directory, you can execute various maintenance scripts. Ensure that the web server user (e.g., `www-data`, `apache`) has appropriate read/write permissions to the `maintenance/` directory and the `config/` directory containing `LocalSettings.php`. Incorrect permissions are a common source of errors. See Manual:Configuration settings for more information on `LocalSettings.php`.
Common CLI Scripts
MediaWiki provides a range of maintenance scripts. Here's a breakdown of some of the most frequently used ones:
- `rebuildindex.php`: Rebuilds the search index. Crucial after significant content changes or updates.
- `update.php`: Performs database schema updates. Run this *after* upgrading MediaWiki core files. See Manual:Upgrading MediaWiki for details.
- `runCron.php`: Executes scheduled tasks (cron jobs) manually. Useful for testing or when cron is not functioning correctly. See Manual:Cron jobs for information on automated cron jobs.
- `archive.php`: Archives revisions of pages. Essential for maintaining database performance.
- `refreshLinks.php`: Updates the `mw_links` table, used for inter-wiki links and broken link detection.
- `purgeDataCache.php`: Clears the data cache. Useful if you suspect caching issues. See Manual:Caching for general information on caching.
Example Usage and Parameters
Let's explore some examples with commonly used parameters. Remember to execute these from the `maintenance/` directory.
Rebuilding the Search Index
Rebuilding the search index can take a significant amount of time, especially on large wikis.
```bash php rebuildindex.php ```
To rebuild the index for a specific namespace, use the `--namespace` parameter:
```bash php rebuildindex.php --namespace 0 # Rebuild for the main namespace ```
For a verbose output, which can be helpful for debugging, use the `--verbose` parameter:
```bash php rebuildindex.php --verbose ```
Running Database Updates
- Always* run `update.php` after upgrading MediaWiki.
```bash php update.php ```
If you encounter errors, ensure your `LocalSettings.php` is correctly configured and that the database user has the necessary permissions. Consult Manual:Database setup for database configuration details.
Purging the Data Cache
```bash php purgeDataCache.php ```
This clears the object cache. If you're using a more advanced caching system like Memcached, you may need to clear that cache separately. See Manual:Configuring Memcached for details.
Key Technical Specifications
Here's a table summarizing key technical details related to CLI usage:
Parameter | Description | Example |
---|---|---|
`--help` | Displays help information for the script. | `php rebuildindex.php --help` |
`--verbose` | Provides detailed output during execution. | `php update.php --verbose` |
`--namespace` | Specifies a namespace to operate on (0 for main). | `php rebuildindex.php --namespace 6` |
`--user` | Specifies a user to run the script as. | `php runCron.php --user=sysop` |
Troubleshooting Common Errors
- **"PHP is not recognized as an internal or external command..."**: This means the PHP executable is not in your system's PATH. You may need to specify the full path to the PHP executable (e.g., `/usr/bin/php`).
- **"Permission denied"**: Ensure the user you are logged in as has the necessary permissions to read and write to the MediaWiki installation directory and database.
- **"Database connection failed"**: Double-check your database connection details in `LocalSettings.php`. See Manual:Database for troubleshooting tips.
- **"Out of memory"**: Large operations like rebuilding the index can consume significant memory. Increase the PHP memory limit in your `php.ini` file. See Manual:PHP configuration for details.
Advanced Usage: Scripting
The CLI scripts can be incorporated into shell scripts for automated maintenance tasks. For example, you could create a script to rebuild the index weekly and archive old revisions monthly.
Consider the following example for a simple weekly index rebuild script:
```bash
- !/bin/bash
cd /var/www/mediawiki/maintenance php rebuildindex.php --verbose >> /var/log/mediawiki/rebuild_index.log 2>&1 ```
Remember to make the script executable (`chmod +x /path/to/script.sh`) and schedule it using cron. See Manual:Configuration settings#Cron for details on scheduling tasks with cron.
Server Requirements
The following table outlines the minimum server requirements for effective CLI operation.
Requirement | Minimum | Recommended |
---|---|---|
PHP Version | 7.3 | 8.1 or higher |
Memory Limit | 128MB | 512MB or higher |
SSH Access | Required | Required |
Database Access | Required | Required |
Security Considerations
- **Limit SSH Access:** Restrict SSH access to only authorized users.
- **Secure Scripts:** Ensure any custom scripts are securely written and protected from unauthorized modification.
- **Database Credentials:** Never hardcode database credentials directly into scripts. Use environment variables or secure configuration files. See Manual:Security best practices for more information.
- **Regular Audits**: Regularly audit your server logs and CLI activity for any suspicious behavior.
Further Resources
- Manual:Maintenance tasks – Comprehensive guide to MediaWiki maintenance.
- Manual:Configuration settings – Details about configuring MediaWiki.
- Manual:API - Accessing MediaWiki programatically.
- Manual:Database - Information on database configuration and management.
- Manual:Upgrading MediaWiki - Guidelines for upgrading your MediaWiki installation.
Intel-Based Server Configurations
Configuration | Specifications | Benchmark |
---|---|---|
Core i7-6700K/7700 Server | 64 GB DDR4, NVMe SSD 2 x 512 GB | CPU Benchmark: 8046 |
Core i7-8700 Server | 64 GB DDR4, NVMe SSD 2x1 TB | CPU Benchmark: 13124 |
Core i9-9900K Server | 128 GB DDR4, NVMe SSD 2 x 1 TB | CPU Benchmark: 49969 |
Core i9-13900 Server (64GB) | 64 GB RAM, 2x2 TB NVMe SSD | |
Core i9-13900 Server (128GB) | 128 GB RAM, 2x2 TB NVMe SSD | |
Core i5-13500 Server (64GB) | 64 GB RAM, 2x500 GB NVMe SSD | |
Core i5-13500 Server (128GB) | 128 GB RAM, 2x500 GB NVMe SSD | |
Core i5-13500 Workstation | 64 GB DDR5 RAM, 2 NVMe SSD, NVIDIA RTX 4000 |
AMD-Based Server Configurations
Configuration | Specifications | Benchmark |
---|---|---|
Ryzen 5 3600 Server | 64 GB RAM, 2x480 GB NVMe | CPU Benchmark: 17849 |
Ryzen 7 7700 Server | 64 GB DDR5 RAM, 2x1 TB NVMe | CPU Benchmark: 35224 |
Ryzen 9 5950X Server | 128 GB RAM, 2x4 TB NVMe | CPU Benchmark: 46045 |
Ryzen 9 7950X Server | 128 GB DDR5 ECC, 2x2 TB NVMe | CPU Benchmark: 63561 |
EPYC 7502P Server (128GB/1TB) | 128 GB RAM, 1 TB NVMe | CPU Benchmark: 48021 |
EPYC 7502P Server (128GB/2TB) | 128 GB RAM, 2 TB NVMe | CPU Benchmark: 48021 |
EPYC 7502P Server (128GB/4TB) | 128 GB RAM, 2x2 TB NVMe | CPU Benchmark: 48021 |
EPYC 7502P Server (256GB/1TB) | 256 GB RAM, 1 TB NVMe | CPU Benchmark: 48021 |
EPYC 7502P Server (256GB/4TB) | 256 GB RAM, 2x2 TB NVMe | CPU Benchmark: 48021 |
EPYC 9454P Server | 256 GB RAM, 2x2 TB NVMe |
Order Your Dedicated Server
Configure and order your ideal server configuration
Need Assistance?
- Telegram: @powervps Servers at a discounted price
⚠️ *Note: All benchmark scores are approximate and may vary based on configuration. Server availability subject to stock.* ⚠️