Installing Moodle/Creating custom php.ini files: Difference between revisions
Frank Ralf (talk | contribs) |
Marc Grober (talk | contribs) |
||
(6 intermediate revisions by 5 users not shown) | |||
Line 3: | Line 3: | ||
==How php.ini is used== | ==How php.ini is used== | ||
===Sourcing=== | ===Sourcing=== | ||
PHP searches for php.ini in a specific order in php5 (in php4 you were required to place a copy of php.ini in every directory from which you wished to run a php script which would be impacted by php.ini - looking at phpinfo.php if you are running php4 will only tell you the location of the php.ini files in one directory....) | |||
For information on sourcing see: | |||
http://www.askapache.com/2007/php/custom-phpini-tips-and-tricks.html | |||
http://us2.php.net/configuration | |||
===Apache configuration versus php.ini=== | |||
Remember, you can effect the behavior of php via php.ini or via htaccess or apache conf files. You should NOT do both. As noted here: | |||
http://moodle.org/mod/forum/discuss.php?d=124441&parent=550026 | |||
In some types of installations there are apache configuration files that set php values, such as max upload file size. Editing php.ini will not have the desired result if apache configuration files provide php directives. | |||
===Invocation=== | ===Invocation=== | ||
PHP can be run via mod_php or as a cgi program. If the latter is used there are some security considerations to address /need section on php cgi security?/ | |||
An artifact of running php as CGI is that since php is invoked everytime a php script is called, you need not restart apache to force a rereading of the php.ini file. | |||
http://us2.php.net/manual/en/security.cgi-bin.force-redirect.php | |||
==Manipulating php.ini== | ==Manipulating php.ini== | ||
===Editing the php.ini file generally=== | ===Editing the php.ini file generally=== | ||
A general listing of core directives that can be placed in php.ini [http://php.net/manual/en/ini.core.php can be found here.] Remember that various versions of php have changed what are allowable directives in php.ini. | |||
Make sure you use a real text editor and make sure you back up any file before editing it. | |||
===php.ini with shared hosts=== | ===php.ini with shared hosts=== | ||
Line 28: | Line 40: | ||
memory_limit = 40M ;(varies: minimum 16M, 32M Moodle v1.7, 40M Moodle v1.8, 128M large sites) | memory_limit = 40M ;(varies: minimum 16M, 32M Moodle v1.7, 40M Moodle v1.8, 128M large sites) | ||
session.save_handler = files ;(unless you are using another handler, e.g. mm) | session.save_handler = files ;(unless you are using another handler, e.g. mm) | ||
magic_quotes_gpc = | magic_quotes_gpc = 0 ;(preferred but not necessary, necessary from 2.0 onwards) | ||
magic_quotes_runtime = 0 ;(necessary) | magic_quotes_runtime = 0 ;(necessary) | ||
file_uploads = 1 | file_uploads = 1 | ||
Line 35: | Line 47: | ||
</code> | </code> | ||
===Max file size settings=== | === Max file size settings === | ||
You may also want to set other, optional php.ini file settings while you are already editing it. For instance, you may want to reset the maximum upload size of file attachments, which usually defaults to 2M(egabytes). For instance, to set these to 16 Megabytes: | You may also want to set other, optional php.ini file settings while you are already editing it. For instance, you may want to reset the maximum upload size of file attachments, which usually defaults to 2M(egabytes). For instance, to set these to 16 Megabytes: | ||
<code php> | |||
post_max_size = 16M | |||
upload_max_filesize = 16M | |||
</code> | |||
If you are running PHP4, you may need to copy the php.ini file into various folders for it to work: | |||
# public_html | |||
# moodle/admin | |||
# moodle/course | |||
# moodle/files | |||
# root of your moodledata directory | |||
==== See Also ==== | |||
* [[File_upload_size | File Upload Size]] | |||
* [[Administration_FAQ#How_do_the_limits_on_uploaded_files_work.3F | How limits on uploaded files work]] | |||
* [[Site_policies#Maximum_uploaded_file_size | Maximum uploaded file size]] | |||
== PHP settings by Moodle version == | == PHP settings by Moodle version == | ||
See [[PHP settings by Moodle version]] for more information on different settings by Moodle version. | See [[PHP settings by Moodle version]] for more information on different settings by Moodle version. |
Latest revision as of 22:38, 12 December 2010
Critical to any installation using php is your php.ini file, which contains directives for you usage of php. This is especially true with respect to a number of moodle settings such as max upload and max post sizes with file upload
How php.ini is used
Sourcing
PHP searches for php.ini in a specific order in php5 (in php4 you were required to place a copy of php.ini in every directory from which you wished to run a php script which would be impacted by php.ini - looking at phpinfo.php if you are running php4 will only tell you the location of the php.ini files in one directory....)
For information on sourcing see: http://www.askapache.com/2007/php/custom-phpini-tips-and-tricks.html http://us2.php.net/configuration
Apache configuration versus php.ini
Remember, you can effect the behavior of php via php.ini or via htaccess or apache conf files. You should NOT do both. As noted here: http://moodle.org/mod/forum/discuss.php?d=124441&parent=550026 In some types of installations there are apache configuration files that set php values, such as max upload file size. Editing php.ini will not have the desired result if apache configuration files provide php directives.
Invocation
PHP can be run via mod_php or as a cgi program. If the latter is used there are some security considerations to address /need section on php cgi security?/ An artifact of running php as CGI is that since php is invoked everytime a php script is called, you need not restart apache to force a rereading of the php.ini file. http://us2.php.net/manual/en/security.cgi-bin.force-redirect.php
Manipulating php.ini
Editing the php.ini file generally
A general listing of core directives that can be placed in php.ini can be found here. Remember that various versions of php have changed what are allowable directives in php.ini.
Make sure you use a real text editor and make sure you back up any file before editing it.
wrappers etc
Moodle specific php.ini settings
Common php.ini settings
Please see PHP settings by Moodle version for additional details.
In the discussion below you can substitute Off for 0 and On for 1.
register_globals = 0 ;(necessary)
safe_mode = 0 ;(necessary)
memory_limit = 40M ;(varies: minimum 16M, 32M Moodle v1.7, 40M Moodle v1.8, 128M large sites)
session.save_handler = files ;(unless you are using another handler, e.g. mm)
magic_quotes_gpc = 0 ;(preferred but not necessary, necessary from 2.0 onwards)
magic_quotes_runtime = 0 ;(necessary)
file_uploads = 1
session.auto_start = 0 ;(necessary)
session.bug_compat_warn = 0
Max file size settings
You may also want to set other, optional php.ini file settings while you are already editing it. For instance, you may want to reset the maximum upload size of file attachments, which usually defaults to 2M(egabytes). For instance, to set these to 16 Megabytes:
post_max_size = 16M
upload_max_filesize = 16M
If you are running PHP4, you may need to copy the php.ini file into various folders for it to work:
- public_html
- moodle/admin
- moodle/course
- moodle/files
- root of your moodledata directory
See Also
PHP settings by Moodle version
See PHP settings by Moodle version for more information on different settings by Moodle version.