PHP: Difference between revisions
(mbstring required since 3.9) |
(→PHP Versions: Added Moodle 4.4) |
||
(10 intermediate revisions by 6 users not shown) | |||
Line 1: | Line 1: | ||
{{Installing Moodle}} | {{Installing Moodle}} | ||
PHP is the scripting language in which Moodle is developed. It is integrated with your web server. The web server detects php pages (by their extension) and sends them to PHP for execution. PHP must be installed and configured properly for Moodle to work effectively (or at all). | PHP is the scripting language in which Moodle is developed. It is integrated with your web server. The web server detects php pages (by their extension) and sends them to PHP for execution. PHP must be installed and configured properly for Moodle to work effectively (or at all). | ||
==PHP Versions== | ==PHP Versions== | ||
* Moodle 3.0.1 and later support PHP 7, however | * Moodle 3.0.1 and later support PHP 7, however | ||
Line 7: | Line 6: | ||
* Moodle 3.4 and Moodle 3.5 '''require''' PHP 7.0 or PHP 7.1 or PHP 7.2 | * Moodle 3.4 and Moodle 3.5 '''require''' PHP 7.0 or PHP 7.1 or PHP 7.2 | ||
* Moodle 3.6 '''requires''' PHP 7.0 or later | * Moodle 3.6 '''requires''' PHP 7.0 or later | ||
* Moodle 3.7 | * Moodle 3.7 '''requires''' PHP 7.1 or later | ||
* Moodle 3.9 '''requires''' PHP 7.2 to 7.4 | |||
* Moodle 3.11 and 4.0 '''requires''' PHP 7.3 to 8.0 | |||
* Moodle 4.1 (LTS) '''requires''' PHP 7.4 to 8.1 | |||
* Moodle 4.2 '''requires''' PHP 8.0 to 8.2 | |||
* Moodle 4.3 '''requires''' PHP 8.0 to 8.2 | |||
* Moodle 4.4 '''requires''' PHP 8.1 to 8.3 | |||
==PHP Settings== | ==PHP Settings== | ||
Check these settings in your php.ini or .htaccess file (if you're using Apache). For settings which use ON/OFF as their values, you can substitute 1 for ON and 0 for OFF if you prefer. If you change php.ini, don't forget to restart the server. | Check these settings in your php.ini or .htaccess file (if you're using Apache). For settings which use ON/OFF as their values, you can substitute 1 for ON and 0 for OFF if you prefer. If you change php.ini, don't forget to restart the server. | ||
* ''memory_limit'' needs to be at least 96M (although some functions may not work if this low). | * ''memory_limit'' needs to be at least 96M (although some functions may not work if this low). Moodle will refuse to install if lower. 128M is recommended. Large systems may need an even higher setting. | ||
* ''session.save_handler'' needs to be set to FILES. | * ''session.save_handler'' needs to be set to FILES. | ||
* ''magic_quotes_runtime'' needs to be OFF. (DEPRECATED in PHP 5.3.0, and REMOVED as of PHP 7.0.0.) | * ''magic_quotes_runtime'' needs to be OFF. (DEPRECATED in PHP 5.3.0, and REMOVED as of PHP 7.0.0.) | ||
Line 20: | Line 25: | ||
* ''post_max_size'' and ''upload_max_filesize'' restrict the maximum file size that can be uploaded. | * ''post_max_size'' and ''upload_max_filesize'' restrict the maximum file size that can be uploaded. | ||
* Check the ''[mail function]'' and database section (for your chosen database) to make sure they match your server configuration. | * Check the ''[mail function]'' and database section (for your chosen database) to make sure they match your server configuration. | ||
==HTTP_RAW_POST_DATA errors== | ==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. | Some users are experiencing $HTTP_RAW_POST_DATA related errors, when establishing connection between MNET servers or making AJAX web services requests. | ||
Line 29: | Line 33: | ||
line 115 of /admin/mnet/peers.php: call to mnet_get_public_key() | line 115 of /admin/mnet/peers.php: call to mnet_get_public_key() | ||
</pre> | </pre> | ||
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. | 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: | 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'''. | * '''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 | For more information about this bug, see: https://bugs.php.net/bug.php?id=66763 | ||
==Finding the correct php.ini== | ==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. | 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. | 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: | ||
<pre> | <pre> | ||
php -i | grep php.ini | php -i | grep php.ini | ||
</pre> | </pre> | ||
==PHP Extensions and libraries== | ==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. | 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). | * 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== | ==Installing (missing) extensions== | ||
This depends on how PHP was installed on your machine and what access you have. Here are some possibilities: | This depends on how PHP was installed on your machine and what access you have. Here are some possibilities: | ||
* If this is a hosted server you are likely to have to ask the administrator or hosting company. | * The extension might be installed but not enabled; you can enable it in php.ini with the <code>extension=<extension-name></code> [https://www.php.net/manual/en/ini.core.php#ini.extension 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 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 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 | * 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. | After making any changes or additions, don't forget to re-start your web server. | ||
== .htaccess files == | == .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). | 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). | ||
Line 87: | Line 85: | ||
* php_value ''name value'' | * php_value ''name value'' | ||
* php_flag ''name on/off'' | * php_flag ''name on/off'' | ||
Examples: | Examples: | ||
* '''php_value memory_limit 128M''' | * '''php_value memory_limit 128M''' | ||
* '''php_flag register_globals off''' | * '''php_flag register_globals off''' | ||
==PHP info== | ==PHP info== | ||
The phpinfo display contains information about the configuration of your PHP installation. This is useful for checking: | 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. | * 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 | * 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. | * that you have installed the required modules needed for Moodle to work, e.g. the LDAP module for LDAP authentication. | ||
=== Displaying phpinfo in Moodle=== | === Displaying phpinfo in Moodle=== | ||
An administrator can find PHP info in ''Settings > Site administration > Server > PHP info''. | An administrator can find PHP info in ''Settings > Site administration > Server > PHP info''. | ||
=== Displaying phpinfo outside of Moodle === | === Displaying phpinfo outside of Moodle === | ||
To view the phpinfo information: | To view the phpinfo information: | ||
* Create a file called info.php using your text editor, containing this single line: | * Create a file called info.php using your text editor, containing this single line: | ||
<code php> | <code php> | ||
<?php phpinfo(); ?> | <?php phpinfo(); ?> | ||
</code> | </code> | ||
* Save this file as info.php | * Save this file as info.php | ||
* Upload this file into the root web accessible folder on your server. | * Upload this file into the root web accessible folder on your server. | ||
* Now open this file in your browser. For example <nowiki>http://<server-name>/info.php</nowiki>. | * Now open this file in your browser. For example <nowiki>http://<server-name>/info.php</nowiki>. | ||
==See also== | ==See also== | ||
*[[Compiling PHP from source]] | *[[Compiling PHP from source]] | ||
* [https://docs.moodle.org/dev/Moodle_and_PHP7 Moodle and PHP7] in the developers documentation | * [https://docs.moodle.org/dev/Moodle_and_PHP7 Moodle and PHP7] in the developers documentation | ||
*http://www.php.net/ - the PHP web site | *http://www.php.net/ - the PHP web site | ||
*http://php.iis.net/ - Microsoft PHP Installer for IIS | *[https://php.iis.net/ http://php.iis.net/] - Microsoft PHP Installer for IIS | ||
* [[MoodleDocs:Style_guide#PHP_syntax_highlighting]] to highlight PHP syntax | * [[MoodleDocs:Style_guide#PHP_syntax_highlighting]] to highlight PHP syntax | ||
* [[Code syntax highlighting]] that uses the GeSHi (Generic Syntax Highlighter) filter. | * [[Code syntax highlighting]] that uses the GeSHi (Generic Syntax Highlighter) filter. | ||
[[de:PHP]] | [[de:PHP]] | ||
[[es:PHP]] | [[es:PHP]] |
Latest revision as of 10:07, 4 October 2024
PHP is the scripting language in which Moodle is developed. It is integrated with your web server. The web server detects php pages (by their extension) and sends them to PHP for execution. PHP must be installed and configured properly for Moodle to work effectively (or at all).
PHP Versions
- Moodle 3.0.1 and later support PHP 7, however
- Moodle 3.1 and earlier does not support PHP 7.1 or later (this means that there is currently no combination of releases of Moodle and PHP that are still supported before Moodle 3.4);
- Moodle 3.4 and Moodle 3.5 require PHP 7.0 or PHP 7.1 or PHP 7.2
- Moodle 3.6 requires PHP 7.0 or later
- Moodle 3.7 requires PHP 7.1 or later
- Moodle 3.9 requires PHP 7.2 to 7.4
- Moodle 3.11 and 4.0 requires PHP 7.3 to 8.0
- Moodle 4.1 (LTS) requires PHP 7.4 to 8.1
- Moodle 4.2 requires PHP 8.0 to 8.2
- Moodle 4.3 requires PHP 8.0 to 8.2
- Moodle 4.4 requires PHP 8.1 to 8.3
PHP Settings
Check these settings in your php.ini or .htaccess file (if you're using Apache). For settings which use ON/OFF as their values, you can substitute 1 for ON and 0 for OFF if you prefer. If you change php.ini, don't forget to restart the server.
- memory_limit needs to be at least 96M (although some functions may not work if this low). Moodle will refuse to install if lower. 128M is recommended. Large systems may need an even higher setting.
- session.save_handler needs to be set to FILES.
- magic_quotes_runtime needs to be OFF. (DEPRECATED in PHP 5.3.0, and REMOVED as of PHP 7.0.0.)
- file_uploads needs to be ON.
- session.auto_start needs to be OFF.
- The temp folder must be defined and writeable by your webserver user
- Check the error display/logging section. Make sure the settings are appropriate for your server use.
- post_max_size and upload_max_filesize restrict the maximum file size that can be uploaded.
- Check the [mail function] and database section (for your chosen database) to make sure they match your server configuration.
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 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.
.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.
See also
- Compiling PHP from source
- 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
- Code syntax highlighting that uses the GeSHi (Generic Syntax Highlighter) filter.