手册:安装 MediaWiki

From MediaWiki.org
Jump to: navigation, search
This page is a translated version of the page Manual:Installing MediaWiki and the translation is 44% complete.

Outdated translations are marked like this.
Other languages:
català • ‎dansk • ‎Deutsch • ‎English • ‎español • ‎français • ‎magyar • ‎Bahasa Indonesia • ‎italiano • ‎日本語 • ‎한국어 • ‎नेपाली • ‎polski • ‎português do Brasil • ‎русский • ‎Türkçe • ‎粵語 • ‎中文
Mediawiki-logo.png 手册:安装指南Manual:Installation guide | 关于 MediaWikiManual:What is MediaWiki?
Help-browser.svg 功能列表Manual:MediaWiki feature list | 安装要求Manual:Installation requirements
Preferences-system.svg 下载Download | 安装Manual:Installing MediaWiki | 配置Manual:Configuring MediaWiki

MediaWiki 可以通过内置的 Web 安装脚本完成安装。 参阅安装要求快速安装指南 获得准备环境来运行安装脚本的详细信息 .

如果没有 Apache, PHP 和 MySQL/MariaDB 的使用经验的话,安装 MediaWiki 可能会很吃力。 因此更多的用户可能会考虑使用 MediaWiki 托管服务 或者 预先配置的软件包.

Manual:Errors and Symptoms#Installation Errors 提供了排解一般安装问题的指导。

下载 MediaWiki 软件

前往 下载页面来下载: 对于用于生产环境的一般情况推荐使用当前的稳定版本。

在 *nix 系统上 下载 MediaWiki 当前的稳定版本 1.30.0, 可以通过以下命令完成:

wget https://releases.wikimedia.org/mediawiki/1.30/mediawiki-1.30.0.tar.gz

或者使用 cURL:

curl -O https://releases.wikimedia.org/mediawiki/1.30/mediawiki-1.30.0.tar.gz

下载的文件是 .tar.gz 格式,所以在使用前需要先从压缩文件中提取。 可以在本地提取并上传到服务器,或者上传压缩包然后在服务器上提取,或者直接在服务器上下载并提取. 在Windows上,这通常由7-Zip(免费)、WinZipWinRARIZArc(免费)来完成。 Linux 和 macOS 系统上可以通过这个命令来提取:

tar xvzf mediawiki-*.tar.gz
如果你以 root 用户提取文件,请考虑使用chown命令来修改文件的所有者,否则那些文件的所有者会是默认的 #1000。


为了即时跟踪最近的更改,开发者们请通过 Git 下载来建立本地存储库。 同时需要通过Composer安装必要的依赖。


If you have not already uploaded the files to your web server, do so now.

Upload the files to your web server's web directory either by:

  1. 直接复制解压的文件夹或
  2. by using an FTP client such as FileZilla (Open Source Software, Windows, OSX and Linux) or Cyberduck (OSX).

If your upload tool has a "change file names to lowercase" option, then you must disable this.

If you installed Apache, the correct directory is specified in your httpd.conf file (it's the DocumentRoot directive, typically /var/www/ or <apache-folder>/htdocs). Note: This changed in Ubuntu 14.04 with Apache 2.4.7 where the primary configuration file for Apache server settings and directories is /etc/apache2/apache2.conf.

If you are using a Linux or Unix server you can instead copy the files to any directory on your server and then make a symbolic link to that folder from your web server's web directory.

Rename the uploaded folder to whatever you would like to have in the URL. If your web server is running as http://localhost for example, renaming to /w/ directory would mean you would access your wiki at http://localhost/w/index.php. 如果您希望将其用作缩短URL的话,不要使用/wiki/ (And don't set up short URLs until you have run the installation script.)

Note that in certain cases, like when a local repository is set-up using Git, on browsing to index.php the Linux server might show the "500 Internal server Error". This is possibly a permissions error which can be resolved on changing the file and directory permissions by running the following command in SSH after changing directory to "w":
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;

This (renamed) folder will now be referred as <MediaWiki-folder>.


If you already have a database server and know the root password for it, the MediaWiki installation script can create a new database for you. If this is the case, you can skip to the Run the installation script section below. If you don't know the root password, for example if you are on a hosted server, you will have to create a new database now. Currently, you must use SQLite, MariaDB/MySQL or PostgreSQL to store the actual contents of your wiki.


MediaWiki 1.13 版本以后增加了对 SQLite 的支持,但如果要使用 SQLite,推荐使用 1.16 或更高版本。 SQLite is a stand-alone database library that stores the database contents in a single file. 如果 PHP 中启用了 pdo-sqlite 模块,那么没有什么其他步骤需要做的。

On the installation page, you will need to choose a database name (which can be anything) and the SQLite database directory. For the database directory, the installer will attempt to use a subdirectory outside of the document root and create it if needed. If this directory is not safe (for example, web-readable), change it manually to avoid making it accessible to everyone on the web.


MediaWiki will ask you for database and user name and will attempt to create them if they don't already exist. If doing so from MediaWiki is impossible, you can do this using various control panels such as PhpMyAdmin, which are often available from shared hosts, or you may be able to use ssh to login to your host and type the commands into a MySQL prompt. See the corresponding documentation. Alternatively, contact your host provider to have them create an account for you.


  1. 下载并安装MariaDB/MySQL。 Depending on how MariaDB/MySQL was installed on your system the commands mysql, mysqladmin and mysqld_safe may need to be amended to include the installation directory of MariaDB/MySQL (for example, by adding /usr/local/mysql/bin/ in front of them).
  2. 检查并看看数据库服务器是否正在运行;比如,运行mysqladmin status。 如果没有,运行mysqld_safe来重启它:sudo mysqld_safe
    • Another way to initially start the MariaDB/MySQL server is to run the configure script available at the root of the installation. It creates the initial tables and automatically starts the MariaDB/MySQL daemon.
    • Alternatively you can start the MariaDB/MySQL daemon with systemd using: sudo systemctl start mysqld. You may also wish to enable the mysqld service with sudo systemctl enable mysqld, so that the MySQL service is started automatically on startup.
  3. Set a password for the "root" account on your database server. mysqladmin -u root password yourpassword
  4. 运行MariaDB/MySQL命令行客户端: mysql -u root -p
  5. This will prompt for the "root" database password you just set, then connect to the MariaDB/MySQL server. 现在通过下面的SQL命令继续。


  1. 下载MySQL msi(比如mysql-5.5.22-winx64.msi)
  2. 打开msi文件并同意所有默认值。 当你创建根账户时,使用一个你能够记住的密码。
  3. 打开 开始(start)->所有项目(All Programs)->MySQL->MySQL Server->MySQL Command Line Client
  4. 输入你刚创建的根密码
  5. 现在继续下方的指导即可


GRANT ALL PRIVILEGES ON wikidb.* TO 'wikiuser'@'localhost' IDENTIFIED BY 'password';

If your database is not running on the same server as your web server, you need to give the appropriate web server hostname -- mediawiki.example.com in my example -- as follows:

GRANT ALL PRIVILEGES ON wikidb.* TO 'wikiuser'@'mediawiki.example.com' IDENTIFIED BY 'password';
警告 警告: MySQL/MariaDB on UNIX/Linux logs all queries sent to it to a file, which will include the password you used for the user account. If this concerns you, delete your .mysql_history file after running these queries. This file may be found in your home directory (~/.mysql_history).


If you are using PostgreSQL, you will need to either have a database and user created for you, or simply supply the name of a PostgreSQL user with "superuser" privileges to the configuration form. Often, this is the database user named postgres.

Here's one way to do most of the setup. 这用于类Unix系统。 In this example, we'll create a database named wikidb, owned by a user named wikiuser. From the command-line, as the postgres user, perform the following steps.

 createuser -S -D -R -P -E wikiuser (然后输入密码)
 createdb -O wikiuser wikidb

or as superuser (default postgres) execute the following commands at the database prompt:


Beware of the list of known issues when running MediaWiki with PostgreSQL.

Run the installation script

Once all of the above steps are complete, you can complete the installation through a web browser by going to the index.php URL in your browser — check the instructions mentioned in 手册:初始配置Manual:Config script.

The installation tool will prompt you to download the LocalSettings.php file, and to save this as <MediaWiki-folder>/LocalSettings.php.

Alternatively, you can run the command-line installer or CLI: php maintenance/install.php.

MediaWiki版本: 1.16

MediaWiki 1.16 and earlier needed to be able to write to the <MediaWiki-folder>/config directory when it ran its installation script. This is not required in 1.17 and above.


Subscribe to our release announcements mailing list.

Once installed, make sure you stay up to date with releases, and keep your server secure!