安装 Moodle

来自MoodleDocs
跳转至:导航、​搜索

This page explains how to install Moodle. If you are an expert and/or in a hurry try Installation Quickstart.

If you just want to try Moodle on a standalone machine there are 'one-click' installers for Windows (see Complete install packages for Windows) and for OSX (see Complete Install Packages for Mac OS X). These are unsuitable for production servers.

需求

Moodle主要是在Linux上使用ApacheMySQLPHP开发(有時也被称为LAMP平台)。

如果你怀疑 LAMP 平台的安全性,LAMP 其实是目前最安全和最流行的组合。

同时也有其他的一些选择 - 查看下面链接中的软件部分:

Moodle 安装的基本需求如下:

硬件

  • 磁盘空间:160MB 是程序安装的最小空闲磁盘空间。你也可能需要存储你自己的资料的话,5GB 实际使用空间基本上够用了。
  • 备份空间:至少与你实际运行的程序和数据相同的存储空间,如果能够进行远程备份,那就更加理想。
  • 内存:256MB 的内存为最小内存,强烈建议使用 1GB 以上内存。Moodle 的基本使用情况是: 1G 的内存能够支持 10 到 20 个的并发用户。但是这个也与你的系统硬件和软件配置有很大的关系。 '并发'的意思为服务器同时在内存中处理的能力,例如用户在某一个时间点内与系统进行交互,而不是指登录系统的用户数量。

软件

  • 操作系统 (!).通常用于运行下面的软软件,选择什么样的操作系统通常根据你的技术能力和实际情况来决定。Linux 和 Windows 是最常见的选择(同时也有很好的技术支持)。如果你可以自由选择操作系统的话,Linux 是最佳的方案。 Moodle 测试了 Debian, Ubuntu, CentOS, RedHat, Windows 7/2012 和 Mac OS X 的兼容性。
  • Web 服务器, 主要使用Apache。Moodle 没有完全测试(或者支持)IISlightttpdnginxcherokee, zeus 和 LiteSpeed,但是 Moodle 应该能够在上面的服务器上正常工作。除此之外,如果你选择使用其他 WEB 服务器的话,Moodle 将会终止安装过程。同时你的服务器也配置 PHP。WEB 服务器使用什么版本并不重要,但是请尽量使用最新版。
  • PHP - 当前的最低版本是5.3.3。你需要为你的 PHP 安装一系列扩展,PHP 页面列出了所有需要安装的扩展。如果一些必须的扩展丢失的话,安装程序会在安装环境校验的时候提示您修复并阻止您进入下一步。
  • 数据库。MySQL 和 PostgreSQL 是主要使用的开发数据库,这2个数据库进行了主要的兼容性测试,相关的技术文档也是最全面的。Oracle 和 MSSQL 都能够被完全的支持(注意,一些可选的插件可能没有在这 2 个数据库中进行兼容性测试),但是相关的文档和与 Moodle 相关的文件没有 MySQL/PostgreSQL 这么全面。MySQL 能提供更多的文档,PostgreSQL 能提供更好的稳定性。你需要在系统中安装 PHP 的扩展来支持你选择的数据库。
  • 访问 Moodle 使用的浏览器最低版本要求为:Firefox 4, Internet Explorer 8, Safari 5, Google Chrome 11, Opera 9

配置你的服务器

如果你希望评估 Moodle,你也可以在桌面计算机中安装 Moodle。

有很多方法来安装你的服务器软件,这个根据你选择服务器的不同而不同。一些链接和指向将在 安装 AMP 中。

如果你使用虚拟服务器,服务器需要的一些软件应该已经帮你安装好了。尤其是在共享服务器上,你需要知道如何修改 PHP 的配置,例如如何修改最大上传文件大小限制。

不同服务器的配置可能有非常大的不同。

下载和拷贝你的文件到正确位置

重要: 有很多地方可以获得 Moodle 的源代码,但是我们建议你到 Moodle 的官方网站 moodle.org 上去下载源代码。如果你遇到任何问题,你通常能够获得更好的支持。

你有 2 个选择:

  • http://moodle.org/downloads 网站上下载你需要的版本,然后解压...
  • 或者 从 Git 代码仓库中直接下载源代码(推荐开发人员使用这个方式,这个方式让你更新程序更加简单):
$ git clone -b MOODLE_25_STABLE git://git.moodle.org/moodle.git 

...这个过程将会切换到 Moodle 的 2.5 稳定分支(最新的每周构建),并且拷贝完整的 Moodle 代码仓库。 更多 GIT 的问题请参考页面Git for Administrators

不管你采用何种方式,当你完全获得 Moodle 代码以后,你应该能够在你的机器或者服务器上看到一个叫moodle的目录,这个目录中有一系列的文件和目录。

你可以将整个 Moodle 目录拷贝到你 Web 服务器的文档目录下,在这种情况下你的网站访问地址为:http://yourwebserver.com/moodle

或者你也可以直接拷贝 Moodle 中的内容到你的 Web 服务器文档目录下,这样你的访问网址就变得更加简化为http://yourwebserver.com

当你不太明白的时候,请查看你系统和WEB服务器的相关文档。

小提示: 如果你下载 Moodle 安装程序到你本地计算机上然后上传到你的服务器上的话,请尽量上传压缩文件到服务器上解压(检查你的文件'文件管理器')。如果你采用的是 FTP 上传当个文件,请注意查看 FTP 的日志,可能有部分文件在上传的时候丢失。
  • 保护 Moodle 文件: 保护 Moodle 程序文件不可以被 WEB 服务器的用户随意更改是非常重要的。例如在 Unix/Linux 操作系统下(使用 root)执行下面的命令:
# chown -R root /path/to/moodle
# chmod -R 0755 /path/to/moodle

(文件的所有权为 administrator/superuser 用户,也只有 administrator/superuser 用户有写入权限,但是其他用户是可以读的)

创建空数据库

下一步需要为你 Moodle 安装实例创建一个新的空数据库。你需要为你的 Moodle 安装实例找到或者设置下面的信息:nformation for use during the final installation stage:

  • dbhost - 数据库的服务器地址。很有可能是localhost如果的 Web 服务器和数据库服务器在同一台机器上,否则你需要在这里设置数据库服务器的名称
  • dbname - 数据库名称,你创建的数据库的名称,比如 moodle
  • dbuser - 数据库用户,能够访问 Moodle 数据库的数据库用户名。不要使用 root 和超级用户的账号。创建一个账号,只赋予这个账号所需要的最低权限就可以
  • dbpass - 数据库用户使用的密码

如果你的 Moodle 站点使用的是虚拟主机服务,你可以通过网页工具访问相关的配置信息,如果你不知道如何配置,请询问你的系统管理员。更多详细信息,可以通过单击下面的数据库分类来获得:

创建(moodledata) 数据目录

Moodle 需要一个目录来存储所有的文件,包括系统上传的文件,临时数据,会话数据等。

Web 服务器需要这个目录具有写入权限。在大型的 Moodle 安装实例中,这个目录越大越好。

重要:: 这个目录一定不要放置在 Web 服务器下,换句话说,这个目录不能通过网页访问到。如果网页能访问到这个目录的话,将会导致非常严重的安全漏洞。如果你使用的是 Linux 操作系统的话,也请不要将这个目录放置到 root 账号目录下和你的 Moodle 安装程序文件目录下。Moodle 在安装的时候将会进行校验,如果 Moodle 发现了文件,将会阻止安装继续进行。

这里是一个Unix/Linux 的配置示例,在创建此目录的时候需要设置权限为所有人都可以访问。这种情况是因为 Moodle 服务器不是共享服务器。与你的服务器管理员取得联系来确定何种访问权限更加合适,同时也需要 Web 服务器用户可以访问到这些文件。

# mkdir /path/to/moodledata
# chmod 0777 /path/to/moodledata

如果你的服务器能够支持 ACL,推荐采用下面的授权方式,例如你的 Apache 服务器用户 www-data:

# chmod -R +a "www-data allow read,delete,write,append,file_inherit,directory_inherit" /path/to/moodledata

如果你计划从命令行中执行 PHP 脚本,你需要为当前用户设置同样的权限:

$ sudo chmod -R +a "`whoami` allow read,delete,write,append,file_inherit,directory_inherit" /path/to/moodledata

Web 目录中配置 moodledata 安全性

如果你使用的是虚拟主机配置的网站,你没有办法配置 'moodledata'的安全性。你也许可以在'moodledata'目录中使用 .htaccess 文件来控制访问权限。这种情况不是对所有系统都是有效的,与你的虚拟主机管理员取得联系,寻求他们的帮助。

创建的文件叫做 .htaccess,这个文件只需要有下面的内容就可以了:

order deny,allow
deny from all

开始 Moodle 安装

现在是时候开始运行安装工具来创建数据库表和配置你的网站了。

Moodle 推荐使用命令行来进行安装。

如果因为什么原因你不能使用这种方式进行安装,例如你使用的 Windows 服务器,Moodle 也提供基于 Web 的安装方式。

命令行安装工具

最好使用你系统的 WEB 用户运行命令行安装工具。你需要知道这个是什么 - 查看你的系统管理文档(如:Ubuntu/Debian 是 'www-data',Centos 是 'apache')

  • 使用命令行安装工具的示例(使用 root 进行,但是 'www-data'是你的 Web 用户):
# chown www-data /path/to/moodle
# cd /path/to/moodle/admin/cli
# sudo -u www-data /usr/bin/php install.php
# chown -R root /path/to/moodle

你可能需要被询问到一些本页中没有讨论到的其他设置,如果你也不十分确定配置的信息,请单击确定使用默认配置就可以了。

# php install.php --help

You will be asked for other settings that have not been discussed on this page - if unsure just accept the defaults. For a full discussion see Administration via command line

Web based installer

To run the web installer script, just go to your Moodle's main URL using a web browser.

The installation process will take you through a number of pages. You should be asked to confirm the copyright, see the database tables being created, supply administrator account details and supply the site details. The database creation can take some time - please be patient. You should eventually end up at the Moodle front page with an invitation to create a new course.

It is very likely that you will be asked to download the new config.php file and upload it to your Moodle installation - just follow the on-screen instructions.

Final configuration

Settings within Moodle

There are a number of options within the Moodle Site Administration screens (accessible from the 'Site administration' tab in the 'Settings' block. Here are a few of the more important ones that you will probably want to check:

  • Settings > Site administration > Plugins > Message Outputs > Email: Set your smtp server and authentication if required (so your Moodle site can send emails). The support contact for your site is also set on this page.
  • Settings > Site administration > Server > System paths: Set the paths to du, dot and aspell binaries.
  • Settings > Site administration > Server > HTTP: If you are behind a firewall you may need to set your proxy credentials in the 'Web proxy' section.
  • Settings > Site administration > Location > Update timezones: Run this to make sure your timezone information is up to date.

Remaining tasks

  • Configure Cron: Moodle's background tasks (e.g. sending out forum emails and performing course backups) are performed by a script which you can set to execute at specific times of the day. This is known as a cron script. Please refer to the Cron instructions.
  • Set up backups: See Site backup and Automated course backup.
  • Check mail works: Create a test user with a valid email address and send them a message. Do they receive an email copy of the message? If not, check the settings in Settings > Site administration > Plugins > Message outputs > Email. Don't be tempted to skip this step (clue: email is used to recover lost passwords, including the administrator password when you forget it!)
  • Secure your Moodle site: Read the Security recommendations.

Installation is complete :)

If something goes wrong...

Here are some things you should try...

  • Check the Installation FAQ
  • Check your file permissions carefully. Can your web server read (but not write) the Moodle program files? Can your web server read and write your Moodle data directory?
  • Check your database permissions. Have you set up your database user with the correct rights and permissions for your configuration (especially if the web server and database server are different machines)?
  • If you are having trouble creating a Configuration file (config.php), you can do it manually by copying config-dist.php (in the root of the Moodle program directory) to config.php, editing it and setting your database/site options there. Installation will continue from the right place.
  • Once you have a config.php (see previous tip) you can edit it to turn on debugging (in section 8). This may give you extra information to help track down a problem. If you have access, check your web server error log(s).
  • Re-check your php.ini / .htaccess settings. Are they appropriate (e.g. memory_limit), did you edit the correct php.ini / .htaccess file and (if required) did you re-start the web server after making changes?
  • Did you include any non-core (optional) plugins, themes or other code before starting the installation script? If so, remove it and try again (it may be broken or incompatible).
  • Explain your problem in the Installation problems forum. PLEASE list your software versions; explain what you did, what happened and what error messages you saw (if any); explain what you tried. There is no such thing as 'nothing', even a blank page is something!

Platform specific instructions

Note: Much of this information is provided by the community. It may not have been checked and may be out of date. Please read in conjunction with the above installation instructions.

See also