This page is a translated version of the page Manual:Maintenance scripts/Running the scripts and the translation is 19% complete.

维护脚本必须从命令行运行。 Users who do not access the server directly from its terminal will usually establish a connection through SSH.

  • For Linux/Unix users this is by using the SSH client in a shell.
  • For Windows users, one can use the SSH command line tool introduced in Windows 10 or alternatively use a third-party tool such as PuTTY shown below or use Windows Subsystem for Linux.

连接到服务器

Linux/MacOS 用户

Most the Linux system and MacOS comes SSH client built-in. So you don't need to any SSH client. You can check SSH client in your system by running following command in your terminal.

Terminal

If this command gives error then you need to install SSH client in your system.

Debian/Ubuntu - sudo apt install openssh-client

MacOS - brew install openssh

Once you get the SSH client in your system then you can run following command to get into server.

Terminal

The default port for SSH connection is 22 and user is root. But shared hosting provider gives the custom user and SSH port number. Replace these values with yours.

Now, you can run the MediaWiki maintenance script on server.

Windows 用户

For Windows user, there are two ways to get into server.

Native SSH client

You can install/enable SSH client using Windows Settings on Windows Server 2019 and Windows 10 devices. They support the SSH natively. See Official doc.

To install the OpenSSH component:

  • Open Settings, select Apps > Apps & Features, then select Optional Features.
  • Scan the list to see if the OpenSSH is already installed. If not, at the top of the page, select Add a feature, then:
    • Find OpenSSH Client, then click Install.

It will install the SSH client in your system. Now, you can SSH to server using PowerShell.

PowerShell

The default port for SSH connection is 22 and user is root. But shared hosting provider gives the custom user and SSH port number. Replace these values with yours.

Now, you can run the MediaWiki maintenance script on server.

Putty (or other 3rd party SSH client)

You can use PuTTY or other 3rd party SSH client on Windows machine:

  • 步骤1:下载并运行PuTTY(一个虚拟终端
  • 步骤2:在PuTTY中,在Host Name(主机名)或IP address(IP地址)一栏输入主机的IP地址(必要情况下请联系网站提供商)并点击Open(打开)。
  • 步骤3:一个命令行窗口将会弹出。在login as: 一栏输入FTP用户名。
  • 步骤4:输入FTP密码。

Now, you can run the MediaWiki maintenance script on server.

Running the script

Once you get into to the server (See "Get into server" above) then you can follow these steps.

Step 1: Goto the MediaWiki root directory. In most cases, it would be /var/www/html

Terminal

Step 2: Run the script

Terminal

If you are using Windows server and get an error (for example: php.exe is no valid Win32 application), try the following.

$ php-cgi maintenance/run.php showSiteStats

$ C:\path\to\php\php-win.exe C:\path\to\mediawiki\maintenance\run.php showSiteStats
Since MediaWiki 1.40, a maintenance script should be invoked directly through maintenance/run.php. Invoking maintenance scripts directly will trigger a warning.
If your script fails to run, and spews out a lot of error messages, the first thing to try is to set the MW_INSTALL_PATH environment variable to point to the root of your MediaWiki installation. This will help scripts to find the necessary files, and is particularly relevant when running maintenance scripts provided by third-party extensions.


Standard command-line options

Almost every PHP script in /maintenance supports several standard options:

选项 描述
--help 显示帮助消息
--conf <path> Location of LocalSettings.php, if not default (at parent directory of the script)
--dbuser <username> Database account to use instead of the one specified in LocalSettings.php, not used for scripts that don't require a database connection or when SQLite database backend is used
--dbpass <password> Database password to use instead of the one specified in LocalSettings.php, not used for scripts that don't require a database connection or when SQLite database backend is used
--globals Output globals at the end of processing for debugging
--memory-limit <value> Set memory limit for the script. Accepts ordinary numbers, standard php.ini abbreviations (1024K, 20M, 1G), max for no limit (will be used by default if omitted) and default for no change. (在版本1.17引入)
--quiet Suppress non-error output
--wiki Wiki ID for wiki farms. This may be of the form dbname or dbname-prefix. LocalSettings.php will be run with the MW_DB and MW_PREFIX constants defined accordingly.
--profiler Profiler output format (usually "text"). (在版本1.22引入)
--mwdebug Enable built-in MediaWiki development settings. (在版本1.31引入)

In cases where the MediaWiki PHP files are symlinked to a central installation, you will need to specify to the maintenance script the path of the LocalSettings.php file. For example:

php maintenance/importImages.php --conf /var/www/html/LocalSettings.php /tmp/wikiimages .jpg .png .svg

MediaWiki installs that use shared settings (family type)

Sometimes MediaWiki is installed as a family for many languages and settings (LocalSettings.php) are split to common part and language parts (see Wiki family#Shared Settings ) where common part is located outside of /w directory and accessed using relative link (require_once "../ExtensionSettings.php";). In this case maintenance scripts will not work when running them in /w/maintenance directory. Run them from /w directory instead.

No shell access

On many shared hosts, you won't have shell access. The following extensions may be useful to run maintenance scripts via the web.