Difference between revisions of "PHP"

Jump to: navigation, search

Note: You are currently viewing documentation for Moodle 2.2. Up-to-date documentation for the latest stable version is available here: PHP.

(See also:)
(PHP Version: version edit)
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
PHP is the scripting language in which Moodle is developed. PHP does not stand alone, it is tightly integrated with a suitable HTTP Server. Most people use the [[Apache]] HTTP Server for this purpose although a number of others are supported.
+
{{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 describes itself as "a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into [[HTML in Moodle|HTML]]."
+
==PHP Version==
 +
Moodle 2.2 requires PHP version 5.3.2 or later.
  
 +
==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
 +
* ''safe_mode'' needs to be OFF.
 +
* ''memory_limit'' should be at least 40M (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.
 +
* ''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.
 +
* 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.
  
== Installation ==
+
==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 [[PHP info]]. The path of the php.ini file is a few lines down in the top section.
  
Usually PHP is installed alongside [[Apache]] and [[MySQL]] in a combination known as AMP, see [[Installing AMP]] for details. It is possible to build PHP from source - you might have to if you need a very new version for developing Moodle - however, it is quite challenging. PHP itself has many dependencies that you will need to obtain and build, some of which are also tricky to build from source (e.g. GD).
+
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>
 +
php -i | grep php.ini
 +
</pre>
  
== Minimum version requirements ==
+
==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 '''iconv''' extension is required.
 +
* The '''mbstring''' extension is recommended.
 +
* The '''curl''' extension is required (required for networking and web services).
 +
* The '''openssl''' extension is recommended (required for networking and web services).
 +
* The '''tokenizer''' extension is recommended.
 +
* The '''xmlrpc''' extension is recommended (required for networking and web services).
 +
* The '''soap''' extension is recommended (required for web services).
 +
* The '''ctype''' extension is required.
 +
* The '''zip''' extension is required.
 +
* The '''gd''' extension is recommended (required for manipulating images).
 +
* The '''simplexml''' extension is required.
 +
* The '''spl''' extension is required.
 +
* The '''pcre''' extension is required.
 +
* The '''dom''' extension is required.
 +
* The '''xml''' extension is required.
 +
* The '''intl''' extension is recommended.
 +
* The '''json''' extension is required.
 +
* '''the appropriate extension for your chosen database is required'''
  
The minimum version of PHP required for Moodle is listed in the [[Installing_Moodle#Requirements|requirements section of the installation instructions]]
+
* 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).
  
== See also: ==
+
==Installing (missing) extensions==
* [[PHP FAQ]] (this page will soon become part of that FAQ page --[[User:Frank Ralf|Frank Ralf]] 08:18, 13 May 2009 (UTC))
 
  
[[Category:Administrator]]
+
This depends on how PHP was installed on your machine and what access you have. Here are some possibilities:
[[Category:Developer]]
+
* 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'''
 +
 
 +
==See also==
 +
*[[PHP FAQ]]
 +
*[[Installing Moodle]]
 +
*[[Performance]]
 +
 
 +
*http://www.php.net/ - the PHP web site
 +
*http://php.iis.net/ - Microsoft PHP Installer for IIS
  
[[ja:PHP]]
 
[[pl:PHP]]
 
 
[[de:PHP]]
 
[[de:PHP]]

Latest revision as of 11:23, 25 June 2012

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 Version

Moodle 2.2 requires PHP version 5.3.2 or later.

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
  • safe_mode needs to be OFF.
  • memory_limit should be at least 40M (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.
  • 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.
  • 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 PHP info. 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.

  • The iconv extension is required.
  • The mbstring extension is recommended.
  • The curl extension is required (required for networking and web services).
  • The openssl extension is recommended (required for networking and web services).
  • The tokenizer extension is recommended.
  • The xmlrpc extension is recommended (required for networking and web services).
  • The soap extension is recommended (required for web services).
  • The ctype extension is required.
  • The zip extension is required.
  • The gd extension is recommended (required for manipulating images).
  • The simplexml extension is required.
  • The spl extension is required.
  • The pcre extension is required.
  • The dom extension is required.
  • The xml extension is required.
  • The intl extension is recommended.
  • The json extension is required.
  • the appropriate extension for your chosen database is required
  • 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.

.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

See also