手册:在 Debian 或 Ubuntu 上运行 MediaWiki

From MediaWiki.org
Jump to navigation Jump to search
This page is a translated version of the page Manual:Running MediaWiki on Debian or Ubuntu and the translation is 50% complete.

Outdated translations are marked like this.
Other languages:
Deutsch • ‎English • ‎español • ‎français • ‎日本語 • ‎한국어 • ‎polski • ‎русский • ‎中文


安装指导Manual:Installation guide
FreeBSDManual:Running MediaWiki on FreeBSD
GNU/LinuxManual:Running MediaWiki on GNU/Linux
- ALT LinuxManual:Running MediaWiki on ALT Linux
- Arch LinuxManual:Running MediaWiki on Arch Linux
- DamnsmalllinuxManual:Running MediaWiki on Damnsmalllinux
- Debian or UbuntuManual:Running MediaWiki on Debian or Ubuntu
- FedoraManual:Running MediaWiki on Fedora
- GentooManual:Running MediaWiki on Gentoo Linux
- MandrivaManual:Running MediaWiki on Mandriva
- Red Hat Enterprise LinuxManual:Running MediaWiki on Red Hat Linux
- SlackwareManual:Running MediaWiki on Slackware Linux
Mac OS XManual:Running MediaWiki on Mac OS X
NetWareManual:Running MediaWiki on NetWare
SolarisManual:Running MediaWiki on Solaris
- Solaris 11 / opensolarisManual:Running MediaWiki on Solaris 11 / opensolaris
- Solaris 10Manual:Running MediaWiki on Solaris 10
WindowsManual:Running MediaWiki on Windows
- Windows Server 2016Manual:Installing MediaWiki on Windows Server 2016
一键Manual:Wiki on a stick
- Uniform ServerManual:Installation on Uniform Server (Windows)
- XAMPPManual:Installing MediaWiki on XAMPP
Sourceforge.netManual:Installing MediaWiki on SourceForge.net
This page documents how to install MediaWiki using the release tarballs. If you want to use system packages, see User:Legoktm/Packages.

这个页面讲解如何在 w:zh:Debianw:zh:Ubuntu GNU/Linux 服务器上安装 MediaWiki。 下面是以 Debian 为例进行说明,也适用于 Ubuntu 和 Raspbian,不一样的地方会特别标明。

This installation procedure requires knowledge of issuing commands from a terminal (e.g. installing applications) and using a text editor (e.g. graphical: gedit, kate; text: nano, emacs, vi).

When text editing is required it can be carried out on the graphical desktop by pressing Alt-F2 and typing

    gksudo gedit 文件名

Alternatively, editing can be done from a terminal

    sudo nano 文件名

Of course, kate could be used instead of gedit or vi instead of nano.

手把手的教程

确保您的 Debian 系统是最新的

Double check that Debian is up-to-date by running:

sudo apt-get update
sudo apt-get upgrade

安装 LAMP 软件栈

Ubuntu Server Edition makes LAMP (Apache, PHP, and MySQL) available for installation during the install process. During the installation step, make sure you choose to install a LAMP server. Alternately, you can install all of these packages from a standard installation using these commands:

Ubuntu 16.04.2 LTS (Xenial) and Debian Stretch include PHP 7.0, and renamed many packages from "php5" to plain "php". In addition, some PHP modules are now in separate packages (xml, mbstring).
sudo apt-get install apache2 mysql-server php php-mysql libapache2-mod-php php-xml php-mbstring
Ubuntu Trusty, Debian Jessie and Raspbian (Jessie) include PHP 5, and use "php5" in most (but not all) packages.
sudo apt-get install apache2 mysql-server php5 php5-mysql libapache2-mod-php5

可选的有用软件包

These packages are not necessary but may be useful, depending on the installation:

名称 包名 说明
可选的 PHP 缓存 php-apcu or php5-apcu Modern MediaWiki versions will automatically take advantage of this being installed for improved performance.
PHP Unicode normalization php-intl or php5-intl MediaWiki will fallback to a slower PHP implementation if not available.
ImageMagick imagemagick Image thumbnailing.
Inkscape inkscape Alternative means of SVG thumbnailing, than ImageMagick. Sometimes it will render SVGs better if originally created in Inkscape.
PHP GD library php-gd or php5-gd Alternative to ImageMagick for image thumbnailing.
PHP command-line php-cli or php5-cli Ability to run PHP commands from the command line, which is useful for debugging and running maintenance scripts.

你可以通过 sudo apt-get install packagename 安装以上的任意一个包。

安装 MediaWiki

你可以从浏览器或命令行下载

    cd Downloads
    wget https://releases.wikimedia.org/mediawiki/1.31/mediawiki-1.31.0.tar.gz
  • 解压到你的 Web 目录里
tar -xvzf /pathtofile/mediawiki-*.tar.gz
sudo mkdir /var/lib/mediawiki
sudo mv mediawiki-*/* /var/lib/mediawiki

配置 MySQL

正常安装

如果您已经在 MySQL 的安装过程中创建了主密码,则无需执行此步骤。

首先,设定一个 MySQL 的主密码。 注意,为安全起见,你的系统主账户和 MySQL 主账户不要使用相同的密码。 确保你在输入如下命令时在最前方加上了一个空格,这样 bash(命令行 shell)就不会把你执行的命令添加到命令历史记录中去。

 mysqladmin -u root password "enter the new password here"
警告 警告: 记住这个用户(root)的密码,因为你在之后配置 MediaWiki 的过程中还要用到。

安全安装

考虑执行 mysql_secure_installation (MySQL 安全安装程序)

来自程序主页的说明:
This program enables you to improve the security of your MySQL installation in the following ways:
  • You can set a password for root accounts.
  • You can remove root accounts that are accessible from outside the local host.
  • You can remove anonymous-user accounts.
  • You can remove the test database (which by default can be accessed by all users, even anonymous users), and privileges that permit anyone to access databases with names that start with test_.
    mysql_secure_installation

可选操作:配置 PHP

这些步骤是可选的,也可以在安装之后进行。 没有这些改变 MediaWiki 也可以运行。

编辑你的 PHP 配置文件,php.ini。 在 Ubuntu Trusty 和 Debian Jessie 上,这个文件位于 /etc/php5/apache2/php.ini

On Ubuntu Xenial and Debian Stretch (PHP 7), it is located at /etc/php/7.0/apache2/php.ini.

最大上传文件大小

假设要将各种文件上传到 Wiki 作为内容,则必须调整上传文件的最大大小限制。 大约在文件上传小节的下半部分。 修改以下语句:

upload_max_filesize = 2M

将上传大小上限调整到至少 20M。 将来你需要上传更大的文件时,你可能需要再次调整这个值。

内存限制

一些 PHP 脚本运行时需要很多内存。 To increase the maximum amount of memory a script can use, page down to about 21%, and change the following entry, if found, from

memory_limit = 8M

to

memory_limit = 128M

If it is already set to 128M or more, leave it as is.

配置 MediaWiki

Navigate your browser to http://localhost/mediawiki (for certain installations it may be http://localhost/mediawiki/config or http://wiki.hostname.com/config instead) and following the procedure given.

If this gives a 404 error then this technique may work:

cd /var/www/html
sudo ln -s /var/lib/mediawiki mediawiki
  • Pay close attention for "Checking environment..." in MediaWiki installation script.

This can solve a lot of problems by specifically identifying the source of any errors.

It may complain that php extensions like mbstring and xml are missing even you have installed them. Please manually activate them by using:

 sudo phpenmod mbstring
 sudo phpenmod xml
 sudo systemctl restart apache2.service

Fill out the configuration form and continue.

Under Database Config, you may change the database name and DB username to new values, but you must turn on "Use superuser account", name:

debian-sys-maint

giving the mysql root password you configured earlier.

The configuration process will prompt you to download a LocalSettings.php that must be saved to the parent directory of the new wiki. The configuration page will give the exact directory/filename that must be moved:

 sudo mv ~/Downloads/LocalSettings.php /var/lib/mediawiki/

And navigate your browser to http://localhost/mediawiki (or http://server_ip_address/mediawiki or http://server_ip_address/mediawiki/index.php) to see your new wiki.

完成! 你现在有了一个可正常运行的 Wiki

额外的 wiki 配置

基本信息

Mediawiki is configured by the LocalSettings.php file, usually found in /var/lib/mediawiki. Manual:LocalSettings.php has detailed information that may be useful. The following are changes that appear to be universally helpful

To edit LocalSettings.php use

gksudo gedit /var/lib/mediawiki/LocalSettings.php

or from a terminal

sudo nano /var/lib/mediawiki/LocalSettings.php


文件上传

参见 手册:配置文件上传Manual:Configuring file uploads

参见 手册:$wgLogoManual:$wgLogo

MediaWiki 扩展

The current tarball for Mediawiki comes with a package of 15 or so of the most popular extensions, but there are literally hundreds more.

Instructions on how to enable extensions can be found at Manual:Extensions#Installing an extensionManual:Extensions#Installing an extension.

美化 URLs

To use /wiki/* instead of /wiki/index.php/* on Debian, follow the recommended short URL guide using '/mediawiki' as the script path instead of '/w' and placing the rewrites in /etc/apache2/conf-enabled/mediawiki.conf.

參見