Instalando Moodle en distribuciones basadas en Debian

De MoodleDocs

Nota: Pendiente de Traducir. ¡Anímese a traducir esta página!.     ( y otras páginas pendientes)


Introducción

Alcance

  • This article documents how to install Moodle on Debian GNU/Linux and on distributions based on Debian, specifically Debian 6.0 “Squeeze” and Ubuntu Server 12.04 LTS. The same instructions should also be applicable across many other Debian and Ubuntu derivatives.
  • These instructions are generic for all the currently maintained versions of Moodle (1.9, 2.2, 2.3 and 2.4 as of Jan 2013). Even the version 1.6 works with slight modifications (see below).

  • Amoung a 'stand alone' setup which does not need a network and two setups of networking, 'LAN only' and 'Internet', are differentiated in this article. They are set in table form as in the table below.
    PC únicamente solo LAN Internet
    You install Moodle on your Debian based computer so that it will be accessible only within that computer. This setup is ideal for testing Moodle and developing courses even when the computer is not connected to the Internet.

    Of course during the installation and later for upgrades you need Internet.

    We safely assume that your computer runs a graphical interface like Gnome, KDE, XFCE, etc.

    The Moodle computer is in a private network such as a LAN or a VPN, and Moodle is only accessible by the computers in that private network.

    With this setup a team can develop courses in collaboration, or run a Moodle for an institution, as long as all the users are in the same private network.

    Here too the server must have Internet access installation and later during upgrades.

    The Moodle server is accessible from the Internet. The machine has either a public IP address or is accessible from outside through port­forwarding. Ideally the computer also has a DNS name.
    Tabla 1. Discusión de los tres arreglos de red
  • Please note that server maintenance including upgrading, taking backups, benchmarking, tuning, hardening, etc. are not part of this documentation.

Advertencia

  • The Internet has become a rough terrain. You should not leave a machine connected to it, especially with a public IP address, unless you understand a whole lot about security. This article covers just the 'default setup', without any special security precautions. Be warned!
  • There is no substitute for thinking. For most part the commands here are self-explanatory. If you are in doubt, invest on building some background knowledge. These instructions are not 'Mantras' which you can cut and paste in to your command line and execute! If you do that, in the best case you will get an error message. The worst case could be anything!

Tipografía y convenciones

Command line dialogs are set in mono typeface as in this example:

; Get the local time
$ date
Son Feb 30 09:50:00 CET 2012

The first line is of course a comment. In the second line you have just typed 'date' and got the response shown in the third line. Commands you enter are set in boldface - the response in regular type.

Sometimes parts of the commands are unique to your setup. They are set in slanted type. In the example below 'username' stands for an existing (Unix) username in your system.

$ last username
username    pts/0        172.18.222.53    Thu Feb  31 22:49 - 03:01  (04:11)
[...]

The command interpreter indicates its readiness by printing the command prompt, commonly called just the 'prompt'. The standard prompt for a non-privileged user is the $ sign - a hash (#) indicates the superuser. Caveat: Don't type the prompt!

Different interpreters have different prompts and speak different languages(!). For example the MySQL command-line tool prints 'mysql>'

mysql>  SELECT now();
+---------------------+
| NOW()               |
+---------------------+
| 2012-02-31 09:50:00 |

La configuración requiere de privilegios de superusuario

All the commands in this page are executed with superuser privileges. In Debian you login as the Unix superuser 'root'. Then all the commands you enter automatically have the maximum privileges.

Debian GNU/Linux 6.0 host tty1
host login: root
Password: [password_for_root]  (not shown)
(message of the day)
root@host: ~#

The convention in Ubuntu is to log in as a non-privileged user and prepend those commands which need superuser privileges with 'sudo' (do as superuser). For example:

Ubuntu 12.04.3 LTS host tty1
host login: user
Password: [password_for_user]
$ reboot
reboot: must be superuser.
$ sudo reboot
[sudo] password for user: [password_for_user]
... The system is going down for reboot NOW!

Adding sudo to every command in a long list of commands becomes tedious. Therefore in this article we assume that the non-privileged user has taken over a privileged shell by executing 'sudo -i'. From then on there is no need for the 'sudo'.

$ sudo -i
[sudo] password for user: [password_for_user]
# reboot
... The system is going down for reboot NOW!

Historia de las versiones:

  • V 0.1 2012-02-10 (ratna) First draft, the OS and structure
  • V 0.2 2012-02-11 (ratna) Apache, more on type, table structure for network configs
  • V 0.3 2012-02-14 (ratna) MySQL, tar, CVS
  • V 0.4 2012-02-25 (ratna) Ubuntu 10.04, MySQL, Moodle 1.6.9, 1.9.16 finished
  • V 0.5 2012-03-01 (ratna) Basic LAMP ready. ToDo lighttpd, phpMyAdmin, PostgreSQL
  • V 0.6 2012-04-10 (ratna) phpMyAdmin, basic git
  • V 0.7 2012-04-15 (ratna) lighttpd, PostgreSQL removed
  • V 0.8 2012-04-30 (ratna) Ubuntu 12.04 LTS tested
  • V 0.9 2012-05-21 (ratna) Intro broken into subsections
  • V 0.91 2012-07-11 (ratna) Corrections to the intro
  • V 0.92 2012-08-27 (ratna) Get the code via git expanded
  • V 0.93 2012-11-10 (ratna) Ubuntu 12.04, MySQL 5.5
  • V 0.94 2013-01-04 (ratna) Get code, transparently from sourceforge.net
  • V 0.95 2013-01-05 (ratna) CVS servers vanishing
  • V 0.96 2013-02-07 (ratna) CVS servers gone!

Instalar Linux

Instalar el software del sistema

There are numerous ways of installing Linux. Usually one boots the computer initially from an external media and then transfer the operating system into an internal 'drive'. This guide summarizes the steps during an installation from a CD-ROM or an USB memory stick into an internal hard disk. For more details refer to the documentation of your distribution.

Importante:

  • Do a minimal installation: i.e. no server components yet
  • If for a server, do not install a GUI. For a server, you are strongly recommended to get a server distribution, they don't have a graphical interface (GUI). In the case of Debian, the basic installation installs no GUI - and in the case of Ubuntu, the Server edition installs no GUI by default.
Debian 6.0 Ubuntu Server 12.04 LTS
  1. Boot from CD-1, in the Installer boot menu select 'Install' (not 'Graphical Install')
  2. Language for the installation process. It will also be the default language for the installed system.
  3. Location
  4. default locale, most likely en_US.UTF-8
  5. Keymap
  6. (Needs some time to detect hardware, load modules, try to configure the network via DHCP) Hostname
  7. Domain name. If proper server with DNS, enter your domain.
  8. Set a root password
  9. Set an account for a for a non-privileged user
  10. Partition disks: Guided or manual
  11. Finish partitioning, write the changes to disk.
  12. (Takes time to copy software)
  13. Configure the network mirror. Choose one closest to you. If your network has a HTTP-Proxy enter next or leave empty.
  14. Checking repositories, configuring apt, scanning the mirror...
  15. Important: In the final "Software selection", accept the default 'Standard system utilities" - don't tick anything else. This is the minimal installation mentioned above.
  16. Install Grub, in the boot sector: Yes
  17. Installation complete. Continue to reboot the new system.
  18. Boots through Grub
  19. Login as root
  20. Edit /etc/apt/sources.list to comment the line 'deb cddom: Official ...CD Binary .../ squeeze main'. Otherwise software update wants to read the CD all the time.
  1. Boot the machine from a bootable CD or memory stick
  2. Select the language of the boot screen
  3. The boot screen appears, select 'Install Ubuntu Server'
  4. Choose the language for the installation process (this will also be the default language of the final system)
  5. Choose the country where the machine is located
  6. Origin of the keyboard
  7. Keyboard layout
  8. Enter the host a name. We'll call it simply hostname
  9. Select the time zone where the computer is located
  10. Partition disks. The simplest variation would be 'Guided - user entire disk'
  11. Choose the correct disk, confirm writing the partition table to the disk
  12. "Installing the base system ..." (takes a couple of minutes)
  13. You are supposed to create a non-privileged user. Set a password - and don't forget those!
  14. Encrypting home partition: No
  15. HTTP-Proxy: Very likely to be none (empty). Your network administrator should tell you otherwise
  16. How do you want to manage upgrades? You are free, 'Install security updates automatically' won't be bad idea
  17. Software selection: In the list 'Software selection', select only 'OpenSSH server' - nothing else! (This is the 'minimal' installation mentioned above.)
  18. Further software will be copied..., 'Install the GRUB boot loader to the master boot record?' Yes
  19. Install finishes. Before rebooting requests you to remove the install media!

Table 2. Dialog during the installation of Linux

Configurar la red

PC únicamente solo LAN Internet
You only need the 'localhost'. Therefore the /etc/network/interfaces file will be:
auto lo
iface lo inet loopback

The /etc/hosts file will define the localhost and a hostname

127.0.0.1        localhost
127.0.1.1        hostname
In a LAN you need an IP address, most likely a private address. Your /etc/network/interfaces will be accordingly:
auto lo
iface lo inet loopback

auto interface
iface interface inet static
  address the.ip.address
  netmask your.net.mask

and your /etc/hosts will define:

127.0.0.1         localhost
the.ip.address    hostname

If the LAN has DNS set, you need put its IP-address in /etc/resolv.conf:

nameserver ip.address.of.nameserver

If the LAN has a gateway to the Internet, by adding that to the interfaces file, your computer can connect to the Internet, for example to fetch updates. See the example in the next column.

If the computer is in the Internet, it will also have a 'gateway' and access to a domain name server. See to that your server name is properly resolved in the Internet. (ping yourserver.your.domain should show you the right IP-address, etc.) You must contact your hoster or the network administrators for further details.
auto lo
iface lo inet loopback

auto interface
iface interface inet static
  address the.ip.address
  netmask your.net.mask
  gateway your.gateway

and your /etc/hosts will contain your domain name:

127.0.0.1       localhost
the.ip.address  hostname.your.domain  hostname

and the resolver, /etc/resolv.conf, should be complete:

nameserver ip.address.of.nameserver 

Tabla 3. Configuraciones de Red

Actualizar el software del sistema

# apt-get update           ; actualiza la lista de paquetes
# apt-get upgrade          ; remplaza (upgrade) los paquetes obsoletos

Instalar Apache

# apt-get install apache2          ; el 'meta package' apache2 busca muchos
                                   ; paquetes tales como ...
... apachd2-mpm-worker apache2-utils apache2-bin apache2-common ...
...

Una vez que se haya completado exitosamente, el script de instalación inicia al demonio del servidor (server daemon). Revíselo al llamar a la página de prueba tal como se describeen la tabla inferior. Usted debería de obtener la página de 'Si Funciona' (It works).

PC únicamente solo LAN Internet
Visite la URL http://localhost/ en un navegador en su computadora desde otra computadora en la LAN visite http://la dirección.ip/ en un navegador desde cualquier computadora en Internet, visite el sitio http://el.nombre.dns/

Tabla 4. Probando la instalación de Apache Por defecto, Apache muestra el contenido de /var/www/, a lo que Apache llama el 'DocumentRoot'. Esto y todos los demás parámetros de configuración de Apache se encuentran en /etc/apache2/. Vea la documentación relevante en http://httpd.apache.org/docs/.

Si Usted quiere reinicar el servidor web en el futuro, Usted puede hacerlo al reiniciar el script de arranque(boot script):

# /etc/init.d/apache2 restart

Instalar MySQL

# apt-get instalar mysql-server
mysql-client-5.1 mysql-common mysql-server mysql-server-5.1 mysql-server-core-5.1
...
Nueva contraseña para el usuario "root" de MySQL:
[       ]    ; ¡ no la vaya a olvidar!
Configurando mysql-server ...

Pruebew el éxito al ingresar con el cliente de MySQL:

# mysql -u root -p
Enter password: XXXXXX
...
mysql>                    ; Usted debería de poder ingresar exitosamente

Instalar PHP

Núcleo de PHP (PHP Core)

# apt-get instalar php5
... apache2-mpm-prefork libapache2-mod-php5 php5-common
...
Los siguientes paquetes serán REMOVIDOS:
 apache2-mpm-worker
...
# /etc/init.d/apache2 restart   ; reiniciar al servidor web para que registre los cambios

Pruebe el éxito al solicitar phpinfo. Para esto Usted tiene que crear una página en webroot que contenga solamente una llamada a phpinfo() y visitarla en el navegador:

# editor /var/www/moodle/phpinfo.php   ; editor any text editor: nano, vi, ...
; añada solamente la línea inferior, guárdela y sálgase.
<?php phpinfo(); ?> 
PC únicamente solo LAN Internet
Visit http://localhost/moodle/phpinfo.php in the same computer. Visit http://the.ip.address/moodle/phpinfo.php from any computer in the LAN. Visit http://dnsname.of.server/moodle/phpinfo.php from any computer in the Internet.

Tabla 5. Revisando phpinfo Recuerde eliminar este archivo una vez que haya concluido la instalación. Proporciona demasiada información a los intrusos potenciales! Más tarde, el administrador de Moodle tiene acceso a esta información al visitar http://su.servidor/moodle/admin/phpinfo.php. # rm /var/www/moodle/phpinfo.php  ; ¡ phpinfo() les proporciona información a los intrusos!

Módulos de PHP

; Todas las versiones de Moodle necesitan los siguientes dos módulos
# apt-get install php5-gd php5-mysql 
; Desde la versión 2.0 Moodle necesita los siguientes módulos adicionales 
# apt-get install php5-curl php5-xmlrpc php5-intl

Usted necesita reiniciar Apache para que registre los nuevos módulos:

# /etc/init.d/apache2 restart

Si Usted necesitara cambiar la configuración de los módulos PHP para Apache2, el archivo de configuración es /etc/php5/apache2/php.ini.

PHP CLI (Interfaz por Línea de Comando)

# apt-get install php5-cli             ; possiblemente solamente Ubuntu requiera esto, en Debian viene conel núcleo

Usted puede revisar la versión del intérprete de PHP con:

# /usr/bin/php -v
PHP 5.3.3-7+squeeze8 with Suhosin-Patch (cli) ...

Tome nota de que el archivo de configuración para el PHP CLI (CLI=Command Line Interfase = Intefaz por Línea de Comando) es /etc/php5/cli/php.ini.

Instalar Moodle

Obtener el código

Mediante descarga del archivo tar

; Obenga ela archivo que necesita:
# wget http://download.moodle.org/download.php/direct/stable16/moodle-1.6.9.tgz
# wget http://download.moodle.org/download.php/direct/stable17/moodle-1.7.7.tgz
# wget http://download.moodle.org/download.php/direct/stable18/moodle-1.8.14.tgz
# wget http://download.moodle.org/download.php/direct/stable19/moodle-latest-19.tgz
# wget http://download.moodle.org/download.php/direct/stable20/moodle-latest-20.tgz
# wget http://download.moodle.org/download.php/direct/stable21/moodle-latest-21.tgz
# wget http://download.moodle.org/download.php/direct/stable22/moodle-latest-22.tgz
# wget http://download.moodle.org/download.php/direct/stable23/moodle-latest-23.tgz
# wget http://download.moodle.org/download.php/direct/stable24/moodle-latest-24.tgz
# wget http://download.moodle.org/download.php/direct/stable24/moodle-latest-25.tgz
# wget http://download.moodle.org/download.php/direct/stable24/moodle-latest-26.tgz
# wget http://download.moodle.org/download.php/direct/moodle/moodle-latest.tgz ; la más reciente versiónen desarrollo

La sversiones de arriba son solamente una muestra tomada del sitio oficial de descargas en http://download.moodle.org/. Refiérase a esa página para más detalles. Tome nota de que los archivos reales sonbucados de forma transparente desde sourceforge.net.

; Descomprima (Untar) el archivo a /var/www/moodle
# tar xzvf moodle-whatever.tgz -C /var/www 

Descargar mediante git

Git permite numerosas formas de organizar su repositorio local. El ejemplo inferior muestra el mínimo indispensable que Usted necesita conseguir del "upstream", del repositorio en git.moodle.org.

# apt-get install git ; instale git si no lo había hecho anteriormente
# cd /var/www         ; cambie a DocumentRoot
; En el comando inferior use MOODLE_19_STABLE, MOODLE_20_STABLE, etc. enlugar de BRANCH_TAG
# git clone -b BRANCH_TAG git://git.moodle.org/moodle.git
Cloning into moodle...
..., done 

Para más detalles, vea: https://docs.moodle.org/en/Git_for_Administrators.

Configurar el directorio moodledata

# mkdir /var/moodledata         ; Esto NO puede estar debajo de la Raíz de Docuemntos de Apache  /var/www
# chown www-data /var/moodledata  ; El servidor Apache necesita tener permisos de escritura en moodledata

Crear una BasedeDatos y un usuario

# mysql -p
Enter password:
mysql> CREATE DATABASE dbname DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
query OK, 1 row affected (0.03 sec)
mysql> GRANT ALL PRIVILEGES ON dbname.* TO 'dbuser'@'localhost' IDENTIFIED BY 'dbpass';
Query OK, 0 rows affected (0.00 sec)
mysql> exit

Revisar la rectitud al acceder a la BasedeDatos como dbuser:

# mysql -u dbuser -p
Enter password: [dbpass]
mysql> use dbname;
...
Database changed

Correr el script de instalación

Antes de iniciar el script de instalación, haga que el directorio de moodle sea escribible para el servidor web. Esto es necesario para permitirle al instalador que cree el archivo de configuración 'config.php'.

# chown www-data /var/www/moodle

Iniciar mediante el navegador de Internet

PC únicamente solo LAN Internet
Visit http://localhost/moodle desde un navegador dentro de la computadora Desde cualquier computadora en la LAN, llame a http://la.dirección.IP/moodle/ Desde cualquier computadora en Internet, llame a http://dnsname.of.server/moodle/

Tabla 6. Iniciar mediante el navegador

Alternativamente correr el script PHP CLI

# php /var/www/moodle/admin/cli/install.php

El procedimiento de instalación es auto-explicatorio. Los parámetros importantes a recordar son:

Web address: http://localhost/moodle o http://the.ip.address/moodle o http://dnsname.of.server/moodle
Moodle Directory: /var/www/moodle
Data Directory: /var/moodledata
Type: Improved MySQL (native mysqli)
Database host: localhost
Database name: dbname
Database user: dbuser
Database password: dbpassword

Estos parámetros son escritos a config.php, como en este ejemplo:

$CFG->dbtype    = 'mysqli';           // 'pgsql', 'mysqli', 'mssql' or 'oci'
$CFG->dblibrary = 'native';           // 'native' only at the moment
$CFG->dbhost    = 'localhost';        // eg 'localhost' or 'db.isp.com' or IP
$CFG->dbname    = 'dbname';           // database name, eg moodle
$CFG->dbuser    = 'dbuser';           // your database username
$CFG->dbpass    = 'dbpasssword';      // your database password
...
$CFG->wwwroot   = 'http://localhost/moodle'; // or http://the.ip.address/moodle or http://dnsname.of.server/moodle
$CFG->dataroot  = '/var/moodledata';

Note: MySQL changed the syntax of CREATE TABLE in version 5.5. Instead of TYPE=MyISAM (or InnoDB) now you have write ENGINE=MyISAM. http://dev.mysql.com/doc/refman/5.5/en/myisam-storage-engine.html Moodle 1.6 crashed due to this. The needed changes are recorded in this patch. [???]

Felicitaciones! NAhora Usted es el propietario de un brillante sitio Moodle! No se le olvide asegurar el directorio moodle y config.php:

# chown root /var/www/moodle
# chown root:root /var/www/moodle/config.php
# chmod 644 /var/www/moodle/config.php

Configurar cron

El script de cron.ini tiene que correrse regularmewnte para que Moodle termine sus tareas pendientes, tales como mandiar publicaciones def foros por Email. Usted podría añadir una línea a roots crontab.

# crontab -e
; añadir solamente una línea similar a la siguiente, guardarlo y salir.
*/15 * * * *        /usr/bin/php /var/www/moodle/admin/cron.php      ; para Moodle 1.x
*/15 * * * *        /usr/bin/php /var/www/moodle/admin/cli/cron.php  ; para Moodle 2.x

Vea https://docs.moodle.org/en/Cron_with_Unix_or_Linux para más detalles.

Opcionalmente instalar phpMyAdmin

# apt-get install phpmyadmin
dbconfig-common javascript-common libjs-mootools libmcrypt4 php5-mcrypt ...
...
Web server tpara reconfigurarse automáticamente:
  [*] apache2              ; select Apache
  [ ] lighttpd
Configure database with dbconfig-common? Yes
Enter MySQL root password;
PC únicamente solo LAN Internet
w3m http://localhost/phpmyadmin/ From any computer in the LAN, call http://the.ip.address/phpmyadmin/ From any computer in the Internet, call http://dnsname.of.server/phpmyadmin/

Table 7. Call phpMySQL

Apéndice

Enlaces externos

Tomado de la versión del 7 de febrero del 2013 de [1]