安裝 Moodle

出自MoodleDocs
於 2013年8月13日 (二) 02:49 由 Yucheng Hu對話 | 貢獻 所做的修訂 →‎命令行安装工具
跳到:導覽、​搜尋

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

The chowns allow the script to write a new config.php file. More information about the options can be found using

# 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