Revision as of 08:16, 12 April 2016 by Daniel Poggenpohl (talk | contribs) (Better readability for the required extensions)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Note: You are currently viewing documentation for Moodle 2.9. Up-to-date documentation for the latest stable version of Moodle may be available here: PHP.

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 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.

  • register_globals MUST be OFF - (Feature removed as of PHP 5.4. PHP 5.4 is a minimum requirement of Moodle 2.7)
  • safe_mode needs to be OFF - (Feature removed as of PHP 5.4. PHP 5.4 is a minimum requirement of Moodle 2.7)
  • memory_limit should be at least 64M (although some functions may not work if this low). 128M is recommended. Large systems may need an even higher setting.
  • session.save_handler needs to be set to FILES.
  • magic_quotes_gpc should be OFF - (Feature removed as of PHP 5.4. PHP 5.4 is a minimum requirement of Moodle 2.7)
  • magic_quotes_runtime needs to be OFF.
  • file_uploads needs to be ON.
  • session.auto_start needs to be OFF.
  • session.bug_compat_warn needs to be OFF - (Feature removed as of PHP 5.4. PHP 5.4 is a minimum requirement of Moodle 2.7)
  • 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.

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.

Extension Status Notes
iconv required
curl required for networking and web services
ctype required
zip required
simplexml required
spl required
pcre required
dom required
xml required
json required
mbstring recommended
tokenizer recommended
intl recommended
openssl recommended required for networking and web services
xmlrpc recommended required for networking and web services
soap recommended required for web services
gd recommended required for manipulating images
DATABASE EXTENSION required choose the extension of the database you're using
  • 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).

Installing (missing) extensions

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.
  • 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.


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 users 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

  • always_populate_raw_post_data should be changed to -1.

For more information about this bug, see:

.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


  • 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