PHP
- Instalación de Moodle
- Inicio Rápido de Instalación
- Cron
- Nginx
- Apache
- IIS
- Ruteo
- Instalar plugins
- Instalación FAQ
- Actualización
- Visión general de actualización
- Implementar actualizaciones automáticas
- Git para Administradores
- Administración por línea de comando
- Actualización FAQ
- Migración de Moodle
- Tamaño de archivo subido
- Crear archivo .htaccess
- Moodle en una netbook sin internet
{
![]() |
Nota del traductor: En esta página, la palabra extensión corresponde a la traducción del término inglés extension, aplica a las extensiones PHP, y no debe de confundirse con lo que el Español internacional usa para la traducción de plugin [sic]. |
PHP es el lenguaje de script en el cual Moodle está desarrollado. Está integrado con su servidor web. El servidor web detecta (por su extensión) las páginas PHP y las envía a PHP para que se ejecutan. PHP debe de estar instalado y configurado apropiadamente para que Moodle funcione adecuadamente (o que simplemente funcione).
Versiones de PHP
- Moodle 3.0.1 y más recientes soportan PHP 7; sin embargo,
- Moodle 3.1 y anteriores no soportan PHP 7.1 ni más recientes (esto significa que actualmente no hay combinaciones de versiones Moodle y PHP que todavía estén soportadas antes de Moodle 3.4);
- Moodle 3.4 y Moodle 3.5 requieren PHP 7.0 o PHP 7.1 o PHP 7.2
- Moodle 3.6 requiere PHP 7.0 o más reciente
- Moodle 3.7 requiere PHP 7.1 o más reciente
- Moodle 3.9 requiere PHP 7.2 o más reciente
- Moodle 3.11 y 4.0 requieren PHP 7.3 a 8.0
- Moodle 4.1 (LTS) requiere PHP 7.4 a 8.1
- Moodle 4.2 requiere PHP 8.0 a 8.2
- Moodle 4.3 requiere PHP 8.0 a 8.2
- Moodle 4.4 requiere PHP 8.1 a 8.3
- Moodle 4.5 (LTS) requiere PHP 8.1 a 8.3
Configuraciones de PHP
Revise estas configuraciones en el archivo php.ini o .htaccess (si está usando Apache). Para las configuraciones que usan SI/NO (ON/OFF) como sus valores, Usted puede sustituir 1 por ON y 0 por OFF si así lo prefiere. Si Usted cambia php.ini, no se olvide de reiniciar el servidor.
- memory_limit necesita ser al menos 96M (aunque algunas funcionalidades podrían no funcionar con tan poco). Moodle se rehusará a instalarse si es más baja. Se recomienda 128M. Las instalaciones más grandes podrían necesitar una configuración aun mayor.
- session.save_handler necesita configurarse a FILES.
- magic_quotes_runtime necesita ser OFF. (DEPRECADO en PHP 5.3.0, y ELIMINADO a partir de PHP 7.0.0.)
- file_uploads necesita ser ON.
- session.auto_start necesita ser OFF.
- La carpeta temp debe estar definida y tener permisos de escritura para su usuario webserver
- Compruebe la sección que muestra/registra (en Bitácoras) los errores. Asegúrese de que las configuraciones estén de acuerdo con el servidor utilizado
- post_max_size y upload_max_filesize restringen el tamaño máximo de archivos que se pueden subir. Puede elevarse hasta 2000 MB si usted necesita subir archivos (de respaldos) mucho muy grandes.
- Compruebe las secciones [mail function] y la sección de la base de datos elegida, para asegurar que coincidan con la configuración de su servidor.
En versiones muy antiguas de Moodle estaban además estas otras configuraciones:
- register_globals DEBE estar OFF - (Característica eliminada en PHP 5.4. PHP 5.4 es un requisito mínimo para Moodle 2.7)
- safe_mode necesita estar OFF - (Característica eliminada en PHP 5.4. PHP 5.4 es un requisito mínimo para Moodle 2.7)
- magic_quotes_gpc debería ser OFF - (Característica eliminada en PHP 5.4. PHP 5.4 es un requisito mínimo para Moodle 2.7)
- session.bug_compat_warn necesita ser OFF - (Característica eliminada en PHP 5.4. PHP 5.4 es un requisito mínimo para Moodle 2.7)
HTTP_RAW_POST_DATA errors
Some users are experiencing $HTTP_RAW_POST_DATA related errors, when establishing connection between MNET servers or making AJAX web services requests.
Request for server name returned empty response line 134 of /mnet/lib.php: call to debugging() line 115 of /admin/mnet/peers.php: call to mnet_get_public_key()
These errors are affecting installations running moodle on PHP 5.6 version and it's a PHP bug on the always_populate_raw_post_data setting the default value to 0.
To avoid the error messages above, please change the value following setting on your php.ini file:
- always_populate_raw_post_data should be changed to -1.
For more information about this bug, see: https://bugs.php.net/bug.php?id=66763
Finding the correct php.ini
Sometimes it is not obvious where the php.ini file is located or you may even find more than one. To be certain run 'phpinfo' - see below. The path of the php.ini file is a few lines down in the top section.
Note that if you are using command-line (CLI) PHP for running cron (or anything else) it may be configured with a different php.ini file. To check, run the following command:
php -i | grep php.ini
PHP Extensions and libraries
The following PHP extensions are required or recommended (some, e.g. iconv, ctype and tokenizer are now included in PHP by default). Others will need to be installed or selected.
Required extensions
- ctype
- curl
- dom
- gd
- iconv
- intl
- json
- mbstring
- pcre
- simplexml
- spl
- xml
- zip
- The appropriate extension for your chosen database is also required (pgsql, mysqli, sqlsrv, oci8, or pdo)
- Other PHP extensions may be required to support optional Moodle functionality, especially external authentication and/or enrolment (e.g. LDAP extension for LDAP authentication and the sockets extension for Chat server).
Recommended extensions
- openssl (required for networking and web services)
- soap (required for web services)
- sodium (required on PHP 8 and above)
- tokenizer
- xmlrpc (required for networking and web services)
Installing (missing) extensions
This depends on how PHP was installed on your machine and what access you have. Here are some possibilities:
- The extension might be installed but not enabled; you can enable it in php.ini with the
extension=<extension-name>
directive. - If this is a hosted server you are likely to have to ask the administrator or hosting company.
- If PHP was compiled from source you will need to recompile, changing the 'configure' settings - see Compilar PHP desde código fuente.
- If it was installed using packages (typically Linux) you can install the required package (see your Linux distribution's documentation)
- If you are using Windows you just need to uncomment the appropriate DLL files in php.ini
After making any changes or additions, don't forget to re-start your web server.
.htaccess files
If you don't have access to the php.ini file or there are conflicting requirements with other PHP applications on the same server you may be able to change PHP settings in an .htaccess file. This should be placed in the 'root' of your Moodle installation (i.e. the same place as the config.php file).
The file isn't always called .htaccess and may not work at all. Contact your server administrator to be sure
Settings are made by adding lines in one of two formats:
- php_value name value
- php_flag name on/off
Examples:
- php_value memory_limit 128M
- php_flag register_globals off
PHP info
The phpinfo display contains information about the configuration of your PHP installation. This is useful for checking:
- that your PHP installation meets Moodle's system requirements.
- the values that are currently applied to your server's PHP install, e.g. File upload limits
- that you have installed the required modules needed for Moodle to work, e.g. the LDAP module for LDAP authentication.
Displaying phpinfo in Moodle
An administrator can find PHP info in Settings > Site administration > Server > PHP info.
Displaying phpinfo outside of Moodle
To view the phpinfo information:
- Create a file called info.php using your text editor, containing this single line:
<?php phpinfo(); ?>
- Save this file as info.php
- Upload this file into the root web accessible folder on your server.
- Now open this file in your browser. For example http://<server-name>/info.php.
Ver también
- Compilar PHP desde código fuente
- Moodle and PHP7 in the developers documentation
- http://www.php.net/ - the PHP web site
- http://php.iis.net/ - Microsoft PHP Installer for IIS
- MoodleDocs:Style_guide#PHP_syntax_highlighting to highlight PHP syntax
- Resaltado de sintaxis de codigo that uses the GeSHi (Generic Syntax Highlighter) filter.
DOCUMENTACIÓN MUY ANTIGUA
Encontrar el php.ini correcto
En ocasiones no es del todo facil saber dónde está localizado el archivo php.ini dentro del servidor, o puede haber más de uno. Para localizar el correcto, ejecute el phpinfo. La ruta del php.ini debe estar en este archivo.
Advierta que si está utilizando la línea de comandos PHP para lanzar el Cron, o cualquier otra tarea, podríaestar configurado con un archivo php.ini diferente. Para comprobarlo, ejecute este comando:
php -i | grep php.ini
Extensiones y librerías PHP
Las siguientes extensiones de PHP son requeridas o recomendadas (algunas, p ej. icon, ctype o tokonizer están ahoras incluidas por defecto en el paquete PHP). Otras deberán ser bien instaladas o seleccionadas para el correcto funcionamiento de Moodle.
Extensiones requeridas
- ctype
- curl
- dom
- gd
- iconv
- intl
- json
- mbstring
- pcre
- simplexml
- spl
- xml
- zip
- La extensión correcta para la base de datos, deberá ser igualmente requerida. (pgsql, mysqli, sqlsrv, oci8, or pdo)
- Otras extensiones pueden ser requeridas de manera opcional para el correcto funcionamiento de todas las utilidades de su Moodle. En particular la Autenticación externa y matriculación (Inscripción) (ej. LDAP y la extensión de sockets para el servidor de Chat).
Extensiones recomendadas
- openssl (requerida para servicios web y red)
- soap (requerida para servicios web)
- sodium (requerida en PHP 8 y superior)
- tokenizer
- xmlrpc (requerida para servicios web y red)
Instalación de extensiones faltantes
This depends on how PHP was installed on your machine and what access you have. Here are some possibilities:
- The extension might be installed but not enabled; you can enable it in php.ini with the
extension=<extension-name>
directive. - If this is a hosted server you are likely to have to ask the administrator or hosting company.
- If PHP was compiled from source you will need to recompile, changing the 'configure' settings - see Compiling PHP from source.
- If it was installed using packages (typically Linux) you can install the required package (see your Linux distribution's documentation)
- If you are using Windows you just need to uncomment the appropriate DLL files in php.ini
After making any changes or additions, don't forget to re-start your web server.
archivos .htaccess
Si no puede acceder al archivo php.ini o encuentra conflictos con los requerimientos con otras aplicaciones en PHP en el mismo entorno del servidor, debería cambiar en la configuración del archivo .htaccess. Este debería localizarse en la carpeta root de su instalación de Moodle (p. ej. en el mismo lugar que el archivo config.php).
El archivo no siempre tiene el nombre de .htaccess, e inclusive puede que no funcione en absoluto. Póngase en contacto con el administrador del servidor para asegurarse"
Se deberían añadir estas líneas en alguna de estas dos formas:
- php_value name value
- php_flag name on/off
Ejemplos:
- php_value memory_limit 128M
- php_flag register_globals off
Información sobre PHP
La utilidad phpinfo muestra información sobre la configuración de la instalación de su PHP. Es muy útil para comprobar:
- La instalación PHP se ajusta a lo que necesita Moodle.
- Los valores que están establecidos en el servicor, p. ej. límite máximo de subida de archivos..
- Que están instalados los módulos PHP que precisa Moodle, p. ej. módulo LDAP para la autenticación..
Mostrar phpinfo en Moodle
Un administrador puede ver la información sobre PHP en Configuraciones > Administración del sitio > Servidor > Información PHP .
Mostrar phpinfo fuera de Moodle
De cualquier forma, en cualquier archivo en el servidor, llamando a esta función se podrá ver la información PHP.:
- Cree un archivo llamado info.php usando su editor de texto, que solamente contenga la siguiente línea:
<?php phpinfo(); ?>
- Guarde este archivo como info.php
- Suba este archivo a la raíz de la carpeta accesible por web de su servidor.
- Ahora abra este archivo en su navegador. Por ejemplo, http://<server-name>/info.php.
Vea también
- Compilar PHP desde código fuente
- Moodle and PHP7 en la documentación en inglés para desarrolladores
- http://www.php.net/ - the PHP web site
- http://php.iis.net/ - Microsoft PHP Installer for IIS
- MoodleDocs:Style_guide#PHP_syntax_highlighting to highlight PHP syntax
- Resaltado de sintaxis de codigo que usa el filtro GeSHi (Generic Syntax Highlighter).
- https://docs.moodle.org/dev/PHP_for_novices
- http://www.php.net/ - the PHP web site
- http://php.iis.net/ - Microsoft PHP Installer for IIS